Skip to content

Instantly share code, notes, and snippets.

@nessthehero
Created November 5, 2012 18:55
Show Gist options
  • Save nessthehero/4019575 to your computer and use it in GitHub Desktop.
Save nessthehero/4019575 to your computer and use it in GitHub Desktop.
grunt 0.4 dummy task
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
test: {
options: {
taskSetting: true
},
target1: {
files: {
'result.txt': ['src/file.txt', 'src/file2.txt']
}
},
target2: {
options: {
taskSetting: false,
whatever: true
},
files: {
src: ['src/**/*.txt'],
dest: 'result.txt'
}
}
},
});
grunt.loadTasks('tasks');
};
'use strict';
exports.init = function(grunt) {
var exports = {};
exports.shared = function() {
grunt.log.writeln("Running shared method.");
};
return exports;
};
'use strict';
module.exports = function(grunt) {
// load functionality shared between tasks
var helper = require('./lib/shared').init(grunt);
// register task to grunt
grunt.registerMultiTask('test', 'Dummy grunt task.', function() {
// merge task and target options with default settings
var options = this.options({
anotherOption: true
});
console.log(options);
// run shared functionality
helper.shared();
// this represents the files grunt will work with no matter what config form you use
console.log(this.files);
// Iterate over all specified file groups.
this.files.forEach(function(fileObj) {
// The source files in the specified file group
var files = grunt.file.expand({nonull: true}, fileObj.src);
// iterate files and do something with them
files.forEach(function(filepath) {
// Warn if a source file/pattern was invalid.
if (!grunt.file.exists(filepath)) {
grunt.log.error('Source file "' + filepath + '" not found.');
return '';
}
grunt.log.writeln('doing something with',filepath);
});
}, this);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment