Skip to content

Commit

Permalink
install:addon will show a deprecation warning then it will run the …
Browse files Browse the repository at this point in the history
…`install` command. Changed the verbage on install-npm.
  • Loading branch information
DanielOchoa committed Apr 8, 2015
1 parent d8a1081 commit 9465b05
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 33 deletions.
21 changes: 12 additions & 9 deletions lib/commands/install-addon.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
'use strict';

var Command = require('../models/command');
var SilentError = require('../errors/silent');
var Promise = require('../ext/promise');
var InstallCommand = require('./install');
var chalk = require('chalk');

module.exports = Command.extend({
module.exports = InstallCommand.extend({
name: 'install:addon',
description: 'Deprecated. You can use `ember install` for ember-cli addons.',
description: 'This command has been deprecated. Please use `ember install` instead.',
works: 'insideProject',

anonymousOptions: [
'<addon-name>'
],

run: function() {
var err = 'This command has been deprecated. Please use `ember install ';
err += '<addonName>` instead.';
return Promise.reject(new SilentError(err));
init: function() {
var warning = 'This command has been deprecated. Please use `ember ';
warning += 'install <addonName>` instead.';
this.ui.writeLine(chalk.red(warning));

if (this._super.init) {
this._super.init();
}
}
});
4 changes: 2 additions & 2 deletions lib/commands/install-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ var Promise = require('../ext/promise');

module.exports = Command.extend({
name: 'install:npm',
description: 'Deprecated. Npm package installs are now managed by the user.',
description: 'Npm package installs are now managed by the user.',
works: 'insideProject',

anonymousOptions: [
'<package-names...>'
],

run: function() {
var err = 'This command has been deprecated. Please use `npm install ';
var err = 'This command has been removed. Please use `npm install ';
err += '<packageName> --save-dev --save-exact` instead.';
return Promise.reject(new SilentError(err));
}
Expand Down
83 changes: 62 additions & 21 deletions tests/unit/commands/install-addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@
var expect = require('chai').expect;
var InstallAddonCommand = require('../../../lib/commands/install-addon');
var commandOptions = require('../../factories/command-options');
var AddonInstall = require('../../../lib/tasks/addon-install');
var Task = require('../../../lib/models/task');
var Promise = require('../../../lib/ext/promise');
var stub = require('../../helpers/stub').stub;
var Project = require('../../../lib/models/project');

describe('install:addon command', function() {
var command, options, msg;
before(function() {
var command, options, tasks, npmInstance, generateBlueprintInstance;

beforeEach(function() {
tasks = {
AddonInstall: AddonInstall,
NpmInstall: Task.extend({
init: function() {
npmInstance = this;
}
}),

GenerateFromBlueprint: Task.extend({
init: function() {
generateBlueprintInstance = this;
}
})
};

options = commandOptions({
settings: {},
project: {
Expand All @@ -15,33 +36,53 @@ describe('install:addon command', function() {
},
isEmberCLIProject: function() {
return true;
}
}
},
initializeAddons: function() { },
reloadAddons: function() {
this.addons = [{
pkg: {
name: 'ember-cli-photoswipe',
'ember-addon': {
defaultBlueprint: 'photoswipe'
}
}
}];
},

findAddonByName: Project.prototype.findAddonByName
},

tasks: tasks
});

stub(tasks.NpmInstall.prototype, 'run', Promise.resolve());
stub(tasks.GenerateFromBlueprint.prototype, 'run', Promise.resolve());

command = new InstallAddonCommand(options);

msg = 'This command has been deprecated. Please use `ember install ';
msg += '<addonName>` instead.';
});

describe('with args', function() {
it('gives a helpful message if no arguments are passed', function() {
return command.validateAndRun(['ember-cli-cordova']).then(function() {
expect(false, 'should reject with error');
}).catch(function(err) {
expect(err.message).to.equal(msg, 'expect error to have a helpful message');
});
});
afterEach(function() {
tasks.NpmInstall.prototype.run.restore();
tasks.GenerateFromBlueprint.prototype.run.restore();
});

describe('without args', function() {
it('gives a helpful message if no arguments are passed', function() {
return command.validateAndRun([]).then(function() {
expect(false, 'should reject with error');
}).catch(function(err) {
expect(err.message).to.equal(msg, 'expect error to have a helpful message');
});

it('will show a deprecation warning', function() {
return command.validateAndRun(['ember-cli-photoswipe']).then(function() {
var msg = 'This command has been deprecated. Please use `ember install ';
msg += '<addonName>` instead.';

expect(command.ui.output).to.include(msg);

expect(npmInstance.ui, 'ui was set');
expect(npmInstance.project, 'project was set');
expect(npmInstance.analytics, 'analytics was set');

expect(generateBlueprintInstance.ui, 'ui was set');
expect(generateBlueprintInstance.project, 'project was set');
expect(generateBlueprintInstance.analytics, 'analytics was set');

});
});
});
2 changes: 1 addition & 1 deletion tests/unit/commands/install-npm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('install:npm command', function() {
});

command = new InstallCommand(options);
msg = 'This command has been deprecated. Please use `npm install ';
msg = 'This command has been removed. Please use `npm install ';
msg += '<packageName> --save-dev --save-exact` instead.';
});

Expand Down

0 comments on commit 9465b05

Please sign in to comment.