UNPKG

4.04 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11const command_1 = require("../models/command");
12const config_1 = require("../utilities/config");
13const schematic_command_1 = require("../models/schematic-command");
14class NewCommand extends schematic_command_1.SchematicCommand {
15 constructor() {
16 super(...arguments);
17 this.name = 'new';
18 this.description = 'Creates a new directory and a new Angular app.';
19 this.scope = command_1.CommandScope.outsideProject;
20 this.allowMissingWorkspace = true;
21 this.arguments = [];
22 this.options = [
23 ...this.coreOptions,
24 {
25 name: 'verbose',
26 type: Boolean,
27 default: false,
28 aliases: ['v'],
29 description: 'Adds more details to output logging.'
30 },
31 {
32 name: 'collection',
33 type: String,
34 aliases: ['c'],
35 description: 'Schematics collection to use.'
36 }
37 ];
38 this.schematicName = 'ng-new';
39 this.initialized = false;
40 }
41 initialize(options) {
42 if (this.initialized) {
43 return Promise.resolve();
44 }
45 super.initialize(options);
46 this.initialized = true;
47 const collectionName = this.parseCollectionName(options);
48 return this.getOptions({
49 schematicName: this.schematicName,
50 collectionName,
51 })
52 .then((schematicOptions) => {
53 this.options = this.options.concat(schematicOptions.options);
54 const args = schematicOptions.arguments.map(arg => arg.name);
55 this.arguments = this.arguments.concat(args);
56 });
57 }
58 run(options) {
59 return __awaiter(this, void 0, void 0, function* () {
60 if (options.dryRun) {
61 options.skipGit = true;
62 }
63 let collectionName;
64 if (options.collection) {
65 collectionName = options.collection;
66 }
67 else {
68 collectionName = this.parseCollectionName(options);
69 }
70 const pathOptions = this.setPathOptions(options, '/');
71 options = Object.assign({}, options, pathOptions);
72 const packageJson = require('../package.json');
73 options.version = packageJson.version;
74 // Ensure skipGit has a boolean value.
75 options.skipGit = options.skipGit === undefined ? false : options.skipGit;
76 options = this.removeLocalOptions(options);
77 return this.runSchematic({
78 collectionName: collectionName,
79 schematicName: this.schematicName,
80 schematicOptions: options,
81 debug: options.debug,
82 dryRun: options.dryRun,
83 force: options.force
84 });
85 });
86 }
87 parseCollectionName(options) {
88 const collectionName = options.collection || options.c || config_1.getDefaultSchematicCollection();
89 return collectionName;
90 }
91 removeLocalOptions(options) {
92 const opts = Object.assign({}, options);
93 delete opts.verbose;
94 delete opts.collection;
95 return opts;
96 }
97}
98NewCommand.aliases = ['n'];
99exports.default = NewCommand;
100//# sourceMappingURL=/Users/hansl/Sources/hansl/angular-cli/commands/new.js.map
\No newline at end of file