Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
grunt-multi
Advanced tools
Run Grunt task with multi-configuration.
Say that we defined a very simple grunt task:
targetPage: 'a',
outTarget: 'mod1.js',
copy: {
subDir: {
files: [
{
expand: true,
cwd: 'src',
src: [ '<%= targetPage %>/*.js' ],
dest: 'build'
}
]
},
out: {
files: [
{
expand: true,
cwd: 'src',
src: '<%= outTarget %>',
dest: 'build'
}
]
}
}
...
// defined your task here
grunt.registerTask('build', [ 'copy' ]);
Quite simple, and when you run grunt build
, you will get all the JS files under src/a
copyed to build/a
.
But what if when your project grows larger, maybe you got like src/b
, src/c
.. in your project?
And that's what Grunt-multi
want to solve, you don't need to modify your copy
configuration, but just want exactly the same task run multiple times but with different configurations ( here within the example, we just want to change the variable targetPage
).
Just see code below, let's configure the grunt-multi
task:
multi: {
// Yes, you can use file pattern to match files or paths
pattern: {
options: {
vars: {
page_list: { patterns: '*', options: { cwd: 'src', filter: 'isDirectory' } }
},
config: {
targetPage: '<%= page_list %>'
},
tasks: [ 'copy' ]
}
},
// Also you can specify a list.
list: {
options: {
vars: {
page_list: [ 'a', 'b', 'c' ]
},
config: {
targetPage: '<%= page_list %>'
},
tasks: [ 'copy' ]
}
},
// A more smart way might be read from an external file.
external: {
options: {
vars: {
page_list: grunt.file.readJSON('build.json').target
},
config: {
targetPage: '<%= page_list %>'
},
tasks: [ 'copy' ]
}
},
// However, sometimes you may want to specify a constant variable.
constant: {
options: {
vars: {
page_list: [ 'a', 'b', 'c' ],
out_target: 'mod2.js'
},
config: {
targetPage: '<%= page_list %>',
outTarget: '<%= out_target %>'
},
tasks: [ 'copy' ]
}
},
// For the consideration of flexibility,you can use a function, but note that the return value, must be either an Array or String.
func: {
options: {
vars: {
page_list: function(){
return [ 'a', 'b', 'c' ];
}
},
config: {
targetPage: '<%= page_list %>'
},
tasks: [ 'copy' ]
}
},
// Also you can use function to direct modify the config, this is useful if you want to get more flexible to modify the configuration.
// params:
// 1、vars: a single instant of the vars you defined
// 2、rawConfig: the raw configuration.
constant_func: {
options: {
vars: {
page_list: [ 'a', 'b', 'c' ],
out_target: 'mod2.js'
},
config: {
targetPage: function( vars, rawConfig ){ return vars.page_list; },
outTarget: function( vars, rawConfig ){ return vars.out_target; }
},
tasks: [ 'copy' ]
}
},
}
After configuration you just run grunt multi:func
( or any defined sub task ) to execute the multi version of copy.
vars
with command$ grunt multi:func --multi-vars page_list=a,b,c:outTarget=mod2.js
Note that this will override the configuration in gruntfile.js
.
In some cases maybe you want to tell if the current thread is a child spawned by grunt-multi
, just use the multi-single
option to distinguish:
if( grunt.option( 'multi-single' ) ){
console.log( 'Child' );
}
Enjoy!
FAQs
Run Grunt task with multi-configuration.
The npm package grunt-multi receives a total of 134 weekly downloads. As such, grunt-multi popularity was classified as not popular.
We found that grunt-multi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.