forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.ts
More file actions
112 lines (95 loc) · 3.26 KB
/
Copy pathinit.ts
File metadata and controls
112 lines (95 loc) · 3.26 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import * as chalk from 'chalk';
import LinkCli from '../tasks/link-cli';
import NpmInstall from '../tasks/npm-install';
import { validateProjectName } from '../utilities/validate-project-name';
import {checkYarnOrCNPM} from '../utilities/check-package-manager';
import {CliConfig} from '../models/config';
const Task = require('../ember-cli/lib/models/task');
const SilentError = require('silent-error');
const GitInit = require('../tasks/git-init');
const packageJson = require('../package.json');
export default Task.extend({
run: function (commandOptions: any, rawArgs: string[]) {
if (commandOptions.dryRun) {
commandOptions.skipInstall = true;
}
// needs an explicit check in case it's just 'undefined'
// due to passing of options from 'new' and 'addon'
let gitInit: any;
if (commandOptions.skipGit === false) {
gitInit = new GitInit({
ui: this.ui,
project: this.project
});
}
const packageManager = CliConfig.fromGlobal().get('packageManager');
let npmInstall: any;
if (!commandOptions.skipInstall) {
npmInstall = new NpmInstall({
ui: this.ui,
project: this.project,
packageManager
});
}
let linkCli: any;
if (commandOptions.linkCli) {
linkCli = new LinkCli({
ui: this.ui,
project: this.project,
packageManager
});
}
const project = this.project;
const packageName = commandOptions.name !== '.' && commandOptions.name || project.name();
if (commandOptions.style === undefined) {
commandOptions.style = CliConfig.fromGlobal().get('defaults.styleExt');
}
if (!packageName) {
const message = 'The `ng ' + this.name + '` command requires a ' +
'package.json in current folder with name attribute or a specified name via arguments. ' +
'For more details, use `ng help`.';
return Promise.reject(new SilentError(message));
}
validateProjectName(packageName);
const SchematicRunTask = require('../tasks/schematic-run').default;
const schematicRunTask = new SchematicRunTask({
ui: this.ui,
project: this.project
});
const cwd = this.project.root;
const schematicName = CliConfig.fromGlobal().get('defaults.schematics.newApp');
commandOptions.version = packageJson.version;
const runOptions = {
taskOptions: commandOptions,
workingDir: cwd,
collectionName: commandOptions.collectionName,
schematicName
};
return schematicRunTask.run(runOptions)
.then(function () {
if (!commandOptions.dryRun) {
process.chdir(commandOptions.directory);
}
})
.then(function () {
if (!commandOptions.skipInstall) {
return checkYarnOrCNPM().then(() => npmInstall.run());
}
})
.then(function () {
if (!commandOptions.dryRun && commandOptions.skipGit === false) {
return gitInit.run(commandOptions, rawArgs);
}
})
.then(function () {
if (!commandOptions.dryRun && commandOptions.linkCli) {
return linkCli.run();
}
})
.then(() => {
if (!commandOptions.dryRun) {
this.ui.writeLine(chalk.green(`Project '${packageName}' successfully created.`));
}
});
}
});