-
-
Save anonymous/078060b4044c671b8b82 to your computer and use it in GitHub Desktop.
This file contains 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 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 | |
} | |
}); | |
}); |
This file contains 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
// /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); | |
}); | |
}); | |
} |
This file contains 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
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