UNPKG

5.82 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const path = require("path");
5const denodeify = require("denodeify");
6const init_1 = require("./init");
7const config_1 = require("../models/config");
8const validate_project_name_1 = require("../utilities/validate-project-name");
9const common_tags_1 = require("common-tags");
10const Command = require('../ember-cli/lib/models/command');
11const Project = require('../ember-cli/lib/models/project');
12const SilentError = require('silent-error');
13const mkdir = denodeify(fs.mkdir);
14const NewCommand = Command.extend({
15 name: 'new',
16 description: `Creates a new directory and a new Angular app.`,
17 works: 'outsideProject',
18 availableOptions: [
19 {
20 name: 'dry-run',
21 type: Boolean,
22 default: false,
23 aliases: ['d'],
24 description: 'Run through without making any changes.'
25 },
26 {
27 name: 'verbose',
28 type: Boolean,
29 default: false,
30 aliases: ['v'],
31 description: 'Adds more details to output logging.'
32 },
33 {
34 name: 'link-cli',
35 type: Boolean,
36 default: false,
37 aliases: ['lc'],
38 description: 'Automatically link the `@angular/cli` package.'
39 },
40 {
41 name: 'ng4',
42 type: Boolean,
43 default: false,
44 description: 'Create a project with Angular 4 in the template.'
45 },
46 {
47 name: 'skip-install',
48 type: Boolean,
49 default: false,
50 aliases: ['si'],
51 description: 'Skip installing packages.'
52 },
53 {
54 name: 'skip-git',
55 type: Boolean,
56 default: false,
57 aliases: ['sg'],
58 description: 'Skip initializing a git repository.'
59 },
60 {
61 name: 'skip-tests',
62 type: Boolean,
63 default: false,
64 aliases: ['st'],
65 description: 'Skip creating spec files.'
66 },
67 {
68 name: 'skip-commit',
69 type: Boolean,
70 default: false,
71 aliases: ['sc'],
72 description: 'Skip committing the first commit to git.'
73 },
74 {
75 name: 'directory',
76 type: String,
77 aliases: ['dir'],
78 description: 'The directory name to create the app in.'
79 },
80 {
81 name: 'source-dir',
82 type: String,
83 default: 'src',
84 aliases: ['sd'],
85 description: 'The name of the source directory.'
86 },
87 {
88 name: 'style',
89 type: String,
90 default: 'css',
91 description: 'The style file default extension.'
92 },
93 {
94 name: 'prefix',
95 type: String,
96 default: 'app',
97 aliases: ['p'],
98 description: 'The prefix to use for all component selectors.'
99 },
100 {
101 name: 'routing',
102 type: Boolean,
103 default: false,
104 description: 'Generate a routing module.'
105 },
106 {
107 name: 'inline-style',
108 type: Boolean,
109 default: false,
110 aliases: ['is'],
111 description: 'Should have an inline style.'
112 },
113 {
114 name: 'inline-template',
115 type: Boolean,
116 default: false,
117 aliases: ['it'],
118 description: 'Should have an inline template.'
119 }
120 ],
121 isProject: function (projectPath) {
122 return config_1.CliConfig.fromProject(projectPath) !== null;
123 },
124 run: function (commandOptions, rawArgs) {
125 const packageName = rawArgs.shift();
126 if (!packageName) {
127 return Promise.reject(new SilentError(`The "ng ${this.name}" command requires a name argument to be specified. ` +
128 `For more details, use "ng help".`));
129 }
130 validate_project_name_1.validateProjectName(packageName);
131 commandOptions.name = packageName;
132 if (commandOptions.dryRun) {
133 commandOptions.skipGit = true;
134 }
135 const directoryName = path.join(process.cwd(), commandOptions.directory ? commandOptions.directory : packageName);
136 const initCommand = new init_1.default({
137 ui: this.ui,
138 tasks: this.tasks,
139 project: Project.nullProject(this.ui, this.cli)
140 });
141 let createDirectory;
142 if (commandOptions.dryRun) {
143 createDirectory = Promise.resolve()
144 .then(() => {
145 if (fs.existsSync(directoryName) && this.isProject(directoryName)) {
146 throw new SilentError(common_tags_1.oneLine `
147 Directory ${directoryName} exists and is already an Angular CLI project.
148 `);
149 }
150 });
151 }
152 else {
153 createDirectory = mkdir(directoryName)
154 .catch(err => {
155 if (err.code === 'EEXIST') {
156 if (this.isProject(directoryName)) {
157 throw new SilentError(common_tags_1.oneLine `
158 Directory ${directoryName} exists and is already an Angular CLI project.
159 `);
160 }
161 }
162 else {
163 throw err;
164 }
165 })
166 .then(() => process.chdir(directoryName));
167 }
168 return createDirectory
169 .then(initCommand.run.bind(initCommand, commandOptions, rawArgs));
170 }
171});
172NewCommand.overrideCore = true;
173exports.default = NewCommand;
174//# sourceMappingURL=/users/hans/sources/angular-cli/commands/new.js.map
\No newline at end of file