Skip to content

Commit 6343541

Browse files
authored
Merge pull request #4652 from NativeScript/hristova/add-drawer-navigation-vue-template
feat: add vue drawer navigation template to create project command
2 parents a4cb42c + 255ccfa commit 6343541

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

docs/man_pages/project/creation/create.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Template | Command
5151
`Angular - Hello World`, `--ng`, `--angular` | tns create tns-template-hello-world-ng
5252
`Angular - SideDrawer` | tns create tns-template-drawer-navigation-ng
5353
`Angular - Tabs` | tns create tns-template-tab-navigation-ng
54-
`Vue.js`, `--vue`, `--vuejs` | tns create tns-template-blank-vue
54+
`Vue.js - Blank`, `--vue`, `--vuejs` | tns create tns-template-blank-vue
55+
`Vue.js - SideDrawer`, | tns create tns-template-drawer-navigation-vue
5556

5657
### Related Commands
5758

lib/commands/create-project.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { isInteractive } from "../common/helpers";
55
export class CreateProjectCommand implements ICommand {
66
public enableHooks = false;
77
public allowedParameters: ICommandParameter[] = [this.$stringParameter];
8+
private static BlankTemplateKey = "Blank";
9+
private static BlankTemplateDescription = "A blank app";
810
private static HelloWorldTemplateKey = "Hello World";
911
private static HelloWorldTemplateDescription = "A Hello World app";
1012
private static DrawerTemplateKey = "SideDrawer";
@@ -109,11 +111,11 @@ or --js flags.)
109111
let selectedTemplate: string;
110112
switch (flavorSelection) {
111113
case constants.NgFlavorName: {
112-
selectedFlavorTemplates.push(...this.getNgFlavors());
114+
selectedFlavorTemplates.push(...this.getNgTemplates());
113115
break;
114116
}
115117
case constants.VueFlavorName: {
116-
selectedFlavorTemplates.push({ value: "tns-template-blank-vue" });
118+
selectedFlavorTemplates.push(...this.getVueTemplates());
117119
break;
118120
}
119121
case constants.TsFlavorName: {
@@ -178,7 +180,7 @@ or --js flags.)
178180
return templates;
179181
}
180182

181-
private getNgFlavors() {
183+
private getNgTemplates() {
182184
const templates = [{
183185
key: CreateProjectCommand.HelloWorldTemplateKey,
184186
value: constants.RESERVED_TEMPLATE_NAMES.angular,
@@ -198,6 +200,21 @@ or --js flags.)
198200
return templates;
199201
}
200202

203+
private getVueTemplates() {
204+
const templates = [{
205+
key: CreateProjectCommand.BlankTemplateKey,
206+
value: "tns-template-blank-vue",
207+
description: CreateProjectCommand.BlankTemplateDescription
208+
},
209+
{
210+
key: CreateProjectCommand.DrawerTemplateKey,
211+
value: "tns-template-drawer-navigation-vue",
212+
description: CreateProjectCommand.DrawerTemplateDescription
213+
}];
214+
215+
return templates;
216+
}
217+
201218
public async postCommandAction(args: string[]): Promise<void> {
202219
const { projectDir } = this.createdProjectData;
203220
const relativePath = path.relative(process.cwd(), projectDir);

test/project-commands.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const expectedTemplateChoices = [
2323
{ key: "SideDrawer", description: "An app with pre-built pages that uses a drawer for navigation" },
2424
{ key: "Tabs", description: "An app with pre-built pages that uses tabs for navigation" }
2525
];
26+
const expectedTemplateChoicesVue = [
27+
{ key: "Blank", description: "A blank app" },
28+
{ key: "SideDrawer", description: "An app with pre-built pages that uses a drawer for navigation" }
29+
];
2630

2731
class ProjectServiceMock implements IProjectService {
2832
async validateProjectName(opts: { projectName: string, force: boolean, pathToProject: string }): Promise<string> {
@@ -92,7 +96,7 @@ describe("Project commands tests", () => {
9296
if (opts.templateAnswer) {
9397
const templateQuestion = opts.projectNameAnswer ? "Finally" : "Next, which template would you like to start from:";
9498
answers[templateQuestion] = opts.templateAnswer;
95-
questionChoices[templateQuestion] = expectedTemplateChoices;
99+
questionChoices[templateQuestion] = opts.flavorAnswer === constants.VueFlavorName ? expectedTemplateChoicesVue : expectedTemplateChoices;
96100
}
97101

98102
prompterStub.expect({
@@ -207,12 +211,14 @@ describe("Project commands tests", () => {
207211
assert.isTrue(createProjectCalledWithForce);
208212
});
209213

210-
it("should select the default vue template when the vue flavor is selected.", async () => {
211-
setupAnswers({ flavorAnswer: constants.VueFlavorName });
214+
it("should ask for a template when vue flavor is selected.", async () => {
215+
setupAnswers({ flavorAnswer: constants.VueFlavorName, templateAnswer: "SideDrawer" });
212216

213217
await createProjectCommand.execute(dummyArgs);
214218

215-
assert.deepEqual(selectedTemplateName, "tns-template-blank-vue");
219+
assert.deepEqual(selectedTemplateName, "tns-template-drawer-navigation-vue");
220+
assert.equal(validateProjectCallsCount, 1);
221+
assert.isTrue(createProjectCalledWithForce);
216222
});
217223
});
218224
});

0 commit comments

Comments
 (0)