Skip to content

Commit

Permalink
Merge pull request #1215 from jakecraige/feature/addon_build_hooks
Browse files Browse the repository at this point in the history
Add addon.postBuild hook
  • Loading branch information
stefanpenner committed Jul 1, 2014
2 parents 8933a7f + aca0fb6 commit f9c4e7c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [BUGFIX] Make behaviour of `--dry-run` more obvious & add `--skip-npm` and `--skip-bower`. [#1205](https://github.com/stefanpenner/ember-cli/pull/1205)
* [ENHANCEMENT] Remove .gitkeep files from `ember init` inside an existing project [#1209](https://github.com/stefanpenner/ember-cli/pull/1209)
* [ENHANCEMENT] Addons can add commands to the local `ember` command. [#1196](https://github.com/stefanpenner/ember-cli/pull/1196)
* [ENHANCEMENT] Addons can implement a postBuild hook. [#1215](https://github.com/stefanpenner/ember-cli/pull/1215)

### 0.0.37

Expand Down
19 changes: 18 additions & 1 deletion lib/models/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,26 @@ module.exports = Task.extend({
});
},

addonsPostBuild: function(results){
var addonPromises = [];

if(this.project && this.project.addons.length) {
addonPromises = this.project.addons.map(function(addon){
if(addon.postBuild) {
return addon.postBuild(results);
}
}).filter(Boolean);
}

return Promise.all(addonPromises).then(function() {
return results;
});
},

build: function() {
return this.builder.build.apply(this.builder, arguments)
.then(this.processBuildResult.bind(this));
.then(this.processBuildResult.bind(this))
.then(this.addonsPostBuild.bind(this));
},

onExit: function() {
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = Task.extend({

process.env.EMBER_ENV = process.env.EMBER_ENV || env;
var builder = new Builder({
outputPath: options.outputPath
outputPath: options.outputPath,
project: this.project
});

var watcher = new Watcher({
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/models/builder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var fs = require('fs-extra');
var Builder = require('../../../lib/models/builder');
var touch = require('../../helpers/file-utils').touch;
var assert = require('assert');
var Promise = require('../../../lib/ext/promise');
var stub = require('../../helpers/stub').stub;

describe('models/builder.js', function() {
var builder, outputPath;
Expand Down Expand Up @@ -31,4 +33,32 @@ describe('models/builder.js', function() {
assert(!fs.existsSync(secondFile));
});
});

describe('addons', function() {
it('allows addons to add promises postbuild', function() {
var addon = {
name: 'TestAddon',
postBuild: function() { }
};
var postBuild = stub(addon, 'postBuild');
var results = 'build results';
builder = new Builder({
setupBroccoliBuilder: function() { },
trapSignals: function() { },
cleanupOnExit: function() { },
builder: {
build: function() { return Promise.resolve(results); }
},
processBuildResult: function(buildResults) { return Promise.resolve(buildResults); },
project: {
addons: [addon]
}
});

return builder.build().then(function() {
assert.equal(postBuild.called, 1, 'expected postBuild to be called');
assert.equal(postBuild.calledWith[0][0], results, 'expected postBuild to be called with the results');
});
});
});
});

0 comments on commit f9c4e7c

Please sign in to comment.