Skip to content

Commit 9b8334f

Browse files
Ionut Achimfilipesilva
Ionut Achim
authored andcommitted
perf(ng new): command to link to angular-cli (#778)
add `--link-cli` command to link newly generated project to the global `angular-cli` package. reduces `ng new ...` command time with about 50%
1 parent 482aa74 commit 9b8334f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

addon/ng2/commands/init.js

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var SilentError = require('silent-error');
66
var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
77
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
88
var GitInit = require('../tasks/git-init');
9+
var LinkCli = require('../tasks/link-cli');
910

1011
module.exports = Command.extend({
1112
name: 'init',
@@ -17,6 +18,7 @@ module.exports = Command.extend({
1718
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
1819
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
1920
{ name: 'blueprint', type: String, aliases: ['b'] },
21+
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
2022
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
2123
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
2224
{ name: 'name', type: String, default: '', aliases: ['n'] },
@@ -57,6 +59,14 @@ module.exports = Command.extend({
5759
});
5860
}
5961

62+
if (commandOptions.linkCli) {
63+
var linkCli = new LinkCli({
64+
ui: this.ui,
65+
analytics: this.analytics,
66+
project: this.project
67+
});
68+
}
69+
6070
if (!commandOptions.skipNpm) {
6171
var npmInstall = new this.tasks.NpmInstall({
6272
ui: this.ui,
@@ -109,6 +119,14 @@ module.exports = Command.extend({
109119
return gitInit.run(commandOptions, rawArgs);
110120
}
111121
}.bind(this))
122+
.then(function () {
123+
if (commandOptions.linkCli) {
124+
return linkCli.run({
125+
verbose: commandOptions.verbose,
126+
optional: false
127+
});
128+
}
129+
})
112130
.then(function () {
113131
if (!commandOptions.skipNpm) {
114132
return npmInstall.run({

addon/ng2/commands/new.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const NewCommand = Command.extend({
1616
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
1717
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
1818
{ name: 'blueprint', type: String, default: 'ng2', aliases: ['b'] },
19+
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
1920
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
2021
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
2122
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },

addon/ng2/tasks/link-cli.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as Promise from 'ember-cli/lib/ext/promise';
2+
import * as Task from 'ember-cli/lib/models/task';
3+
import * as chalk from 'chalk';
4+
import {exec} from 'child_process';
5+
6+
module.exports = Task.extend({
7+
run: function() {
8+
var ui = this.ui;
9+
10+
return new Promise(function(resolve, reject) {
11+
exec('npm link angular-cli', (err) => {
12+
if (err) {
13+
ui.writeLine(chalk.red('Couldn\'t do \'npm link angular-cli\'.'));
14+
reject();
15+
} else {
16+
ui.writeLine(chalk.green('Successfully linked to angular-cli.'));
17+
resolve();
18+
}
19+
});
20+
});
21+
}
22+
});

0 commit comments

Comments
 (0)