Skip to content

create --tsc option added + tests #1832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/man_pages/project/creation/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ create
Usage | Synopsis
---|---
Create from default JavaScript template | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>]`
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>]`
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>]`
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>]`
Copy from existing project | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>] --copy-from <Directory>`
Create from custom template | `$ tns create <App Name> [--path <Directory>] [--appid <App ID>] --template <Template>`
Expand All @@ -17,6 +17,7 @@ Creates a new project for native development with NativeScript.
* `--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.
* `--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.<% } %>
* `--ng` - Sets the template for your project to the Angular template.
* `--tsc` - Sets the template for your project to the TypeScript template.

### Attributes
* `<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.
Expand Down
13 changes: 10 additions & 3 deletions lib/commands/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ export class CreateProjectCommand implements ICommand {

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

let selectedTemplate = this.$options.ng ? constants.ANGULAR_NAME : this.$options.template;
let selectedTemplate: string;
if (this.$options.tsc) {
selectedTemplate = constants.TYPESCRIPT_NAME;
} else if (this.$options.ng) {
selectedTemplate = constants.ANGULAR_NAME;
} else {
selectedTemplate = this.$options.template;
}

this.$projectService.createProject(args[0], selectedTemplate).wait();
}).future<void>()();
Expand Down
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ class ItunesConnectApplicationTypesClass implements IiTunesConnectApplicationTyp
export let ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesClass();

export let ANGULAR_NAME = "angular";
export let TYPESCRIPT_NAME = "TypeScript";
1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface IOptions extends ICommonOptions {
keyStorePath: string;
linkTo: string;
ng: boolean;
tsc: boolean;
bundle: boolean;
platformTemplate: string;
port: Number;
Expand Down
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class Options extends commonOptionsLibPath.OptionsBase {
baseConfig: { type: OptionType.String },
platformTemplate: { type: OptionType.String },
ng: {type: OptionType.Boolean },
tsc: {type: OptionType.Boolean },
bundle: {type: OptionType.Boolean },
all: {type: OptionType.Boolean },
teamId: { type: OptionType.String }
Expand Down
33 changes: 33 additions & 0 deletions test/project-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe("Project commands tests", () => {
assert.isTrue(isProjectCreated);
});

it("should not fail when using only --tsc.", () => {
options.tsc = true;

createProjectCommand.execute(dummyArgs).wait();

assert.isTrue(isProjectCreated);
});

it("should not fail when using only --template.", () => {
options.template = "ng";

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

it("should set the template name correctly when used --tsc.", () => {
options.tsc = true;

createProjectCommand.execute(dummyArgs).wait();

assert.deepEqual(selectedTemplateName, constants.TYPESCRIPT_NAME);
});

it("should not set the template name when --ng is not used.", () => {
options.ng = false;

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

it("should not set the template name when --tsc is not used.", () => {
options.tsc = false;

createProjectCommand.execute(dummyArgs).wait();

assert.isUndefined(selectedTemplateName);
});

it("should fail when --ng and --template are used simultaneously.", () => {
options.ng = true;
options.template = "ng";
Expand All @@ -97,5 +121,14 @@ describe("Project commands tests", () => {
createProjectCommand.execute(dummyArgs).wait();
});
});

it("should fail when --tsc and --template are used simultaneously.", () => {
options.tsc = true;
options.template = "tsc";

assert.throws(() => {
createProjectCommand.execute(dummyArgs).wait();
});
});
});
});