Skip to content
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

Set bowerDirectory for project #2287

Merged
merged 1 commit into from
Oct 15, 2014
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
6 changes: 1 addition & 5 deletions lib/broccoli/ember-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ function EmberApp(options) {
this.tests = options.hasOwnProperty('tests') ? options.tests : !isProduction;
this.hinting = options.hasOwnProperty('hinting') ? options.hinting : !isProduction;

if (fs.existsSync(path.join(this.project.root, '.bowerrc'))) {
this.bowerDirectory = JSON.parse(fs.readFileSync(path.join(this.project.root, '.bowerrc'))).directory;
}

this.bowerDirectory = this.bowerDirectory || 'bower_components';
this.bowerDirectory = this.project.bowerDirectory;

if (process.env.EMBER_CLI_TEST_COMMAND) {
this.tests = true;
Expand Down
16 changes: 16 additions & 0 deletions lib/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,24 @@ function Project(root, pkg) {
this.pkg = pkg;
this.addonPackages = {};
this.liveReloadFilterPatterns = [];
this.setupBowerDirectory();
}

Project.prototype.setupBowerDirectory = function() {
var bowerrcPath = path.join(this.root, '.bowerrc');
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this into a function (perhaps setupBowerDirectory or something) that is called from here instead of inlining it?


if (fs.existsSync(bowerrcPath)) {
var bowerrcContent = fs.readFileSync(bowerrcPath);
try {
this.bowerDirectory = JSON.parse(bowerrcContent).directory;
} catch (exception) {
this.bowerDirectory = null;
}
}

this.bowerDirectory = this.bowerDirectory || 'bower_components';
};

var NULL_PROJECT = new Project(process.cwd(), {});

NULL_PROJECT.isEmberCLIProject = function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "vendor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
3 changes: 3 additions & 0 deletions tests/fixtures/bower-directory-tests/invalid-bowerrc/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
"directory": "vendor"
})
Empty file.
7 changes: 4 additions & 3 deletions tests/helpers/mock-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
var Project = require('../../lib/models/project');

function MockProject() {
Project.apply(this, arguments);
this.root = process.cwd();
this.pkg = {};
var root = process.cwd();
var pkg = {};
Project.apply(this, [root, pkg]);
}

MockProject.prototype.require = function(file) {
Expand Down Expand Up @@ -37,6 +37,7 @@ MockProject.prototype.initializeAddons = Project.prototype.initializeAddons;
MockProject.prototype.buildAddonPackages = Project.prototype.buildAddonPackages;
MockProject.prototype.discoverAddons = Project.prototype.discoverAddons;
MockProject.prototype.addIfAddon = Project.prototype.addIfAddon;
MockProject.prototype.setupBowerDirectory = Project.prototype.setupBowerDirectory;
MockProject.prototype.dependencies = function() {
return [];
};
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/broccoli/ember-app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ describe('broccoli/ember-app', function() {

assert.equal(project.configPath(), 'custom config path');
});

it('should set bowerDirectory for app', function() {
var app = new EmberApp({
project: project
});

assert.equal(app.bowerDirectory, project.bowerDirectory);
assert.equal(app.bowerDirectory, 'bower_components');
});
});

describe('contentFor', function() {
Expand Down
32 changes: 31 additions & 1 deletion tests/unit/models/project-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('models/project.js', function() {
project.config('development');
assert.equal(addonConfigCalled, true);
});

it('returns getAddonsConfig result when configPath is not present', function() {
var expected = {
foo: 'bar'
Expand Down Expand Up @@ -280,4 +280,34 @@ describe('models/project.js', function() {
assert.equal(project.isEmberCLIAddon(), false);
});
});

describe('bowerDirectory', function() {
it('should be initialized in constructor', function() {
assert.equal(project.bowerDirectory, 'bower_components');
});

it('should be set to directory property in .bowerrc', function() {
projectPath = path.resolve(__dirname, '../../fixtures/bower-directory-tests/bowerrc-with-directory');
project = new Project(projectPath, {});
assert.equal(project.bowerDirectory, 'vendor');
});

it('should default to ‘bower_components’ unless directory property is set in .bowerrc', function() {
projectPath = path.resolve(__dirname, '../../fixtures/bower-directory-tests/bowerrc-without-directory');
project = new Project(projectPath, {});
assert.equal(project.bowerDirectory, 'bower_components');
});

it('should default to ‘bower_components’ if .bowerrc is not present', function() {
projectPath = path.resolve(__dirname, '../../fixtures/bower-directory-tests/no-bowerrc');
project = new Project(projectPath, {});
assert.equal(project.bowerDirectory, 'bower_components');
});

it('should default to ‘bower_components’ if .bowerrc json is invalid', function() {
projectPath = path.resolve(__dirname, '../../fixtures/bower-directory-tests/invalid-bowerrc');
project = new Project(projectPath, {});
assert.equal(project.bowerDirectory, 'bower_components');
});
});
});