Skip to content

Commit ea8f056

Browse files
author
DimitarTachev
committed
chore: fix pr comments
1 parent 1cb0323 commit ea8f056

File tree

3 files changed

+65
-25
lines changed

3 files changed

+65
-25
lines changed

docs/man_pages/project/creation/create.md

+30-10
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,49 @@ position: 1
77

88
Usage | Synopsis
99
---|---
10-
Create from default JavaScript template | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>]`
11-
Create from default TypeScript template | `$ tns create <App Name> --template typescript [--path <Directory>] [--appid <App ID>]` OR `$ tns create <App Name> --tsc [--path <Directory>] [--appid <App ID>]` OR `$ tns create <App Name> --template tsc [--path <Directory>] [--appid <App ID>]`
12-
Create from default Angular template | `$ tns create <App Name> --template angular [--path <Directory>] [--appid <App ID>]` OR `$ tns create <App Name> --template ng [--path <Directory>] [--appid <App ID>]` OR `$ tns create <App Name> --ng [--path <Directory>] [--appid <App ID>]`
13-
Copy from existing project | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>]`
14-
Create from custom template | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>] --template <Template>`
10+
Create from default JavaScript template | `$ tns create [<App Name>] [--js] [--path <Directory>] [--appid <App ID>]`
11+
Create from default TypeScript template | `$ tns create [<App Name>] --ts [--path <Directory>] [--appid <App ID>]`
12+
Create from default Angular template | `$ tns create [<App Name>] --ng [--path <Directory>] [--appid <App ID>]`
13+
Create from default Vue.js template | `$ tns create [<App Name>] --vue [--path <Directory>] [--appid <App ID>]`
14+
Create from custom template | `$ tns create [<App Name>] [--path <Directory>] [--appid <App ID>] --template <Template>`
1515

16-
Creates a new project for native development with NativeScript.
16+
Interactively creates a new NativeScript app.
1717

1818
### Options
1919
* `--path` - Specifies the directory where you want to create the project, if different from the current directory. The directory must be empty.
2020
* `--appid` - Sets the application identifier for your project.
21-
* `--template` - Specifies a valid npm package which you want to use to create your project. If `--template` is not set, the NativeScript CLI creates the project from the default JavaScript hello-world template.<% if(isHtml) { %> If one or more application assets are missing from the `App_Resources` directory in the package, the CLI adds them using the assets available in the default hello-world template.<% } %>
22-
* `--ng` - Sets the template for your project to the Angular template.
23-
* `--tsc` - Sets the template for your project to the TypeScript template.
21+
* `--template` - Specifies a valid npm package which you want to use to create your project. If `--template` is not set, the NativeScript CLI will ask you to pick one from a predefined list afterwards.<% if(isHtml) { %> If one or more application assets are missing from the `App_Resources` directory in the package, the CLI adds them using the assets available in the default hello-world template.<% } %>
22+
* `--js`, `--javascript` - Sets the template for your project to the JavaScript template.
23+
* `--ts`, `--tsc`, `--typescript` - Sets the template for your project to the TypeScript template.
24+
* `--ng`, `--angular` - Sets the template for your project to the Angular template.
25+
* `--vue`, `--vuejs` - Sets the template for your project to the Vue.js template.
2426

2527
### Attributes
26-
* `<App Name>` is the name of project. The specified name must meet the requirements of all platforms that you want to target. <% if(isConsole) { %>For more information about the `<App Name>` requirements, run `$ tns help create`<% } %><% if(isHtml) { %>For projects that target Android, you can use uppercase or lowercase letters, numbers, and underscores. The name must start with a letter.
28+
* `<App Name>` is the name of project. The specified name must meet the requirements of all platforms that you want to target. If not specified, the NativeScript CLI will ask you for it afterwards. <% if(isConsole) { %>For more information about the `<App Name>` requirements, run `$ tns help create`<% } %><% if(isHtml) { %>For projects that target Android, you can use uppercase or lowercase letters, numbers, and underscores. The name must start with a letter.
2729
For projects that target iOS, you can use uppercase or lowercase letters, numbers, and hyphens.<% } %>
2830
* `<App ID>` is the application identifier for your project. It must be a domain name in reverse and must meet the requirements of all platforms that you want to target. If not specified, the application identifier is set to `org.nativescript.<App name>` <% if(isConsole) { %>For more information about the `<App ID>` requirements, run `$ tns help create`<% } %><% if(isHtml) { %>For projects that target Android, you can use uppercase or lowercase letters, numbers, and underscores in the strings of the reversed domain name, separated by a dot. Strings must be separated by a dot and must start with a letter. For example: `com.nativescript.My_Andro1d_App`
2931
For projects that target iOS, you can use uppercase or lowercase letters, numbers, and hyphens in the strings of the reversed domain name. Strings must be separated by a dot. For example: `com.nativescript.My-i0s-App`.
3032
* `<Template>` is a valid npm package which you want to use as template for your app. You can specify the package by name in the npm registry or by local path or GitHub URL to a directory or .tar.gz containing a package.json file. The contents of the package will be copied to the `app` directory of your project.<% } %>
3133

3234
<% if(isHtml) { %>
35+
36+
### Templates Usage
37+
38+
Based on the selected options, the NativeScript CLI will use the project templates below:
39+
40+
Selected Option | Template
41+
----------|----------
42+
`Plain JavaScript - Hello World`, `--js`, `--javascript` | tns-template-hello-world
43+
`Plain JavaScript - SideDrawer` | tns-template-drawer-navigation
44+
`Plain JavaScript - Tabs` | tns-template-tab-navigation
45+
`Plain TypeScript - Hello World`, `--ts`, `--tsc`, `--typescript` | tns-template-hello-world-ts
46+
`Plain TypeScript - SideDrawer` | tns-template-drawer-navigation-ts
47+
`Plain TypeScript - Tabs` | tns-template-tab-navigation-ts
48+
`Angular - Hello World`, `--ng`, `--angular` | tns-template-hello-world-ng
49+
`Angular - SideDrawer` | tns-template-drawer-navigation-ng
50+
`Angular - Tabs` | tns-template-tab-navigation-ng
51+
`Vue.js`, `--vue`, `--vuejs` | tns-template-blank-vue
52+
3353
### Related Commands
3454

3555
Command | Description

test/project-commands.ts

+26-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ let isProjectCreated: boolean;
1212
let createProjectCalledWithForce: boolean;
1313
let validateProjectCallsCount: number;
1414
const dummyArgs = ["dummyArgsString"];
15+
const expectedFlavorChoices = [
16+
{ key: "Angular", description: "Learn more at https://angular.io/" },
17+
{ key: "Vue.js", description: "Learn more at https://vuejs.org/" },
18+
{ key: "Plain TypeScript", description: "Learn more at https://www.typescriptlang.org/" },
19+
{ key: "Plain JavaScript", description: "Learn more at https://www.javascript.com/" }
20+
];
21+
const expectedTemplateChoices = [
22+
{ key: "Hello World", description: "A Hello World app" },
23+
{ key: "SideDrawer", description: "An app with pre-built pages that uses a drawer for navigation" },
24+
{ key: "Tabs", description: "An app with pre-built pages that uses tabs for navigation" }
25+
];
1526

1627
class ProjectServiceMock implements IProjectService {
1728
async validateProjectName(opts: { projectName: string, force: boolean, pathToProject: string }): Promise<string> {
@@ -68,19 +79,25 @@ describe("Project commands tests", () => {
6879
templateAnswer?: string,
6980
}) {
7081
const prompterStub = <stubs.PrompterStub>testInjector.resolve("$prompter");
71-
const choices: IDictionary<string> = {};
82+
const answers: IDictionary<string> = {};
83+
const questionChoices: IDictionary<any[]> = {};
7284
if (opts.projectNameAnswer) {
73-
choices["First, what will be the name of your app?"] = opts.projectNameAnswer;
85+
answers["First, what will be the name of your app?"] = opts.projectNameAnswer;
7486
}
7587
if (opts.flavorAnswer) {
76-
choices[opts.projectNameAnswer ? "Next" : "First" + ", which flavor would you like to use?"] = opts.flavorAnswer;
88+
const flavorQuestion = opts.projectNameAnswer ? "Next" : "First" + ", which flavor would you like to use?";
89+
answers[flavorQuestion] = opts.flavorAnswer;
90+
questionChoices[flavorQuestion] = expectedFlavorChoices;
7791
}
7892
if (opts.templateAnswer) {
79-
choices[opts.projectNameAnswer ? "Finally" : "Next" + ", which template would you like to start from?"] = opts.templateAnswer;
93+
const templateQuestion = opts.projectNameAnswer ? "Finally" : "Next" + ", which template would you like to start from?";
94+
answers[templateQuestion] = opts.templateAnswer;
95+
questionChoices[templateQuestion] = expectedTemplateChoices;
8096
}
8197

8298
prompterStub.expect({
83-
choices
99+
answers,
100+
questionChoices
84101
});
85102
}
86103

@@ -171,21 +188,21 @@ describe("Project commands tests", () => {
171188
});
172189

173190
it("should ask for a template when ts flavor is selected.", async () => {
174-
setupAnswers({ flavorAnswer: constants.TsFlavorName, templateAnswer: "Hello World" });
191+
setupAnswers({ flavorAnswer: constants.TsFlavorName, templateAnswer: "SideDrawer" });
175192

176193
await createProjectCommand.execute(dummyArgs);
177194

178-
assert.deepEqual(selectedTemplateName, "tns-template-hello-world-ts");
195+
assert.deepEqual(selectedTemplateName, "tns-template-drawer-navigation-ts");
179196
assert.equal(validateProjectCallsCount, 1);
180197
assert.isTrue(createProjectCalledWithForce);
181198
});
182199

183200
it("should ask for a template when js flavor is selected.", async () => {
184-
setupAnswers({ flavorAnswer: constants.JsFlavorName, templateAnswer: "Hello World" });
201+
setupAnswers({ flavorAnswer: constants.JsFlavorName, templateAnswer: "Tabs" });
185202

186203
await createProjectCommand.execute(dummyArgs);
187204

188-
assert.deepEqual(selectedTemplateName, "tns-template-hello-world");
205+
assert.deepEqual(selectedTemplateName, "tns-template-tab-navigation");
189206
assert.equal(validateProjectCallsCount, 1);
190207
assert.isTrue(createProjectCalledWithForce);
191208
});

test/stubs.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,15 @@ export class LockFile {
514514
export class PrompterStub implements IPrompter {
515515
private strings: IDictionary<string> = {};
516516
private passwords: IDictionary<string> = {};
517-
private choices: IDictionary<string> = {};
517+
private answers: IDictionary<string> = {};
518+
private questionChoices: IDictionary<any[]> = {};
518519

519-
expect(options?: { strings?: IDictionary<string>, passwords?: IDictionary<string>, choices?: IDictionary<string> }) {
520+
expect(options?: { strings?: IDictionary<string>, passwords?: IDictionary<string>, answers?: IDictionary<string>, questionChoices?: IDictionary<any[]> }) {
520521
if (options) {
521522
this.strings = options.strings || this.strings;
522523
this.passwords = options.passwords || this.passwords;
523-
this.choices = options.choices || this.choices;
524+
this.answers = options.answers || this.answers;
525+
this.questionChoices = options.questionChoices || this.questionChoices;
524526
}
525527
}
526528

@@ -543,9 +545,10 @@ export class PrompterStub implements IPrompter {
543545
throw unreachable();
544546
}
545547
async promptForDetailedChoice(question: string, choices: any[]): Promise<string> {
546-
chai.assert.ok(question in this.choices, `PrompterStub didn't expect to be asked: ${question}`);
547-
const result = this.choices[question];
548-
delete this.choices[question];
548+
chai.assert.ok(question in this.answers, `PrompterStub didn't expect to be asked: ${question}`);
549+
chai.assert.deepEqual(choices, this.questionChoices[question]);
550+
const result = this.answers[question];
551+
delete this.answers[question];
549552
return result;
550553
}
551554
async confirm(prompt: string, defaultAction?: () => boolean): Promise<boolean> {

0 commit comments

Comments
 (0)