diff --git a/addon/ng2/commands/init.js b/addon/ng2/commands/init.js index 71222d146b2d..f77a1c2852b7 100644 --- a/addon/ng2/commands/init.js +++ b/addon/ng2/commands/init.js @@ -6,6 +6,7 @@ var SilentError = require('silent-error'); var validProjectName = require('ember-cli/lib/utilities/valid-project-name'); var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option'); var GitInit = require('../tasks/git-init'); +var LinkCli = require('../tasks/link-cli'); module.exports = Command.extend({ name: 'init', @@ -17,6 +18,7 @@ module.exports = Command.extend({ { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, { name: 'blueprint', type: String, aliases: ['b'] }, + { name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] }, { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, { name: 'name', type: String, default: '', aliases: ['n'] }, @@ -57,6 +59,14 @@ module.exports = Command.extend({ }); } + if (commandOptions.linkCli) { + var linkCli = new LinkCli({ + ui: this.ui, + analytics: this.analytics, + project: this.project + }); + } + if (!commandOptions.skipNpm) { var npmInstall = new this.tasks.NpmInstall({ ui: this.ui, @@ -109,6 +119,14 @@ module.exports = Command.extend({ return gitInit.run(commandOptions, rawArgs); } }.bind(this)) + .then(function () { + if (commandOptions.linkCli) { + return linkCli.run({ + verbose: commandOptions.verbose, + optional: false + }); + } + }) .then(function () { if (!commandOptions.skipNpm) { return npmInstall.run({ diff --git a/addon/ng2/commands/new.ts b/addon/ng2/commands/new.ts index 253778c1e7d8..685e4e3e1124 100644 --- a/addon/ng2/commands/new.ts +++ b/addon/ng2/commands/new.ts @@ -16,6 +16,7 @@ const NewCommand = Command.extend({ { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, { name: 'blueprint', type: String, default: 'ng2', aliases: ['b'] }, + { name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] }, { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }, diff --git a/addon/ng2/tasks/link-cli.ts b/addon/ng2/tasks/link-cli.ts new file mode 100644 index 000000000000..181993cac6b1 --- /dev/null +++ b/addon/ng2/tasks/link-cli.ts @@ -0,0 +1,22 @@ +import * as Promise from 'ember-cli/lib/ext/promise'; +import * as Task from 'ember-cli/lib/models/task'; +import * as chalk from 'chalk'; +import {exec} from 'child_process'; + +module.exports = Task.extend({ + run: function() { + var ui = this.ui; + + return new Promise(function(resolve, reject) { + exec('npm link angular-cli', (err) => { + if (err) { + ui.writeLine(chalk.red('Couldn\'t do \'npm link angular-cli\'.')); + reject(); + } else { + ui.writeLine(chalk.green('Successfully linked to angular-cli.')); + resolve(); + } + }); + }); + } +});