Skip to content

Commit 5af58f8

Browse files
committed
Option to reuse build output during plugin development
When you're working on a deploy plugin or tweaking your deploy config, you often run `ember deploy` repeatedly, and each run usually invokes this plugin to do a full rebuild of your app, even though your app has not changed and the build options are identical. This PR makes it possible to set the environment variable EMBER_CLI_DEPLOY_REUSE_BUILD to reuse the results from the previous run. This can make it much faster to test changes to all the configuration and plugins that come after the build plugin (which is most of them).
1 parent b056732 commit 5af58f8

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ None
6464

6565
* yarn test
6666

67+
## Faster iteration while authoring deploy plugins & configs
68+
69+
When you're working on a deploy plugin or tweaking your deploy config, you often run `ember deploy` repeatedly, and each run usually invokes this plugin to do a full rebuild of your app, even though your app has not changed and the build options are identical.
70+
71+
You can instead reuse the build from the previous `ember deploy` by setting the environment variable `EMBER_CLI_DEPLOY_REUSE_BUILD`. This may make your interactive testing much faster. It's safe to use during development as long as you aren't actively changing your app or altering this module's `environment` or `outputPath`.
72+
6773
## Why `ember test` doesn't work
6874

6975
Since this is a node-only ember-cli addon, we use mocha for testing and this package does not include many files and devDependencies which are part of ember-cli's typical `ember test` processes.

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ module.exports = {
2020
build: function(/* context */) {
2121
var self = this;
2222
var outputPath = this.readConfig('outputPath');
23+
if (process.env.EMBER_CLI_DEPLOY_REUSE_BUILD) {
24+
this.log('reusing build from `' + outputPath, { verbose: true });
25+
return RSVP.resolve({
26+
distDir: outputPath,
27+
distFiles: glob.sync('**/*', { cwd: outputPath, nodir: true })
28+
});
29+
}
2330
var buildEnv = this.readConfig('environment');
2431

2532
var Builder = this.project.require('ember-cli/lib/models/builder');

tests/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
globals: {
33
"describe": true,
44
"beforeEach": true,
5+
"afterEach": true,
56
"it": true
67
},
78
env: {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* hello world */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* hello world */

tests/index-test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,16 @@ describe('build plugin', function() {
135135
}
136136
}
137137
};
138-
plugin.beforeHook(context);
139138
});
140139

140+
afterEach(function() {
141+
delete process.env.EMBER_CLI_DEPLOY_REUSE_BUILD;
142+
});
143+
144+
141145
it('builds the app and resolves with distDir and distFiles', function(done) {
142146
this.timeout(50000);
147+
plugin.beforeHook(context);
143148
assert.isFulfilled(plugin.build(context))
144149
.then(function(result) {
145150
assert.deepEqual(result, {
@@ -167,5 +172,26 @@ describe('build plugin', function() {
167172
done(reason);
168173
});
169174
});
175+
176+
it('can reuse build results and resolve with distDir and distFiles', function(done) {
177+
process.env.EMBER_CLI_DEPLOY_REUSE_BUILD = 'true';
178+
context.config.build.outputPath = __dirname + '/fixtures/fake-build-output';
179+
plugin.beforeHook(context);
180+
181+
assert.isFulfilled(plugin.build(context))
182+
.then(function(result) {
183+
assert.deepEqual(result, {
184+
distDir: __dirname + '/fixtures/fake-build-output',
185+
distFiles: [
186+
'assets/inner-example.css',
187+
'top-file-example.js'
188+
]
189+
});
190+
done();
191+
}).catch(function(reason){
192+
done(reason);
193+
});
194+
});
195+
170196
});
171197
});

0 commit comments

Comments
 (0)