Skip to content

Instantly share code, notes, and snippets.

@kaw2k
Last active December 17, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaw2k/5537773 to your computer and use it in GitHub Desktop.
Save kaw2k/5537773 to your computer and use it in GitHub Desktop.
A simple sample gruntfile. If you are trying this, make sure to run `npm install`.
var args = process.argv.slice(2);
switch (args[0]) {
// cmd: node app a
case 'a':
console.log('Hello!');
break;
// -cmd: node app b
case 'b':
console.log('World!');
break;
// -cmd: node app
default:
console.log('No parames matched :(');
}
function commentCommand(cmd) {
cmd = cmd || 'cmd';
var result = require('execSync')
.exec('grep -nr "// '+cmd+':" ./')
.stdout
.split('\n')[0];
if (result !== '') {
var reg = new RegExp('// '+cmd+':(.+)', 'i');
result = result.match(reg)[1];
}
return result;
}
module.exports = function (grunt) {
// config
grunt.initConfig({
exec: {
run: {
cmd: commentCommand
}
},
watch: {
scripts: {
files: 'app.js',
tasks: ['jshint', 'exec']
}
},
jshint: {
files: ['**/*.js', '!**/node_modules/**']
}
});
// load
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-exec');
// register
grunt.registerTask('default', ['watch']);
};
{
"name": "grunt-demo",
"version": "0.1.0",
"devDependencies": {
"execSync": "~0.0.4",
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.4.3",
"grunt-contrib-watch": "~0.4.0",
"grunt-exec": "~0.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment