Skip to content

Commit

Permalink
Allow addons to have public trees.
Browse files Browse the repository at this point in the history
* Public is namespaced by default under the addons package name.
* Add simple easy to override method lookup pattern for customizing
  treeFor on a type by type basis.
  • Loading branch information
rwjblue committed Sep 8, 2014
1 parent 45d1b11 commit f15f198
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 11 deletions.
22 changes: 14 additions & 8 deletions lib/broccoli/ember-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ function EmberApp(options) {
// do not watch vendor/ or bower's default directory by default
bower: unwatchedTree(this.bowerDirectory),
vendor: fs.existsSync('vendor') ? unwatchedTree('vendor') : null,

public: fs.existsSync('public') ? 'public' : null
}, defaults);

this.options.jshintrc = merge(this.options.jshintrc, {
Expand Down Expand Up @@ -276,8 +278,16 @@ EmberApp.prototype.testIndex = function() {
});
};

EmberApp.prototype.publicFolder = function() {
return 'public';
EmberApp.prototype.publicTree = function() {
var trees = this.addonTreesFor('public');

if (this.trees.public) {
trees.push(this.trees.public);
}

return mergeTrees(trees, {
overwrite: true
});
};

EmberApp.prototype.removeStylesAndTemplates = function(tree) {
Expand Down Expand Up @@ -693,14 +703,10 @@ EmberApp.prototype.toArray = function() {
this.index(),
this.javascript(),
this.styles(),
this.otherAssets()
this.otherAssets(),
this.publicTree()
];

var publicFolder = this.publicFolder();
if (fs.existsSync(publicFolder)) {
sourceTrees.push(publicFolder);
}

if (this.tests) {
sourceTrees = sourceTrees.concat(this.testIndex(), this.testFiles());
}
Expand Down
28 changes: 25 additions & 3 deletions lib/models/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ Addon.prototype.treePaths = {
'addon-styles': 'addon/styles',
'addon-templates': 'addon/templates',
vendor: 'vendor',
'test-support': 'test-support'
'test-support': 'test-support',
public: 'public'
};

Addon.prototype.treeForMethods = {
app: 'treeForApp',
styles: 'treeForStyles',
templates: 'treeForTemplates',
addon: 'treeForAddon',
vendor: 'treeForVendor',
'test-support': 'treeForTestSupport',
public: 'treeForPublic'
};

Addon.prototype.treeFor = function treeFor(name) {
Expand All @@ -94,13 +105,15 @@ Addon.prototype.treeFor = function treeFor(name) {

Addon.prototype._treeFor = function _treeFor(name) {
var treePath = path.join(this.root, this.treePaths[name]);
var treeForMethod = this.treeForMethods[name];
var tree;


if (fs.existsSync(treePath)) {
tree = this.treeGenerator(treePath);

if (name === 'addon') {
tree = this.treeForAddon(tree);
if (this[treeForMethod]) {
tree = this[treeForMethod](tree);
}
}

Expand All @@ -127,6 +140,15 @@ Addon.prototype.includedModules = function() {
return this._includedModules;
};

Addon.prototype.treeForPublic = function(tree) {
this._requireBuildPackages();

return this.pickFiles(tree, {
srcDir: '/',
destDir: '/' + this.moduleName()
});
};

Addon.prototype.treeForAddon = function(tree) {
this._requireBuildPackages();

Expand Down
25 changes: 25 additions & 0 deletions tests/acceptance/brocfile-smoke-test-slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ describe('Acceptance: brocfile-smoke-test', function() {
});
});

it('addons can have a public tree that is merged and returned namespaced by default', function() {
console.log(' running the slow end-to-end it will take some time');

this.timeout(100000);

return copyFixtureFiles('brocfile-tests/public-tree')
.then(function() {
var packageJsonPath = path.join(__dirname, '..', '..', 'tmp', appName, 'package.json');
var packageJson = require(packageJsonPath);
packageJson.devDependencies['ember-random-addon'] = 'latest';

return fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
})
.then(function() {
return runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build', {
verbose: true
});
})
.then(function() {
var subjectFileContents = fs.readFileSync(path.join('.', 'dist', 'ember-random-addon', 'some-root-file.txt'), { encoding: 'utf8' });

assert.equal(subjectFileContents, 'ROOT FILE' + EOL);
});
});

it('using pods based templates', function() {
console.log(' running the slow end-to-end it will take some time');

Expand Down
Empty file.
63 changes: 63 additions & 0 deletions tests/unit/models/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,67 @@ describe('models/addon.js', function() {
assert.notEqual(addon.root, undefined);
});

describe('custom treeFor methods', function() {
it('can define treeForApp', function() {
var called;

addon.treeForApp = function() {
called = true;
};

addon.treeFor('app');
assert(called);
});

it('can define treeForStyles', function() {
var called;

addon.treeForStyles = function() {
called = true;
};

addon.treeFor('styles');
assert(called);
});

it('can define treeForVendor', function() {
var called;

addon.treeForVendor = function() {
called = true;
};

addon.treeFor('vendor');
assert(called);
});

it('can define treeForTemplates', function() {
var called;

addon.treeForTemplates = function() {
called = true;
};

addon.treeFor('templates');
assert(called);
});

it('can define treeForPublic', function() {
var called;

addon.treeForPublic = function() {
called = true;
};

addon.treeFor('public');
assert(called);
});
});

describe('trees for it\'s treePaths', function() {
it('app', function() {
var tree = addon.treeFor('app');

assert.equal(typeof tree.read, 'function');
});

Expand All @@ -88,6 +146,11 @@ describe('models/addon.js', function() {
var tree = addon.treeFor('vendor');
assert.equal(typeof tree.read, 'function');
});

it('public', function() {
var tree = addon.treeFor('public');
assert.equal(typeof tree.read, 'function');
});
});
});

Expand Down

0 comments on commit f15f198

Please sign in to comment.