UNPKG

3.97 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const chalk = require("chalk");
4const link_cli_1 = require("../tasks/link-cli");
5const npm_install_1 = require("../tasks/npm-install");
6const validate_project_name_1 = require("../utilities/validate-project-name");
7const check_package_manager_1 = require("../utilities/check-package-manager");
8const config_1 = require("../models/config");
9const Task = require('../ember-cli/lib/models/task');
10const Promise = require('../ember-cli/lib/ext/promise');
11const SilentError = require('silent-error');
12const normalizeBlueprint = require('../ember-cli/lib/utilities/normalize-blueprint-option');
13const GitInit = require('../tasks/git-init');
14exports.default = Task.extend({
15 run: function (commandOptions, rawArgs) {
16 if (commandOptions.dryRun) {
17 commandOptions.skipInstall = true;
18 }
19 const installBlueprint = new this.tasks.InstallBlueprint({
20 ui: this.ui,
21 project: this.project
22 });
23 // needs an explicit check in case it's just 'undefined'
24 // due to passing of options from 'new' and 'addon'
25 let gitInit;
26 if (commandOptions.skipGit === false) {
27 gitInit = new GitInit({
28 ui: this.ui,
29 project: this.project
30 });
31 }
32 let npmInstall;
33 if (!commandOptions.skipInstall) {
34 const packageManager = config_1.CliConfig.fromGlobal().get('packageManager');
35 npmInstall = new npm_install_1.default({
36 ui: this.ui,
37 project: this.project,
38 packageManager
39 });
40 }
41 let linkCli;
42 if (commandOptions.linkCli) {
43 linkCli = new link_cli_1.default({
44 ui: this.ui,
45 project: this.project
46 });
47 }
48 const project = this.project;
49 const packageName = commandOptions.name !== '.' && commandOptions.name || project.name();
50 if (!packageName) {
51 const message = 'The `ng ' + this.name + '` command requires a ' +
52 'package.json in current folder with name attribute or a specified name via arguments. ' +
53 'For more details, use `ng help`.';
54 return Promise.reject(new SilentError(message));
55 }
56 const blueprintOpts = {
57 dryRun: commandOptions.dryRun,
58 blueprint: 'ng',
59 rawName: packageName,
60 targetFiles: rawArgs || '',
61 rawArgs: rawArgs.toString(),
62 sourceDir: commandOptions.sourceDir,
63 style: commandOptions.style,
64 prefix: commandOptions.prefix,
65 routing: commandOptions.routing,
66 inlineStyle: commandOptions.inlineStyle,
67 inlineTemplate: commandOptions.inlineTemplate,
68 ignoredUpdateFiles: ['favicon.ico'],
69 ng4: commandOptions.ng4,
70 skipGit: commandOptions.skipGit,
71 skipTests: commandOptions.skipTests
72 };
73 validate_project_name_1.validateProjectName(packageName);
74 blueprintOpts.blueprint = normalizeBlueprint(blueprintOpts.blueprint);
75 return installBlueprint.run(blueprintOpts)
76 .then(function () {
77 if (commandOptions.skipGit === false) {
78 return gitInit.run(commandOptions, rawArgs);
79 }
80 })
81 .then(function () {
82 if (!commandOptions.skipInstall) {
83 return npmInstall.run();
84 }
85 })
86 .then(function () {
87 if (commandOptions.linkCli) {
88 return linkCli.run();
89 }
90 })
91 .then(check_package_manager_1.checkYarnOrCNPM)
92 .then(() => {
93 this.ui.writeLine(chalk.green(`Project '${packageName}' successfully created.`));
94 });
95 }
96});
97//# sourceMappingURL=/users/hans/sources/angular-cli/tasks/init.js.map
\No newline at end of file