|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -var InitCommand = require('ember-cli/lib/commands/init'); |
4 |
| - |
5 |
| -module.exports = InitCommand .extend({ |
6 |
| - availableOptions: [ |
7 |
| - { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, |
8 |
| - { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, |
9 |
| - { name: 'blueprint', type: String, aliases: ['b'] }, |
10 |
| - { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, |
11 |
| - { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, |
12 |
| - { name: 'name', type: String, default: '', aliases: ['n'] } |
13 |
| - ], |
14 |
| - |
15 |
| - _defaultBlueprint: function() { |
16 |
| - if (this.project.isEmberCLIAddon()) { |
17 |
| - return 'addon'; |
18 |
| - } else { |
19 |
| - return 'ng2'; |
| 3 | +var Command = require('ember-cli/lib/models/command'); |
| 4 | +var Promise = require('ember-cli/lib/ext/promise'); |
| 5 | +var SilentError = require('silent-error'); |
| 6 | +var validProjectName = require('ember-cli/lib/utilities/valid-project-name'); |
| 7 | +var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option'); |
| 8 | +var GitInit = require('../tasks/git-init'); |
| 9 | + |
| 10 | +module.exports = Command.extend({ |
| 11 | + name: 'init', |
| 12 | + description: 'Creates a new angular-cli project in the current folder.', |
| 13 | + aliases: ['i'], |
| 14 | + works: 'everywhere', |
| 15 | + |
| 16 | + availableOptions: [ |
| 17 | + { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, |
| 18 | + { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, |
| 19 | + { name: 'blueprint', type: String, aliases: ['b'] }, |
| 20 | + { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, |
| 21 | + { name: 'skip-bower', type: Boolean, default: false, aliases: ['sb'] }, |
| 22 | + { name: 'name', type: String, default: '', aliases: ['n'] } |
| 23 | + ], |
| 24 | + |
| 25 | + anonymousOptions: [ |
| 26 | + '<glob-pattern>' |
| 27 | + ], |
| 28 | + |
| 29 | + _defaultBlueprint: function() { |
| 30 | + if (this.project.isEmberCLIAddon()) { |
| 31 | + return 'addon'; |
| 32 | + } else { |
| 33 | + return 'ng2'; |
| 34 | + } |
| 35 | + }, |
| 36 | + |
| 37 | + run: function(commandOptions, rawArgs) { |
| 38 | + if (commandOptions.dryRun) { |
| 39 | + commandOptions.skipNpm = true; |
| 40 | + commandOptions.skipBower = true; |
| 41 | + } |
| 42 | + |
| 43 | + var installBlueprint = new this.tasks.InstallBlueprint({ |
| 44 | + ui: this.ui, |
| 45 | + analytics: this.analytics, |
| 46 | + project: this.project |
| 47 | + }); |
| 48 | + |
| 49 | + // needs an explicit check in case it's just 'undefined' |
| 50 | + // due to passing of options from 'new' and 'addon' |
| 51 | + if (commandOptions.skipGit === false) { |
| 52 | + var gitInit = new GitInit({ |
| 53 | + ui: this.ui, |
| 54 | + project: this.project |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + if (!commandOptions.skipNpm) { |
| 59 | + var npmInstall = new this.tasks.NpmInstall({ |
| 60 | + ui: this.ui, |
| 61 | + analytics: this.analytics, |
| 62 | + project: this.project |
| 63 | + }); |
| 64 | + } |
| 65 | + |
| 66 | + if (!commandOptions.skipBower) { |
| 67 | + var bowerInstall = new this.tasks.BowerInstall({ |
| 68 | + ui: this.ui, |
| 69 | + analytics: this.analytics, |
| 70 | + project: this.project |
| 71 | + }); |
| 72 | + } |
| 73 | + |
| 74 | + var project = this.project; |
| 75 | + var packageName = commandOptions.name !== '.' && commandOptions.name || project.name(); |
| 76 | + |
| 77 | + if (!packageName) { |
| 78 | + var message = 'The `ng ' + this.name + '` command requires a ' + |
| 79 | + 'package.json in current folder with name attribute or a specified name via arguments. ' + |
| 80 | + 'For more details, use `ng help`.'; |
| 81 | + |
| 82 | + return Promise.reject(new SilentError(message)); |
| 83 | + } |
| 84 | + |
| 85 | + var blueprintOpts = { |
| 86 | + dryRun: commandOptions.dryRun, |
| 87 | + blueprint: commandOptions.blueprint || this._defaultBlueprint(), |
| 88 | + rawName: packageName, |
| 89 | + targetFiles: rawArgs || '', |
| 90 | + rawArgs: rawArgs.toString() |
| 91 | + }; |
| 92 | + |
| 93 | + if (!validProjectName(packageName)) { |
| 94 | + return Promise.reject(new SilentError('We currently do not support a name of `' + packageName + '`.')); |
| 95 | + } |
| 96 | + |
| 97 | + blueprintOpts.blueprint = normalizeBlueprint(blueprintOpts.blueprint); |
| 98 | + |
| 99 | + return installBlueprint.run(blueprintOpts) |
| 100 | + .then(function() { |
| 101 | + if (commandOptions.skipGit === false) { |
| 102 | + return gitInit.run(commandOptions, rawArgs); |
| 103 | + } |
| 104 | + }.bind(this)) |
| 105 | + .then(function() { |
| 106 | + if (!commandOptions.skipNpm) { |
| 107 | + return npmInstall.run({ |
| 108 | + verbose: commandOptions.verbose, |
| 109 | + optional: false |
| 110 | + }); |
| 111 | + } |
| 112 | + }) |
| 113 | + .then(function() { |
| 114 | + if (!commandOptions.skipBower) { |
| 115 | + return bowerInstall.run({ |
| 116 | + verbose: commandOptions.verbose |
| 117 | + }); |
20 | 118 | }
|
21 |
| - }, |
| 119 | + }); |
| 120 | + } |
22 | 121 | });
|
23 | 122 |
|
24 | 123 | module.exports.overrideCore = true;
|
0 commit comments