Skip to content

Commit 2a8e87c

Browse files
author
Vladimir Enchev
committed
create --tsc option added + tests
1 parent 5e5c839 commit 2a8e87c

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

docs/man_pages/project/creation/create.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ create
44
Usage | Synopsis
55
---|---
66
Create from default JavaScript template | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>]`
7-
Create from default TypeScript template | `$ tns create <App Name> --template typescript [--path <Directory>] [--appid <App ID>]` OR `$ tns create <App Name> --template tsc [--path <Directory>] [--appid <App ID>]`
7+
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>]`
88
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>]`
99
Copy from existing project | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>] --copy-from <Directory>`
1010
Create from custom template | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>] --template <Template>`
@@ -17,6 +17,7 @@ Creates a new project for native development with NativeScript.
1717
* `--copy-from` - Specifies a directory which contains an existing NativeScript project. If `--copy-from` and `--template` are not set, the NativeScript CLI creates the project from the default JavaScript hello-world template.
1818
* `--template` - Specifies a valid npm package which you want to use to create your project. If `--copy-from` and `--template` are 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.<% } %>
1919
* `--ng` - Sets the template for your project to the Angular template.
20+
* `--tsc` - Sets the template for your project to the TypeScript template.
2021

2122
### Attributes
2223
* `<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.

lib/commands/create-project.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ export class CreateProjectCommand implements ICommand {
1010

1111
execute(args: string[]): IFuture<void> {
1212
return (() => {
13-
if (this.$options.ng && this.$options.template) {
14-
this.$errors.fail("You cannot use --ng and --template simultaneously.");
13+
if ((this.$options.tsc || this.$options.ng) && this.$options.template) {
14+
this.$errors.fail("You cannot use --ng or --tsc options together with --template.");
1515
}
1616

17-
let selectedTemplate = this.$options.ng ? constants.ANGULAR_NAME : this.$options.template;
17+
let selectedTemplate: string;
18+
if (this.$options.tsc) {
19+
selectedTemplate = constants.TYPESCRIPT_NAME;
20+
} else if (this.$options.ng) {
21+
selectedTemplate = constants.ANGULAR_NAME;
22+
} else {
23+
selectedTemplate = this.$options.template;
24+
}
1825

1926
this.$projectService.createProject(args[0], selectedTemplate).wait();
2027
}).future<void>()();

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ class ItunesConnectApplicationTypesClass implements IiTunesConnectApplicationTyp
4444
export let ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesClass();
4545

4646
export let ANGULAR_NAME = "angular";
47+
export let TYPESCRIPT_NAME = "TypeScript";

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ interface IOptions extends ICommonOptions {
8282
keyStorePath: string;
8383
linkTo: string;
8484
ng: boolean;
85+
tsc: boolean;
8586
bundle: boolean;
8687
platformTemplate: string;
8788
port: Number;

lib/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class Options extends commonOptionsLibPath.OptionsBase {
3333
baseConfig: { type: OptionType.String },
3434
platformTemplate: { type: OptionType.String },
3535
ng: {type: OptionType.Boolean },
36+
tsc: {type: OptionType.Boolean },
3637
bundle: {type: OptionType.Boolean },
3738
all: {type: OptionType.Boolean },
3839
teamId: { type: OptionType.String }

test/project-commands.ts

+33
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ describe("Project commands tests", () => {
6565
assert.isTrue(isProjectCreated);
6666
});
6767

68+
it("should not fail when using only --tsc.", () => {
69+
options.tsc = true;
70+
71+
createProjectCommand.execute(dummyArgs).wait();
72+
73+
assert.isTrue(isProjectCreated);
74+
});
75+
6876
it("should not fail when using only --template.", () => {
6977
options.template = "ng";
7078

@@ -81,6 +89,14 @@ describe("Project commands tests", () => {
8189
assert.deepEqual(selectedTemplateName, constants.ANGULAR_NAME);
8290
});
8391

92+
it("should set the template name correctly when used --tsc.", () => {
93+
options.tsc = true;
94+
95+
createProjectCommand.execute(dummyArgs).wait();
96+
97+
assert.deepEqual(selectedTemplateName, constants.TYPESCRIPT_NAME);
98+
});
99+
84100
it("should not set the template name when --ng is not used.", () => {
85101
options.ng = false;
86102

@@ -89,6 +105,14 @@ describe("Project commands tests", () => {
89105
assert.isUndefined(selectedTemplateName);
90106
});
91107

108+
it("should not set the template name when --tsc is not used.", () => {
109+
options.tsc = false;
110+
111+
createProjectCommand.execute(dummyArgs).wait();
112+
113+
assert.isUndefined(selectedTemplateName);
114+
});
115+
92116
it("should fail when --ng and --template are used simultaneously.", () => {
93117
options.ng = true;
94118
options.template = "ng";
@@ -97,5 +121,14 @@ describe("Project commands tests", () => {
97121
createProjectCommand.execute(dummyArgs).wait();
98122
});
99123
});
124+
125+
it("should fail when --tsc and --template are used simultaneously.", () => {
126+
options.tsc = true;
127+
options.template = "tsc";
128+
129+
assert.throws(() => {
130+
createProjectCommand.execute(dummyArgs).wait();
131+
});
132+
});
100133
});
101134
});

0 commit comments

Comments
 (0)