Skip to content

Commit 08a0d91

Browse files
authored
feat: add svelte support (#5418)
1 parent c053d94 commit 08a0d91

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

Diff for: lib/commands/create-project.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ export class CreateProjectCommand implements ICommand {
4444
this.$options.ng ||
4545
this.$options.vue ||
4646
this.$options.react ||
47+
this.$options.svelte ||
4748
this.$options.js) &&
4849
this.$options.template
4950
) {
5051
this.$errors.failWithHelp(
51-
"You cannot use a flavor option like --ng, --vue, --react, --tsc and --js together with --template."
52+
"You cannot use a flavor option like --ng, --vue, --react, --svelte, --tsc and --js together with --template."
5253
);
5354
}
5455

@@ -64,6 +65,8 @@ export class CreateProjectCommand implements ICommand {
6465
selectedTemplate = constants.VUE_NAME;
6566
} else if (this.$options.react) {
6667
selectedTemplate = constants.REACT_NAME;
68+
} else if (this.$options.svelte) {
69+
selectedTemplate = constants.SVELTE_NAME;
6770
} else {
6871
selectedTemplate = this.$options.template;
6972
}
@@ -132,6 +135,10 @@ export class CreateProjectCommand implements ICommand {
132135
key: constants.VueFlavorName,
133136
description: "Learn more at https://nativescript.org/vue",
134137
},
138+
{
139+
key: constants.SvelteFlavorName,
140+
description: "Learn more at https://svelte-native.technology",
141+
},
135142
{
136143
key: constants.TsFlavorName,
137144
description: "Learn more at https://nativescript.org/typescript",
@@ -152,7 +159,7 @@ export class CreateProjectCommand implements ICommand {
152159
this.$logger.printMarkdown(`# Let’s create a NativeScript app!`);
153160
this.$logger.printMarkdown(`
154161
Answer the following questions to help us build the right app for you. (Note: you
155-
can skip this prompt next time using the --template option, or the --ng, --react, --vue, --ts, or --js flags.)
162+
can skip this prompt next time using the --template option, or the --ng, --react, --vue, --svelte, --ts, or --js flags.)
156163
`);
157164
}
158165
}
@@ -180,6 +187,10 @@ can skip this prompt next time using the --template option, or the --ng, --react
180187
selectedFlavorTemplates.push(...this.getVueTemplates());
181188
break;
182189
}
190+
case constants.SvelteFlavorName: {
191+
selectedFlavorTemplates.push(...this.getSvelteTemplates());
192+
break;
193+
}
183194
case constants.TsFlavorName: {
184195
selectedFlavorTemplates.push(...this.getTsTemplates());
185196
break;
@@ -285,6 +296,18 @@ can skip this prompt next time using the --template option, or the --ng, --react
285296
return templates;
286297
}
287298

299+
private getSvelteTemplates() {
300+
const templates = [
301+
{
302+
key: CreateProjectCommand.HelloWorldTemplateKey,
303+
value: constants.RESERVED_TEMPLATE_NAMES.svelte,
304+
description: CreateProjectCommand.HelloWorldTemplateDescription,
305+
},
306+
];
307+
308+
return templates;
309+
}
310+
288311
private getVueTemplates() {
289312
const templates = [
290313
{

Diff for: lib/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export const RESERVED_TEMPLATE_NAMES: IStringDictionary = {
138138
angular: "@nativescript/template-hello-world-ng",
139139
react: "@nativescript/template-blank-react",
140140
reactjs: "@nativescript/template-blank-react",
141+
svelte: "@nativescript/template-blank-svelte",
141142
};
142143

143144
export const ANALYTICS_LOCAL_TEMPLATE_PREFIX = "localTemplate_";
@@ -167,9 +168,11 @@ export const ANGULAR_NAME = "angular";
167168
export const JAVASCRIPT_NAME = "javascript";
168169
export const TYPESCRIPT_NAME = "typescript";
169170
export const REACT_NAME = "react";
171+
export const SVELTE_NAME = "svelte";
170172
export const NgFlavorName = "Angular";
171173
export const VueFlavorName = "Vue.js";
172174
export const ReactFlavorName = "React";
175+
export const SvelteFlavorName = "Svelte";
173176
export const TsFlavorName = "Plain TypeScript";
174177
export const JsFlavorName = "Plain JavaScript";
175178
export class ProjectTypes {

Diff for: lib/declarations.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ interface IOptions
658658
ng: boolean;
659659
angular: boolean;
660660
react: boolean;
661+
svelte: boolean;
661662
vue: boolean;
662663
vuejs: boolean;
663664
js: boolean;

Diff for: lib/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export class Options {
129129
reactjs: { type: OptionType.Boolean, hasSensitiveValue: false },
130130
vue: { type: OptionType.Boolean, hasSensitiveValue: false },
131131
vuejs: { type: OptionType.Boolean, hasSensitiveValue: false },
132+
svelte: { type: OptionType.Boolean, hasSensitiveValue: false },
132133
tsc: { type: OptionType.Boolean, hasSensitiveValue: false },
133134
ts: { type: OptionType.Boolean, hasSensitiveValue: false },
134135
typescript: { type: OptionType.Boolean, hasSensitiveValue: false },

Diff for: test/project-commands.ts

+40
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const expectedFlavorChoices = [
3232
"Learn more at https://github.com/shirakaba/react-nativescript",
3333
},
3434
{ key: "Vue.js", description: "Learn more at https://nativescript.org/vue" },
35+
{
36+
key: "Svelte",
37+
description: "Learn more at https://svelte-native.technology",
38+
},
3539
{
3640
key: "Plain TypeScript",
3741
description: "Learn more at https://nativescript.org/typescript",
@@ -188,6 +192,16 @@ describe("Project commands tests", () => {
188192
assert.isTrue(createProjectCalledWithForce);
189193
});
190194

195+
it("should not fail when using only --svelte.", async () => {
196+
options.svelte = true;
197+
198+
await createProjectCommand.execute(dummyArgs);
199+
200+
assert.isTrue(isProjectCreated);
201+
assert.equal(validateProjectCallsCount, 1);
202+
assert.isTrue(createProjectCalledWithForce);
203+
});
204+
191205
it("should not fail when using only --tsc.", async () => {
192206
options.tsc = true;
193207

@@ -228,6 +242,16 @@ describe("Project commands tests", () => {
228242
assert.isTrue(createProjectCalledWithForce);
229243
});
230244

245+
it("should set the template name correctly when used --svelte.", async () => {
246+
options.svelte = true;
247+
248+
await createProjectCommand.execute(dummyArgs);
249+
250+
assert.deepStrictEqual(selectedTemplateName, constants.SVELTE_NAME);
251+
assert.equal(validateProjectCallsCount, 1);
252+
assert.isTrue(createProjectCalledWithForce);
253+
});
254+
231255
it("should set the template name correctly when used --tsc.", async () => {
232256
options.tsc = true;
233257

@@ -331,5 +355,21 @@ describe("Project commands tests", () => {
331355
assert.equal(validateProjectCallsCount, 1);
332356
assert.isTrue(createProjectCalledWithForce);
333357
});
358+
359+
it("should ask for a template when svelte flavor is selected.", async () => {
360+
setupAnswers({
361+
flavorAnswer: constants.SvelteFlavorName,
362+
templateAnswer: "Hello World",
363+
});
364+
365+
await createProjectCommand.execute(dummyArgs);
366+
367+
assert.deepStrictEqual(
368+
selectedTemplateName,
369+
"@nativescript/template-blank-svelte"
370+
);
371+
assert.equal(validateProjectCallsCount, 1);
372+
assert.isTrue(createProjectCalledWithForce);
373+
});
334374
});
335375
});

0 commit comments

Comments
 (0)