Skip to content

Commit

Permalink
Merge 6e7da1d into cddaef1
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Jul 21, 2015
2 parents cddaef1 + 6e7da1d commit a7c4aa2
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 127 deletions.
9 changes: 8 additions & 1 deletion lib/models/addon-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ AddonDiscovery.prototype.discoverProjectAddons = function(project) {
var projectAsAddon = this.discoverFromProjectItself(project);
var internalAddons = this.discoverFromInternalProjectAddons(project);
var cliAddons = this.discoverFromCli(project.cli);
var dependencyAddons = this.discoverFromDependencies(project.root, project.nodeModulesPath, project.pkg, false);
var dependencyAddons;

if (project.hasDependencies()) {
dependencyAddons = this.discoverFromDependencies(project.root, project.nodeModulesPath, project.pkg, false);
} else {
dependencyAddons = [];
}

var inRepoAddons = this.discoverInRepoAddons(project.root, project.pkg);
var addons = projectAsAddon.concat(cliAddons, internalAddons, dependencyAddons, inRepoAddons);

Expand Down
10 changes: 9 additions & 1 deletion lib/models/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ Command.prototype.constructor = Command;
@method beforeRun
@return {Promise|null}
*/
Command.prototype.beforeRun = function() {};
Command.prototype.beforeRun = function() {

};

/*
@method validateAndRun
Expand Down Expand Up @@ -132,6 +134,12 @@ Command.prototype.validateAndRun = function(args) {
return Promise.resolve();
}

if (this.works === 'insideProject') {
if (!this.project.hasDependencies()) {
throw new SilentError('node_modules appears empty, you may need to run `npm install`');
}
}

return Watcher.detectWatcher(this.ui, commandOptions.options).then(function(options) {
return this.run(options, commandOptions.args);
}.bind(this));
Expand Down
3 changes: 3 additions & 0 deletions lib/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Project.prototype.setupBowerDirectory = function() {
debug('bowerDirectory: %s', this.bowerDirectory);
};

Project.prototype.hasDependencies = function() {
return !!this.nodeModulesPath;
};
/**
Sets the path to the node_modules directory for this
project.
Expand Down
14 changes: 6 additions & 8 deletions tests/factories/command-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
var defaults = require('lodash/object/defaults');
var MockUI = require('../helpers/mock-ui');
var MockAnalytics = require('../helpers/mock-analytics');
var MockProject = require('../helpers/mock-project');

module.exports = function CommandOptionsFactory(options) {
var project = new MockProject();
project.isEmberCLIProject = function() { return true; };
project.config = function() { return {}; };

return defaults(options || { }, {
ui: new MockUI(),
analytics: new MockAnalytics(),
tasks: {},
project: {
isEmberCLIProject: function isEmberCLIProject() {
return true;
},
config: function() {
return {};
}
}
project: project
});
};
6 changes: 6 additions & 0 deletions tests/helpers/mock-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ MockProject.prototype.name = function() {
};

MockProject.prototype.initializeAddons = Project.prototype.initializeAddons;
MockProject.prototype.hasDependencies = function() {
return true;
};
MockProject.prototype.discoverAddons = Project.prototype.discoverAddons;
MockProject.prototype.addIfAddon = Project.prototype.addIfAddon;
MockProject.prototype.supportedInternalAddonPaths = Project.prototype.supportedInternalAddonPaths;
MockProject.prototype.setupBowerDirectory = Project.prototype.setupBowerDirectory;
MockProject.prototype.setupNodeModulesPath = Project.prototype.setupNodeModulesPath;
MockProject.prototype.isEmberCLIProject = Project.prototype.isEmberCLIProject;
MockProject.prototype.isEmberCLIAddon = Project.prototype.isEmberCLIAddon;
MockProject.prototype.findAddonByName = Project.prototype.findAddonByName;
MockProject.prototype.dependencies = function() {
return [];
};
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/analytics-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

var expect = require('chai').expect;
var expect = require('chai').expect;
var Command = require('../../lib/models/command');
var MockUI = require('../helpers/mock-ui');
var MockProject = require('../helpers/mock-project');
var command;
var called = false;

Expand All @@ -18,10 +19,13 @@ beforeEach(function() {
run: function() {}
});

var project = new MockProject();
project.isEmberCLIProject = function() { return true; };

command = new FakeCommand({
ui: new MockUI(),
analytics: analytics,
project: { isEmberCLIProject: function(){ return true; }}
project: project
});
});

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/cli/cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function ember(args) {
isEmberCLIProject: function() { // similate being inside or outside of a project
return isWithinProject;
},
hasDependencies: function() {
return true;
},
blueprintLookupPaths: function() {
return [];
}
Expand Down
23 changes: 13 additions & 10 deletions tests/unit/commands/destroy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ var Promise = require('../../../lib/ext/promise');
var Task = require('../../../lib/models/task');
var expect = require('chai').expect;
var commandOptions = require('../../factories/command-options');
var MockProject = require('../../helpers/mock-project');

describe('generate command', function() {
var command;

beforeEach(function() {
command = new DestroyCommand(commandOptions({
settings: {},
var project = new MockProject();

project.name = function() {
return 'some-random-name';
};

project: {
name: function() {
return 'some-random-name';
},
project.isEmberCLIProject = function isEmberCLIProject() {
return true;
};

isEmberCLIProject: function isEmberCLIProject() {
return true;
}
},
command = new DestroyCommand(commandOptions({
settings: {},

project: project,
tasks: {
DestroyFromBlueprint: Task.extend({
project: project,
run: function(options) {
return Promise.resolve(options);
}
Expand Down
38 changes: 26 additions & 12 deletions tests/unit/commands/generate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@ var Promise = require('../../../lib/ext/promise');
var Task = require('../../../lib/models/task');
var expect = require('chai').expect;
var commandOptions = require('../../factories/command-options');
var SilentError = require('silent-error');
var MockProject = require('../../helpers/mock-project');

describe('generate command', function() {
var command;

beforeEach(function() {
var project = new MockProject();
project.name = function() {
return 'some-random-name';
};

project.isEmberCLIProject = function isEmberCLIProject() {
return true;
};

project.blueprintLookupPaths = function() {
return [];
};

//nodeModulesPath: 'somewhere/over/the/rainbow'
command = new GenerateCommand(commandOptions({
settings: {},

project: {
name: function() {
return 'some-random-name';
},

isEmberCLIProject: function isEmberCLIProject() {
return true;
},
blueprintLookupPaths: function() {
return [];
}
},
project: project,

tasks: {
GenerateFromBlueprint: Task.extend({
project: project,
run: function(options) {
return Promise.resolve(options);
}
Expand All @@ -36,6 +42,14 @@ describe('generate command', function() {
}));
});

it('runs GenerateFromBlueprint but with null nodeModulesPath', function() {
command.project.hasDependencies = function() { return false; };

expect(function() {
command.validateAndRun(['controller', 'foo']);
}).to.throw(SilentError, 'node_modules appears empty, you may need to run `npm install`');
});

it('runs GenerateFromBlueprint with expected options', function() {
return command.validateAndRun(['controller', 'foo'])
.then(function(options) {
Expand Down
41 changes: 18 additions & 23 deletions tests/unit/commands/install-addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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');
var MockProject = require('../../helpers/mock-project');

describe('install:addon command', function() {
var command, options, tasks, npmInstance, generateBlueprintInstance;
Expand All @@ -28,30 +28,25 @@ describe('install:addon command', function() {
})
};

var project = new MockProject();

project.name = function() { return 'some-random-name'; };
project.isEmberCLIProject = function() { return true; };
project.initializeAddons = function() { };
project.reloadAddons = function() {
this.addons = [{
pkg: {
name: 'ember-cli-photoswipe',
'ember-addon': {
defaultBlueprint: 'photoswipe'
}
}
}];
};

options = commandOptions({
settings: {},
project: {
name: function() {
return 'some-random-name';
},
isEmberCLIProject: function() {
return true;
},
initializeAddons: function() { },
reloadAddons: function() {
this.addons = [{
pkg: {
name: 'ember-cli-photoswipe',
'ember-addon': {
defaultBlueprint: 'photoswipe'
}
}
}];
},

findAddonByName: Project.prototype.findAddonByName
},

project: project,
tasks: tasks
});

Expand Down
21 changes: 11 additions & 10 deletions tests/unit/commands/install-bower-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
var expect = require('chai').expect;
var commandOptions = require('../../factories/command-options');
var InstallCommand = require('../../../lib/commands/install-bower');
var MockProject = require('../../helpers/mock-project');

describe('install:bower command', function() {
var command, options, msg;

beforeEach(function() {
options = commandOptions({
settings: {},
var project = new MockProject();
project.name = function() {
return 'some-random-name';
};

project: {
name: function() {
return 'some-random-name';
},
project.isEmberCLIProject = function() {
return true;
};

isEmberCLIProject: function() {
return true;
}
},
options = commandOptions({
settings: {},
project: project
});

command = new InstallCommand(options);
Expand Down
22 changes: 12 additions & 10 deletions tests/unit/commands/install-npm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
var expect = require('chai').expect;
var commandOptions = require('../../factories/command-options');
var InstallCommand = require('../../../lib/commands/install-npm');
var MockProject = require('../../helpers/mock-project');

describe('install:npm command', function() {
var command, options, msg;

beforeEach(function() {
options = commandOptions({
settings: {},
var project = new MockProject();

project.name = function() {
return 'some-random-name';
};

project: {
name: function() {
return 'some-random-name';
},
project.isEmberCLIProject =function() {
return true;
};

isEmberCLIProject: function() {
return true;
}
}
options = commandOptions({
settings: {},
project: project
});

command = new InstallCommand(options);
Expand Down

0 comments on commit a7c4aa2

Please sign in to comment.