Skip to content

Commit d4e3785

Browse files
committed
Remove ability for plugin author to add functions to pluginHelper
1 parent d81a88d commit d4e3785

File tree

4 files changed

+15
-63
lines changed

4 files changed

+15
-63
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ module.exports = {
3434
},
3535
requiredConfig: ['awesomeApiKey'], // throw an error if this is not configured
3636

37-
// return an object from here to add functionality to the `pluginHelper`
38-
// that is passed in to user defined config property functions
39-
pluginHelper: function(context) {
40-
return {
41-
sayHello: function() {
42-
return 'Hello' + context.project.name();
43-
}
44-
};
45-
},
46-
4737
// implement any hooks appropriate for your plugin
4838
willUpload: function(context) {
4939
// Use the `readConfig` method for uniform access to this plugin's config,

index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
var CoreObject = require('core-object');
22
var chalk = require('chalk');
3-
var merge = require('lodash.merge');
3+
var cloneDeep = require('lodash.clonedeep');
44

5-
function _pluginHelperDefaults() {
5+
function _pluginHelper() {
66
return {
77
readConfigDefault: function(property) {
88
var configuredValue = this.defaultConfig[property];
99
if (typeof configuredValue === 'function') {
10-
return configuredValue.call(this, this.context);
10+
return cloneDeep(configuredValue.call(this, this.context));
1111
}
12-
return configuredValue;
12+
return cloneDeep(configuredValue);
1313
}.bind(this)
1414
};
1515
}
@@ -56,8 +56,7 @@ var DeployPluginBase = CoreObject.extend({
5656
readConfig: function(property){
5757
var configuredValue = this.pluginConfig[property];
5858
if (typeof configuredValue === 'function') {
59-
var helper = merge(this.pluginHelper(this.context), _pluginHelperDefaults.call(this));
60-
return configuredValue.call(this.pluginConfig, this.context, helper);
59+
return configuredValue.call(this.pluginConfig, this.context, _pluginHelper.call(this));
6160
}
6261
return configuredValue;
6362
},
@@ -88,10 +87,6 @@ var DeployPluginBase = CoreObject.extend({
8887

8988
this.logRaw(chalkColor('- ' + message));
9089
}
91-
},
92-
93-
pluginHelper: function(/*context*/) {
94-
return {};
9590
}
9691
});
9792

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"dependencies": {
2525
"chalk": "^1.0.0",
2626
"core-object": "0.0.2",
27-
"lodash.merge": "^4.6.0"
27+
"lodash.clonedeep": "^4.5.0"
2828
}
2929
}

tests/unit/index-nodetest.js

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -75,63 +75,30 @@ describe('base plugin', function() {
7575
describe('plugin helper', function() {
7676
it('provides access to the oringal default values', function() {
7777
var Plugin = Subject.extend({
78-
requiredConfig: ['bar'],
7978
defaultConfig: {
80-
foo: function(context) {
81-
return context.foo;
82-
}
79+
distFiles: ['index.html', 'assets/logo.png']
8380
}
8481
});
8582

8683
var plugin = new Plugin({
87-
name: 'blah'
88-
});
89-
90-
var context = {
91-
foo: 'foo',
92-
config: {
93-
blah: {
94-
foo: function(context, pluginHelper) {
95-
return pluginHelper.readConfigDefault('foo') + 'foo';
96-
},
97-
bar: function(context, pluginHelper) {
98-
return pluginHelper.readConfigDefault('bar') + 'bar';
99-
}
100-
}
101-
}
102-
};
103-
104-
plugin.beforeHook(context);
105-
assert.equal(plugin.readConfig('foo'), 'foofoo');
106-
assert.equal(plugin.readConfig('bar'), 'undefinedbar');
107-
});
108-
109-
it('allows the implementer to add things to the pluginHelper', function() {
110-
var Plugin = Subject.extend({
111-
defaultConfig: { foo: 'foo' }
112-
});
113-
114-
var plugin = new Plugin({
115-
name: 'blah',
116-
117-
pluginHelper: function(context) {
118-
return { bar: context.foo };
119-
}
84+
name: 'build'
12085
});
12186

12287
var context = {
123-
foo: 'bar',
12488
config: {
125-
blah: {
126-
foo: function(context, pluginHelper) {
127-
return pluginHelper.readConfigDefault('foo') + pluginHelper.bar;
89+
build: {
90+
distFiles: function(context, pluginHelper) {
91+
var arr = pluginHelper.readConfigDefault('distFiles');
92+
arr.push('index.json');
93+
return arr;
12894
}
12995
}
13096
}
13197
};
13298

13399
plugin.beforeHook(context);
134-
assert.equal(plugin.readConfig('foo'), 'foobar');
100+
assert.deepEqual(plugin.defaultConfig.distFiles, ['index.html', 'assets/logo.png']);
101+
assert.deepEqual(plugin.readConfig('distFiles'), ['index.html', 'assets/logo.png', 'index.json']);
135102
});
136103
});
137104
});

0 commit comments

Comments
 (0)