Skip to content

@kaw2k /Gruntfile.js
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.