Saturday, 15 September 2012

node.js - Grunt: How can I change file mode bits (chmod)? -



node.js - Grunt: How can I change file mode bits (chmod)? -

i generate shell script within grunt build file , set execution bit.

in task following:

grunt.registertask('createscript', 'creates script', function() { var ejs = require('ejs'); //... grunt.file.write( './build/myscript.sh', ejs.render( grunt.file.read('myscript.sh.ejs'), { locals:myparams } ) ); });

it seems neither grunt.file.write nor grunt.file have alternative specify file mode bits. (see api grunt.file)

how can set bits?

because grunt runs in node, can utilize file scheme module fs of node. fs has method chmod() / chmodsync().

the code illustration this:

grunt.registertask('createscript', 'creates script', function() { var ejs = require('ejs'); var fs = require('fs'); //... grunt.file.write( './build/myscript.sh', ejs.render( grunt.file.read('myscript.sh.ejs'), { locals:myparams } ) ); fs.chmodsync('./build/myscript.sh', '777'); });

node.js gruntjs

No comments:

Post a Comment