grunt-multi
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "grunt-multi", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Run Grunt task with multi-configuration.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -16,3 +16,2 @@ # grunt-multi | ||
files: [ | ||
// widget中的字体 | ||
{ | ||
@@ -28,3 +27,2 @@ expand: true, | ||
files: [ | ||
// widget中的字体 | ||
{ | ||
@@ -56,3 +54,3 @@ expand: true, | ||
multi: { | ||
// Yes, you can use file pattern to match files or paths, more detail | ||
// Yes, you can use file pattern to match files or paths | ||
pattern: { | ||
@@ -79,3 +77,3 @@ options: { | ||
}, | ||
// An more smart way may be just read from an external file. | ||
// A more smart way might be read from an external file. | ||
external: { | ||
@@ -91,3 +89,3 @@ options: { | ||
}, | ||
// However, sometimes you just want to specify a constant variable. | ||
// However, sometimes you may want to specify a constant variable. | ||
constant: { | ||
@@ -121,3 +119,3 @@ options: { | ||
After configuration you must add the task in front of your task List, let change the code like this: | ||
After configuration you must add the `multi` task in front of your task List, change the code like below: | ||
@@ -128,6 +126,13 @@ ```js | ||
But when you run `grunt build` again, nothing magic happen. Yeah, that's the point, for the risk of ruining your old task, the `grunt-multi` will not work until you specify a `--multi` flag, so just try it, nothing will hurt you. | ||
But when you run `grunt build` again, nothing magic happen. That's the point, for the risk of ruining your old task, the `grunt-multi` would not work until you specify a `--multi` flag, so just try it, nothing will hurt you. | ||
One more thing, you can use a additional flat `--debug` to console out the particular configuration for a single thread. | ||
One more thing, you can also add an additional flat `--debug` to console out the particular configuration for a single thread. | ||
### Specify `vars` with command | ||
```bash | ||
$ grunt build --multi --multi-vars page_list=a,b,c:outTarget=mod2.js | ||
``` | ||
Note that this will override the configuration in `gruntfile.js`. | ||
Enjoy! |
@@ -54,3 +54,3 @@ /* | ||
var options = grunt.config.getRaw( this.name )[ this.target ].options; | ||
var vars = options.vars; | ||
var vars = options.vars || {}; | ||
// Stringify the config, to simplify the template process. | ||
@@ -74,2 +74,26 @@ var configStr = JSON.stringify( options.config ); | ||
/** | ||
* If multi-vars specified, it will override the configuration. | ||
* example: --multi-vars a=1,2,3:b:jack,bill,rose | ||
*/ | ||
if( grunt.option( 'multi-vars' ) ){ | ||
var multiVars = grunt.option( 'multi-vars' ); | ||
var cmdVarsChunk = multiVars.split( ':' ); | ||
cmdVarsChunk.forEach(function( v ){ | ||
var name = v.substring( 0, v.indexOf( '=' ) ); | ||
var values = v.substring( v.indexOf( '=' ) + 1 ); | ||
if( name && values ){ | ||
values = values.split( ',' ); | ||
} | ||
if( values.length == 1 ){ | ||
vars[ name ] = values[ 0 ]; | ||
} | ||
else { | ||
vars[ name ] = values; | ||
} | ||
}); | ||
} | ||
grunt.util._.each( vars, function( value, key ){ | ||
@@ -146,6 +170,2 @@ | ||
} | ||
}, function( child ){ | ||
child.stdout.on('data', function (data) { | ||
console.log( data.toString( 'utf8') ); | ||
}); | ||
}); | ||
@@ -152,0 +172,0 @@ }); |
@@ -174,2 +174,27 @@ /** | ||
it('USE Command', function (done) { | ||
// 执行grunt | ||
// 先安装npm 依赖 | ||
ChildProcess.exec( 'grunt cmd --multi --debug --multi-vars page_list=a,b,c:out_target=mod2.js', function (error, stdout, stderr) { | ||
console.log('stdout: ' + stdout); | ||
console.log('stderr: ' + stderr); | ||
if (error) { | ||
done( error ); | ||
} | ||
else { | ||
assertFiles( [ | ||
'build/a/app.js', | ||
'build/a/index.js', | ||
'build/b/home.js', | ||
'build/b/profile.js', | ||
'build/c/dashboard.js', | ||
'build/c/list.js', | ||
'build/mod2.js' | ||
]); | ||
done(null); | ||
} | ||
}); | ||
}); | ||
}); | ||
@@ -176,0 +201,0 @@ |
@@ -90,2 +90,10 @@ module.exports = function (grunt) { | ||
} | ||
}, | ||
command: { | ||
options: { | ||
config: { | ||
targetPage: '<%= page_list %>', | ||
outTarget: '<%= out_target %>' | ||
} | ||
} | ||
} | ||
@@ -102,2 +110,3 @@ } | ||
grunt.registerTask('func', [ 'multi:func', 'copy' ]); | ||
grunt.registerTask('cmd', [ 'multi:command', 'copy' ]); | ||
}; |
22983
491
131