anonymous / Gruntfile.js secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View Gruntfile.js
1 2 3 4 5 6 7 8 9 10 11
var uncomment = require('webProjectTools');
 
grunt.registerTask('uncomment4', 'Uncomment client JS files', function(){
var files = [ path.resolve(__dirname, 'client/js/bundle.min.js') ];
console.log('in gruntfile: ' + files);
uncomment({
js: {
src: files
}
});
});
View Gruntfile.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
// /path/to/webProjectBuilder/node_modules/webProjectTools/index.js
 
var fse = require('fs-extra')
, _ = require('lodash')
, uncomment = require('uncommentify')({ all: true })
, cleanCss = require('clean-css');
 
var defaults = {
js: {
src: [] // paths relative to the calling script
},
css: {
src: [] // paths relative to the calling script
}
};
 
function errHandler(err, data) {
if (err) return console.error('Failed with error: ' + err);
// console.log('Source: ' + src);
console.log('Success: ' + data);
}
 
// swapped src/dest naming here since matches the api
function removeAndMove(src, dst, callback) {
fse.remove(dst, function (err) {
console.log('in module removeAndMove src: ' + src);
console.log('in module removeAndMove dst: ' + dst);
if (err) return callback(err);
fse.move(src, dst, callback);
});
}
 
module.exports = function(opts){
var options = _.merge({}, defaults, opts);
var src = options.js.src;
console.log('in module outside foreach: ' + options.js.src);
src.forEach(function (src) {
console.log('in module foreach: ' + src);
fse.createReadStream(src)
.pipe(uncomment)
.pipe(fse.createWriteStream(src + '.tmp'))
.on('finish', function () {
removeAndMove(src + '.tmp', src, errHandler);
});
});
}
View Gruntfile.js
1 2 3 4 5 6 7 8 9 10 11 12
me@workstation:/path/to/webProjectBuilder$ grunt uncomment4
Running "uncomment4" task
in gruntfile: /path/to/webProjectBuilder/client/js/bundle.min.js // this is the correct location
in module outside foreach: /path/to/webProjectBuilder/client/js/bundle.min.js // this is the correct location
in module foreach: /path/to/webProjectBuilder/client/js/bundle.min.js // this is the correct location
 
Done, without errors.
 
 
Execution Time (2014-09-30 11:52:49 UTC)
loading tasks 1.4s ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100%
Total 1.4s
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.