Last active
December 17, 2015 02:39
-
-
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 :('); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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