Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2bf0f07

Browse files
Allow definition of global (task) options or target specifc options
A target specific option will overwrite a global option with the same name No merge will occur! The global option WILL be overwritten!
1 parent a4e17cc commit 2bf0f07

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

‎README.md‎

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,82 @@ Available options:
163163
- `vars`: variables can be used within the next option `config`, in fact `var` is a list, you can get the list by `file pattern`, `array`, `function`(return a list).
164164
- `config`: the config item you want to change, you can use `vars` as template variables.
165165
- `tasks`: the tasks you want to run.
166-
- `continue`: if set to `true`, you indicate that the task will not stop. ( example: watch ).
166+
- `continued`: if set to `true`, you indicate that the task will not stop. ( example: watch ).
167167
- `logBegin`: Function, return log content you want to put in front of a thread.
168168
- `logEnd`: Function, return log content you want to put after a thread finish.
169169
- `maxSpawn`: The max number of spawns that can run at the same time.
170170

171+
Options can be specified globally for all `multi` targets and individually within each `multi:target`.
172+
173+
##### Task options (all targets)
174+
175+
```js
176+
//Both targets (list and constant_func) will inherit task options
177+
//and wiil have the vars.page_list = [ 'a', 'b', 'c' ]
178+
multi: {
179+
options : {
180+
vars: {
181+
page_list: [ 'a', 'b', 'c' ]
182+
}
183+
},
184+
list: {
185+
options: {
186+
config: {
187+
targetPage: '<%= page_list %>'
188+
},
189+
tasks: [ 'copy' ]
190+
}
191+
},
192+
constant_func: {
193+
options: {
194+
config: {
195+
targetPage: function( vars, rawConfig ){ return vars.page_list; },
196+
},
197+
tasks: [ 'copy' ]
198+
}
199+
}
200+
}
201+
```
202+
203+
##### Target specific options
204+
205+
```js
206+
//Both targets (list and constant_func) will inherit task options
207+
//but only list target will have vars.page_list = [ 'a', 'b', 'c' ]
208+
//In the constant_func target the global vars.page_list will be
209+
//overwritten by the target specific option vars.page_list = [ 'x', 'y', 'z' ]
210+
multi: {
211+
options : {
212+
vars: {
213+
page_list: [ 'a', 'b', 'c' ]
214+
}
215+
},
216+
list: {
217+
options: {
218+
config: {
219+
targetPage: '<%= page_list %>'
220+
},
221+
tasks: [ 'copy' ]
222+
}
223+
},
224+
constant_func: {
225+
options: {
226+
vars: {
227+
page_list: [ 'x', 'y', 'z' ]
228+
},
229+
config: {
230+
targetPage: function( vars, rawConfig ){ return vars.page_list; },
231+
},
232+
tasks: [ 'copy' ]
233+
}
234+
}
235+
}
236+
```
237+
171238
### Specify `vars` with command
172239
173240
```bash
174-
$ grunt multi:func --page_lista,b,c --outTargetmod2.js
241+
$ grunt multi:func --page_list=a,b,c --outTarget=mod2.js
175242
```
176243
Note that this will override the configuration in `gruntfile.js`.
177244

‎tasks/multi.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ module.exports = function (grunt) {
5151
grunt.log.debug( 'Begin Multi tasks.' );
5252

5353
// Get the raw `multi` config, in case the glob-patterns have been replaced by grunt automatically.
54-
var options = grunt.config.getRaw( this.name )[ this.target ].options;
54+
var taskOptions = grunt.config.getRaw( this.name ).options;
55+
var targetOptions = grunt.config.getRaw( this.name )[ this.target ].options;
56+
// Merges global task options with target specific options
57+
var allOptions = [{}].concat([
58+
grunt.util.kindOf(taskOptions) === 'object' ? taskOptions : {},
59+
grunt.util.kindOf(targetOptions) === 'object' ? targetOptions : {}
60+
]);
61+
var options = grunt.util._.extend.apply(null, allOptions);
5562
var maxSpawn = options.maxSpawn;
5663
var vars = options.vars;
5764
var logBegin = options.logBegin;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /