Skip to content

Instantly share code, notes, and snippets.

@sankargorthi
Last active January 3, 2016 17:49
Show Gist options
  • Save sankargorthi/8498632 to your computer and use it in GitHub Desktop.
Save sankargorthi/8498632 to your computer and use it in GitHub Desktop.
Copy component.json to a work folder, parse and then nuke the work folder. I did this because `grunt.file.expand` was too slow on my project structure, especially with all the node_modules folders present under multiple sub-projects.
module.exports = function (grunt) {
'use strict';
require('load-grunt-tasks')(grunt);
grunt.renameTask('clean', 'nuke');
grunt.initConfig({
nuke: {
work: ['work']
},
shell: {
warmup: {
options: {
stdout: true
},
command: 'for config in `find . -name component.json -maxdepth 2 -not -path \'./bootstrap/*\' -not -path \'./work/*\'`; do (parent=`dirname $config` && mkdir -p work/$parent && cp $config work/$parent/); done'
}
}
});
grunt.registerTask('cook', 'Generate the moduleMap', function () {
var map = {},
features = grunt.file.expand({
filter: 'isFile'
}, [
'./work/**/component.json'
]);
features.forEach(function (feature) {
var config = require(feature);
map[config.name] = {
version: config.version
};
});
grunt.file.write('bootstrap/lib/moduleMap.js', 'module.exports=' + JSON.stringify(map));
});
grunt.registerTask('warmup', [
'shell:warmup',
'cook',
'nuke'
]);
};
$ grunt warmup
Running "shell:warmup" (shell) task
Running "cook" task
Running "nuke:work" (nuke) task
Cleaning work...OK
Done, without errors.
Elapsed time
loading tasks 156ms
shell:warmup 170ms
nuke:work 29ms
Total 355ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment