Gruntplugin for processing (add, replace, split) any file
Getting Started
This plugin requires Grunt ~0.4.x
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-process --save
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-process');
The "process" task
Overview
In your project's Gruntfile, add a section named process to the data object passed into grunt.initConfig().
grunt.initConfig({
process:{
options:{
// common options go here.
},
your_target:{
options:{
// Target-specific options go here.
},
files:[
// Target-specific file lists and/or options go here.
]
},
},
});
Options
options.read
Type: Function
method for open file and convert to string or any format what you need
grunt.initConfig({
customRead:{
options:{
read:function(src,dest,fileObject){
returngrunt.file.readJSON(src);// default function for read
// if want use async read function:
// var done = this.async();
// process.nextTick(function () {
// var content = grunt.file.readJSON(src, readOptions);
// done(null, content);
// });
}
},
files:[{
src:'some/path/to.file',
dest:'distr/path/to.file'
}]
}
});
options.process
Type: Function
method for process file and convert to any format what you need (for save)
grunt.initConfig({
customProcess:{
options:{
read:function(src,dest,content,fileObject){
return content;// this is default function for process
// if want use async process function:
// var done = this.async();
// process.nextTick(function () {
// content = content.replace(/[1-9]/g, ''); //remove all numbers for example
// done(null, content);
// });
}
},
files:[{
src:'some/path/to.file',
dest:'distr/path/to.file'
}]
}
});
options.save
Type: Function
method for save file(s). must return object (key - is file path; value - content)