Skip to content

Commit 9556253

Browse files
committed
[WIP] Restructure to support plugin base class
1 parent b93199e commit 9556253

File tree

9 files changed

+44
-39
lines changed

9 files changed

+44
-39
lines changed

config/deploy.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ module.exports = function(environment) {
22
var ENV = {};
33

44
if (environment === 'development') {
5+
ENV.build = {
6+
environment: 'development'
7+
};
58
ENV.store = {
69
host: 'localhost',
710
port: 6379
@@ -15,7 +18,9 @@ module.exports = function(environment) {
1518
}
1619

1720
if (environment === 'staging') {
18-
ENV.buildEnv = 'staging';
21+
ENV.build = {
22+
environment: 'production'
23+
};
1924

2025
ENV.store = {
2126
host: 'staging-redis.firstiwaslike.com',

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ Deploy.prototype.blueprintsPath = function() {
3636
};
3737

3838
Deploy.prototype.included = function(app) {
39-
var buildEnv = this._deployEnvSetByDeployCommand();
39+
var deployEnv = this._deployEnvSetByDeployCommand();
4040
var root = app.project.root;
4141
var configPath = path.join(root, 'config', 'deploy');
4242
var config;
4343
var fingerprint;
4444

45-
if (buildEnv) {
46-
config = require(configPath)(buildEnv);
45+
if (deployEnv) {
46+
config = require(configPath)(deployEnv);
4747

4848
if (config.fingerprint === false) {
4949
app.options.fingerprint = {enabled: false};

lib/models/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = CoreObject.extend({
4646
'assets.gzipExtensions': ['js', 'css', 'svg'],
4747
'assets.type': 's3',
4848
'assets.exclude': [],
49-
'buildEnv': 'production',
49+
'build.environment': 'production',
5050
'buildPath': 'tmp/deploy-dist/',
5151
'manifestPrefix': this.project.name(),
5252
'store.manifestSize': 10,

lib/tasks/pipeline.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ module.exports = Task.extend({
4545

4646
setup: function(){
4747
var self = this;
48-
return this._readConfig().then(function(deployConfig){
48+
return this._readDeployConfig().then(function(deployConfig){
4949
self.project.addons.forEach(function(addon){
50-
self._registerPipelineHooks(addon, deployConfig.plugins);
50+
self._registerPipelineHooks(addon, deployConfig);
5151
});
5252
return deployConfig;
5353
});
5454
},
5555

5656
run: function(hooks) {
57+
var self = this;
5758
var pipeline = this._pipeline;
5859
var ui = this.ui;
5960
var project = this.project;
60-
var self = this;
6161
var commandLineArgs = this.commandLineArgs;
6262

6363
return this.setup().then(function(deployConfig){
@@ -68,24 +68,23 @@ module.exports = Task.extend({
6868
project: project,
6969
ui: ui
7070
};
71-
return pipeline.execute({
72-
deployment: context
73-
});
71+
return pipeline.execute(context);
7472
});
7573
},
7674

77-
_readConfig: function() {
75+
_readDeployConfig: function() {
7876
var project = this.project;
7977
var deployConfigFn = require(path.join(project.root, this.deployConfigPath));
8078
return Promise.resolve(deployConfigFn(this.deployEnvironment));
8179
},
8280

83-
_registerPipelineHooks: function(addon, configuredPluginList) {
81+
_registerPipelineHooks: function(addon, deployConfig) {
8482
var self = this;
83+
var configuredPluginList = deployConfig.plugins;
8584

8685
if (this._isDeployPluginPack(addon)) {
8786
addon.addons.forEach(function(nestedAddon){
88-
self._registerPipelineHooks(nestedAddon, configuredPluginList);
87+
self._registerPipelineHooks(nestedAddon, deployConfig);
8988
});
9089
return;
9190
}
@@ -99,7 +98,6 @@ module.exports = Task.extend({
9998
}
10099

101100
var deployPlugin = addon.createDeployPlugin({name: name});
102-
var pluginName = this._getPluginName(deployPlugin);
103101

104102
this._pipeline.hookNames().forEach(function(hookName) {
105103
var fn = deployPlugin[hookName];
@@ -108,8 +106,13 @@ module.exports = Task.extend({
108106
}
109107

110108
this._pipeline.register(hookName, {
111-
name: pluginName,
112-
fn: fn.bind(deployPlugin)
109+
name: deployPlugin.name,
110+
fn: function(context){
111+
if (deployPlugin.beforeHook && typeof deployPlugin.beforeHook === 'function') {
112+
deployPlugin.beforeHook(context);
113+
}
114+
return fn.call(deployPlugin, context);
115+
}
113116
});
114117
}.bind(this));
115118
},
@@ -130,14 +133,6 @@ module.exports = Task.extend({
130133

131134
_addonImplementsDeploymentHooks: function(addon) {
132135
return addon.createDeployPlugin && typeof addon.createDeployPlugin === 'function';
133-
},
134-
135-
_getPluginName: function(plugin) {
136-
if (typeof plugin.name === 'function') {
137-
return plugin.name();
138-
} else {
139-
return plugin.name;
140-
}
141136
}
142137
});
143138

lib/utilities/pipeline.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Pipeline.prototype._hooksWithoutDidFail = function(hooks) {
7575
Pipeline.prototype._handlePipelineFailure = function(ui, context, error) {
7676
ui.write(red('|\n'));
7777
ui.write(red('+- didFail\n'));
78+
ui.write(red(error + "\n" + error.stack));
7879
return this._executeHook.bind(this, 'didFail')(context)
7980
.then(Promise.reject.bind(this, error));
8081
};

node-tests/fixtures/config-with-defaults/deploy.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module.exports = {
22
"development": {
3-
"buildEnv": "production",
3+
"build": {
4+
"environment": "development"
5+
},
46
"buildPath": "tmp/deploy-dist/",
57
"indexFiles": null,
68
"manifestPrefix": "foo",
@@ -23,7 +25,9 @@ module.exports = {
2325
},
2426

2527
"staging": {
26-
"buildEnv": "staging",
28+
"build": {
29+
"environment": "production"
30+
},
2731
"buildPath": "tmp/deploy-dist/",
2832
"indexFiles": null,
2933
"manifestPrefix": "foo",

node-tests/unit/models/config-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ describe('Config', function() {
2424
describe('buildEnv', function(){
2525
it('defaults to production', function() {
2626
var config = createConfig('tomster', {});
27-
expect(config.get('buildEnv')).to.eq('production');
27+
expect(config.get('build.environment')).to.eq('production');
2828
});
2929
it('allows configuration', function() {
30-
var config = createConfig('tomster', { buildEnv: 'chocula' });
31-
expect(config.get('buildEnv')).to.eq('chocula');
30+
var config = createConfig('tomster', { build: { environment: 'chocula' } });
31+
expect(config.get('build.environment')).to.eq('chocula');
3232
});
3333
});
3434

node-tests/unit/tasks/pipeline-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('PipelineTask', function() {
271271
describe('executing the pipeline task', function() {
272272
it ('executes the pipeline, passing in the deployment context', function() {
273273
var pipelineExecuted = false;
274-
var deployment;
274+
var pipelineContext;
275275

276276
var project = {
277277
name: function() {return 'test-project';},
@@ -289,7 +289,7 @@ describe('PipelineTask', function() {
289289
pipeline: {
290290
execute: function(context) {
291291
pipelineExecuted = true;
292-
deployment = context.deployment;
292+
pipelineContext = context;
293293
return Promise.resolve();
294294
}
295295
}
@@ -298,11 +298,11 @@ describe('PipelineTask', function() {
298298
return expect(task.run()).to.be.fulfilled
299299
.then(function() {
300300
expect(pipelineExecuted).to.be.true;
301-
expect(deployment.ui).to.eq(mockUi);
302-
expect(deployment.project).to.eq(project);
303-
expect(deployment.deployEnvironment).to.eq('development');
304-
expect(deployment.config.build.buildEnv).to.eq('development');
305-
expect(deployment.commandLineArgs.revision).to.eq('123abc');
301+
expect(pipelineContext.ui).to.eq(mockUi);
302+
expect(pipelineContext.project).to.eq(project);
303+
expect(pipelineContext.deployEnvironment).to.eq('development');
304+
expect(pipelineContext.config.build.buildEnv).to.eq('development');
305+
expect(pipelineContext.commandLineArgs.revision).to.eq('123abc');
306306
});
307307
});
308308
});

rfc/plugins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ property. Usually, the `name` will be the plugin name sans the `ember-cli-deploy
8383
prefix, unless a name has been specified as described in Advanced Plugin
8484
Configuration below.
8585

86-
### The `deployment` object
86+
### The `context` object
8787

88-
For each high-level ember-cli-deploy operation, a `deployment` object is created.
88+
For each high-level ember-cli-deploy operation, a `context` object is created.
8989
This object is passed to each hook that is invoked on the plugins. It has a number
9090
of properties that may be of use to a plugin:
9191

0 commit comments

Comments
 (0)