From 2d18bfb4f4a97c112d34b5ad3f7755758dfd241d Mon Sep 17 00:00:00 2001 From: Martin Broerse Date: Tue, 24 Nov 2015 22:58:40 +0100 Subject: [PATCH 1/4] Add distDir to defaultConfig --- index.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index f1fbbb1..4c1942e 100644 --- a/index.js +++ b/index.js @@ -14,33 +14,43 @@ module.exports = { name: options.name, defaultConfig: { environment: 'production', - outputPath: 'tmp' + path.sep + 'deploy-dist' + outputPath: 'tmp' + path.sep + 'deploy-dist', + distDir: function(context) { + return context.distDir; + } }, - build: function(context) { - var self = this; + setup: function() { var outputPath = this.readConfig('outputPath'); + return { + distDir: outputPath + }; + }, + + build: function(/* context */) { + var self = this; + var distDir = this.readConfig('distDir'); var buildEnv = this.readConfig('environment'); var Builder = this.project.require('ember-cli/lib/models/builder'); var builder = new Builder({ ui: this.ui, - outputPath: outputPath, + outputPath: distDir, environment: buildEnv, project: this.project }); - this.log('building app to `' + outputPath + '` using buildEnv `' + buildEnv + '`...', { verbose: true }); + this.log('building app to `' + distDir + '` using buildEnv `' + buildEnv + '`...', { verbose: true }); return builder.build() .finally(function() { return builder.cleanup(); }) - .then(this._logSuccess.bind(this, outputPath)) + .then(this._logSuccess.bind(this, distDir)) .then(function(files) { files = files || []; return { - distDir: outputPath, + distDir: distDir, distFiles: files }; }) From 2f017d8eb86e579eea5a61b1146c4530734cad4e Mon Sep 17 00:00:00 2001 From: Martin Broerse Date: Wed, 25 Nov 2015 08:15:26 +0100 Subject: [PATCH 2/4] No need to return distDir again --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 4c1942e..f1a8365 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,6 @@ module.exports = { files = files || []; return { - distDir: distDir, distFiles: files }; }) From dd01baf2cebac8e073a54a232f38e298de7ddb12 Mon Sep 17 00:00:00 2001 From: Martin Broerse Date: Wed, 25 Nov 2015 23:21:10 +0100 Subject: [PATCH 3/4] add setup hook test --- tests/unit/index-nodetest.js | 44 +++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/tests/unit/index-nodetest.js b/tests/unit/index-nodetest.js index 6ef6a94..d8958b3 100644 --- a/tests/unit/index-nodetest.js +++ b/tests/unit/index-nodetest.js @@ -60,8 +60,7 @@ describe('build plugin', function() { return previous; }, []); - - assert.equal(messages.length, 2); + assert.equal(messages.length, 3); }); it('adds default config to the config object', function() { @@ -76,7 +75,8 @@ describe('build plugin', function() { config = { build: { environment: 'development', - outputPath: 'tmp/dist-deploy' + outputPath: 'tmp/dist-deploy', + distDir: 'tmp/dist-deploy' } }; plugin = subject.createDeployPlugin({ @@ -102,6 +102,39 @@ describe('build plugin', function() { }); }); + describe('setup hook', function() { + var plugin, context; + + beforeEach(function() { + plugin = subject.createDeployPlugin({ + name: 'build' + }); + + context = { + ui: mockUi, + project: { + name: function() { return 'test-project'; }, + require: function(mod) { return require(mod); }, + addons: [], + root: 'tests/dummy' + }, + config: { + build: { + buildEnv: 'development', + outputPath: 'tmp/dist-deploy' + } + } + }; + plugin.beforeHook(context); + }); + + it('resolves with distDir', function() { + assert.deepEqual(plugin.setup(context), { + distDir: 'tmp/dist-deploy' + }); + }); + }); + describe('build hook', function() { var plugin, context; @@ -121,19 +154,18 @@ describe('build plugin', function() { config: { build: { buildEnv: 'development', - outputPath: 'tmp/dist-deploy', + distDir: 'tmp/dist-deploy' } } }; plugin.beforeHook(context); }); - it('builds the app and resolves with distDir and distFiles', function(done) { + it('builds the app and resolves with distFiles', function(done) { this.timeout(50000); return assert.isFulfilled(plugin.build(context)) .then(function(result) { assert.deepEqual(result, { - distDir: 'tmp/dist-deploy', distFiles: [ 'assets/dummy.css', 'assets/dummy.js', From 0a9775df36c3e38bae32a7d00e0854bb1d01c8d8 Mon Sep 17 00:00:00 2001 From: Martin Broerse Date: Thu, 26 Nov 2015 07:00:37 +0100 Subject: [PATCH 4/4] Improve test --- tests/unit/index-nodetest.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/index-nodetest.js b/tests/unit/index-nodetest.js index d8958b3..5958fb8 100644 --- a/tests/unit/index-nodetest.js +++ b/tests/unit/index-nodetest.js @@ -76,7 +76,9 @@ describe('build plugin', function() { build: { environment: 'development', outputPath: 'tmp/dist-deploy', - distDir: 'tmp/dist-deploy' + distDir: function(context) { + return context.distDir; + } } }; plugin = subject.createDeployPlugin({