Skip to content

Commit

Permalink
perf(ng new): command to link to angular-cli (#778)
Browse files Browse the repository at this point in the history
add `--link-cli` command to link newly generated project to the global `angular-cli`
package. reduces `ng new ...` command time with about 50%
  • Loading branch information
Ionut Achim authored and filipesilva committed May 19, 2016
1 parent 482aa74 commit 9b8334f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions addon/ng2/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'] },
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions addon/ng2/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down
22 changes: 22 additions & 0 deletions addon/ng2/tasks/link-cli.ts
Original file line number Diff line number Diff line change
@@ -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();
}
});
});
}
});

0 comments on commit 9b8334f

Please sign in to comment.