Skip to content

fix(new): command to npm link to angular-cli #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should create that closer to where you use it. It's also weird (and will be invalid) to use var linkCli inside a scope block.

Also, use let for local variables to catch these.

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();
}
});
});
}
});