Skip to content

Commit 2d99960

Browse files
author
Aaron Chambers
committed
Merge pull request #9 from strange-studios/support-activate-pipeline
[WIP] `configure` primes the config with data from the deployment context
2 parents 923615c + 5b08293 commit 2d99960

File tree

5 files changed

+85
-29
lines changed

5 files changed

+85
-29
lines changed

index.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,14 @@ module.exports = {
4444
var ui = deployment.ui;
4545
var config = deployment.config[this.name] = deployment.config[this.name] || {};
4646

47-
return validateConfig(ui, config)
48-
.then(function() {
49-
ui.write(blue('| '));
50-
ui.writeLine(blue('- config ok'));
51-
});
47+
return this._resolvePipelineData(config, context)
48+
.then(validateConfig.bind(this, ui, config));
5249
},
5350

5451
didBuild: function(context) {
5552
var deployment = context.deployment;
5653
var ui = deployment.ui;
57-
var config = deployment.config[this.name] || {};
54+
var config = deployment.config[this.name] = deployment.config[this.name] || {};
5855
var type = config.type;
5956

6057
var KeyGenerator = generators[type];
@@ -67,9 +64,21 @@ module.exports = {
6764
.then(keyGenerator.generate.bind(keyGenerator))
6865
.then(_successMessage.bind(this, ui))
6966
.then(function(value) {
70-
return { revision: value };
67+
return { revisionKey: value };
7168
})
7269
.catch(_errorMessage.bind(this, ui));
70+
},
71+
72+
_resolvePipelineData: function(config, context) {
73+
config.distDir = config.distDir || function(context) {
74+
return context.distDir;
75+
};
76+
77+
config.distFiles = config.distFiles || function(context) {
78+
return context.distFiles;
79+
};
80+
81+
return Promise.resolve();
7382
}
7483
};
7584
}

lib/key-generators/file-hash.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module.exports = CoreObject.extend({
1616

1717
generate: function() {
1818
var filePattern = this._config.filePattern;
19-
var distDir = this._context.distDir;
20-
var distFiles = this._context.distFiles;
19+
var distDir = this._resolveConfigValue('distDir', this._config, this._context);
20+
var distFiles = this._resolveConfigValue('distFiles', this._config, this._context);
2121
var fingerprint;
2222

2323
var filePaths = distFiles.filter(minimatch.filter(filePattern, { matchBase: true }));
@@ -33,5 +33,13 @@ module.exports = CoreObject.extend({
3333
fingerprint = new Fingerprint();
3434
return fingerprint.hashFn(contents.toString());
3535
})
36+
},
37+
38+
_resolveConfigValue: function(key, config, context) {
39+
if(typeof config[key] === 'function') {
40+
return config[key](context);
41+
}
42+
43+
return config[key];
3644
}
3745
});

lib/utilities/validate-config.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ module.exports = function(ui, config) {
2222
}
2323
});
2424

25+
ui.write(blue('| '));
26+
ui.writeLine(blue('- config ok'));
27+
2528
return Promise.resolve();
2629
}

tests/unit/index-nodetest.js

+49-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
var assert = require('ember-cli/tests/helpers/assert');
44

5+
function hooks(plugin) {
6+
return Object.keys(plugin).filter(function(key) {
7+
return (key !== 'name') && (key.charAt(0) !== '_') && (typeof plugin[key] === 'function');
8+
});
9+
}
10+
511
describe('the index', function() {
612
var subject;
713

@@ -18,14 +24,15 @@ describe('the index', function() {
1824
});
1925

2026
it('implements the correct hooks', function() {
21-
var result = subject.createDeployPlugin({
27+
var plugin = subject.createDeployPlugin({
2228
name: 'test-plugin'
2329
});
2430

25-
assert.equal(typeof result.didBuild, 'function');
31+
assert.equal(hooks(plugin).length, 2);
32+
assert.sameMembers(hooks(plugin), ['configure', 'didBuild']);
2633
});
2734

28-
describe('willDeploy hook', function() {
35+
describe('configure hook', function() {
2936
it('resolves if config is ok', function() {
3037
var plugin = subject.createDeployPlugin({
3138
name: 'revision-key'
@@ -48,6 +55,41 @@ describe('the index', function() {
4855

4956
return assert.isFulfilled(plugin.configure.call(plugin, context))
5057
});
58+
59+
describe('resolving data from the pipeline', function() {
60+
it('resolves the config data from the context', function() {
61+
var plugin = subject.createDeployPlugin({
62+
name: 'revision-key'
63+
});
64+
65+
var config = {
66+
type: 'file-hash',
67+
filePattern: 'eeee'
68+
};
69+
var context = {
70+
deployment: {
71+
ui: {
72+
write: function() {},
73+
writeLine: function() {}
74+
},
75+
config: {
76+
'revision-key': config
77+
}
78+
},
79+
80+
distDir: 'some-dir',
81+
distFiles: ['a.js', 'b.css']
82+
};
83+
84+
return assert.isFulfilled(plugin.configure.call(plugin, context))
85+
.then(function() {
86+
assert.typeOf(config.distDir, 'function');
87+
assert.typeOf(config.distFiles, 'function');
88+
assert.equal(config.distDir(context), 'some-dir');
89+
assert.sameMembers(config.distFiles(context), ['a.js', 'b.css']);
90+
});
91+
});
92+
});
5193
});
5294

5395
describe('didBuild hook', function() {
@@ -57,8 +99,6 @@ describe('the index', function() {
5799
});
58100

59101
var context = {
60-
distDir: 'tests/fixtures',
61-
distFiles: ['index.html'],
62102
deployment: {
63103
ui: {
64104
write: function() {},
@@ -67,15 +107,17 @@ describe('the index', function() {
67107
config: {
68108
'revision-key': {
69109
type: 'file-hash',
70-
filePattern: 'index.html'
110+
filePattern: 'index.html',
111+
distDir: 'tests/fixtures',
112+
distFiles: ['index.html'],
71113
},
72114
}
73115
}
74116
};
75117

76118
return assert.isFulfilled(plugin.didBuild.call(plugin, context))
77119
.then(function(result) {
78-
assert.equal(result.revision, 'ae1569f72495012cd5e8588e0f2f5d49');
120+
assert.equal(result.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
79121
});
80122
});
81123
});

tests/unit/lib/tags/file-hash-nodetest.js renamed to tests/unit/lib/key-generators/file-hash-nodetest.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ describe('the file-hash key generator', function() {
1212
describe('#generate', function() {
1313
it ('generates a hash of the supplied index file', function() {
1414
var subject = new KeyGenerator({
15-
context: {
16-
distDir: 'tests/fixtures',
17-
distFiles: ['index.html'],
18-
},
1915
config: {
20-
filePattern: 'index.html'
16+
filePattern: 'index.html',
17+
distDir: 'tests/fixtures',
18+
distFiles: ['index.html']
2119
}
2220
});
2321

@@ -29,12 +27,10 @@ describe('the file-hash key generator', function() {
2927

3028
it('rejects when the filePattern doesn\'t exist in distFiles', function() {
3129
var subject = new KeyGenerator({
32-
context: {
30+
config: {
31+
filePattern: 'some-file-that-does-not-exist',
3332
distDir: 'tests/fixtures',
3433
distFiles: ['index.html']
35-
},
36-
config: {
37-
filePattern: 'some-file-that-does-not-exist'
3834
}
3935
});
4036

@@ -46,12 +42,10 @@ describe('the file-hash key generator', function() {
4642

4743
it('rejects when the file doesn\'t exist', function() {
4844
var subject = new KeyGenerator({
49-
context: {
45+
config: {
46+
filePattern: 'index.xxx',
5047
distDir: 'tests/fixtures',
5148
distFiles: ['index.xxx']
52-
},
53-
config: {
54-
filePattern: 'index.xxx'
5549
}
5650
});
5751

0 commit comments

Comments
 (0)