-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathcreate-project.ts
48 lines (40 loc) · 1.73 KB
/
create-project.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as constants from "../constants";
import * as path from "path";
export class CreateProjectCommand implements ICommand {
public enableHooks = false;
public allowedParameters: ICommandParameter[] = [this.$stringParameterBuilder.createMandatoryParameter("Project name cannot be empty.")];
private createdProjecData: ICreateProjectData;
constructor(private $projectService: IProjectService,
private $logger: ILogger,
private $errors: IErrors,
private $options: IOptions,
private $stringParameterBuilder: IStringParameterBuilder) { }
public async execute(args: string[]): Promise<void> {
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: string;
if (this.$options.tsc) {
selectedTemplate = constants.TYPESCRIPT_NAME;
} else if (this.$options.ng) {
selectedTemplate = constants.ANGULAR_NAME;
} else {
selectedTemplate = this.$options.template;
}
this.createdProjecData = await this.$projectService.createProject({
projectName: args[0],
template: selectedTemplate,
appId: this.$options.appid,
pathToProject: this.$options.path,
force: this.$options.force,
ignoreScripts: this.$options.ignoreScripts
});
}
public async postCommandAction(args: string[]): Promise<void> {
const { projectDir } = this.createdProjecData;
const relativePath = path.relative(process.cwd(), projectDir);
this.$logger.printMarkdown(`Now you can navigate to your project with \`$ cd ${relativePath}\``);
this.$logger.printMarkdown(`After that you can run it on device/emulator by executing \`$ tns run <platform>\``);
}
}
$injector.registerCommand("create", CreateProjectCommand);