b925f472 by Adam Heath

Add build:foo feature flag support.

1 parent efcdde5f
...@@ -37,9 +37,6 @@ module.exports = function (grunt) { ...@@ -37,9 +37,6 @@ module.exports = function (grunt) {
37 lines.push('container[' + JSON.stringify(id) + ']=' + JSON.stringify(file) + ';\n'); 37 lines.push('container[' + JSON.stringify(id) + ']=' + JSON.stringify(file) + ';\n');
38 }); 38 });
39 lines.push('})(require.paths);'); 39 lines.push('})(require.paths);');
40 if (false && lines.length == 2) {
41 lines = [];
42 }
43 grunt.file.write('.grunt/holygrail/scripts/revconfig.js', lines.join('')); 40 grunt.file.write('.grunt/holygrail/scripts/revconfig.js', lines.join(''));
44 }); 41 });
45 42
...@@ -49,7 +46,7 @@ module.exports = function (grunt) { ...@@ -49,7 +46,7 @@ module.exports = function (grunt) {
49 var holyGrailTmp = '.grunt/holygrail'; 46 var holyGrailTmp = '.grunt/holygrail';
50 var initConfig = { 47 var initConfig = {
51 clean: { 48 clean: {
52 dist: { 49 montyPython: {
53 files: [{ 50 files: [{
54 dot: true, 51 dot: true,
55 src: [ 52 src: [
...@@ -88,8 +85,14 @@ module.exports = function (grunt) { ...@@ -88,8 +85,14 @@ module.exports = function (grunt) {
88 var checkList = []; 85 var checkList = [];
89 var buildList = [ 86 var buildList = [
90 'check', 87 'check',
91 'clean:dist', 88 'clean:montyPython',
89 'post-clean',
92 ]; 90 ];
91 var postCleanList = [];
92
93 grunt.registerTask('post-clean', 'post-clean', function() {
94 grunt.task.run(postCleanList);
95 });
93 96
94 function externalMultiTask(name, desc, command, updateOptions) { 97 function externalMultiTask(name, desc, command, updateOptions) {
95 grunt.log.writeln('registering multiTask', name); 98 grunt.log.writeln('registering multiTask', name);
...@@ -236,7 +239,7 @@ module.exports = function (grunt) { ...@@ -236,7 +239,7 @@ module.exports = function (grunt) {
236 src: ['dist/!(scripts){,**/}*.html'], 239 src: ['dist/!(scripts){,**/}*.html'],
237 }, 240 },
238 }; 241 };
239 initConfig.clean.dist.files[0].src.push('.grunt/usemin'); 242 initConfig.clean.montyPython.files[0].src.push('.grunt/usemin');
240 initConfig.htmlmin = { 243 initConfig.htmlmin = {
241 dist: { 244 dist: {
242 //options: _.extend({}, mpConfig.htmlmin.options), 245 //options: _.extend({}, mpConfig.htmlmin.options),
...@@ -262,7 +265,7 @@ module.exports = function (grunt) { ...@@ -262,7 +265,7 @@ module.exports = function (grunt) {
262 }), 265 }),
263 }] 266 }]
264 }; 267 };
265 initConfig.clean.dist.files[0].src.push('.grunt/usemin-css'); 268 initConfig.clean.montyPython.files[0].src.push('.grunt/usemin-css');
266 initConfig.usemin.css = _.map(mpConfig.css.options.dirs, function (value) { 269 initConfig.usemin.css = _.map(mpConfig.css.options.dirs, function (value) {
267 return 'dist/' + value + '/{,**/}*.css'; 270 return 'dist/' + value + '/{,**/}*.css';
268 }); 271 });
...@@ -367,7 +370,6 @@ module.exports = function (grunt) { ...@@ -367,7 +370,6 @@ module.exports = function (grunt) {
367 initConfig.requirejs = { 370 initConfig.requirejs = {
368 dist: { 371 dist: {
369 options: { 372 options: {
370
371 done: function onDone(next) { 373 done: function onDone(next) {
372 /* jshint devel:true */ 374 /* jshint devel:true */
373 var target = grunt.task.current.target; 375 var target = grunt.task.current.target;
...@@ -390,7 +392,7 @@ module.exports = function (grunt) { ...@@ -390,7 +392,7 @@ module.exports = function (grunt) {
390 } 392 }
391 //lines.push('return bundles;'); 393 //lines.push('return bundles;');
392 lines.push('})(require, \'bundles\');'); 394 lines.push('})(require, \'bundles\');');
393 if (lines.length == 2) { 395 if (lines.length == 3) {
394 lines = []; 396 lines = [];
395 } 397 }
396 grunt.file.write('.grunt/holygrail/scripts/bundles.js', lines.join('\n')); 398 grunt.file.write('.grunt/holygrail/scripts/bundles.js', lines.join('\n'));
...@@ -459,9 +461,6 @@ module.exports = function (grunt) { ...@@ -459,9 +461,6 @@ module.exports = function (grunt) {
459 } 461 }
460 //buildList.push('uglify:bower'); // montyPython 462 //buildList.push('uglify:bower'); // montyPython
461 //buildList.push('uglify:requireconfig'); // montyPython 463 //buildList.push('uglify:requireconfig'); // montyPython
462 if (mpConfig.useRev && mpConfig.bower) {
463 //buildList.push('rev:requireconfig'); // montyPython
464 }
465 buildList.push('usemin:html'); // montyPython 464 buildList.push('usemin:html'); // montyPython
466 buildList.push('usemin:css'); // montyPython 465 buildList.push('usemin:css'); // montyPython
467 buildList.push('htmlmin'); // montyPython 466 buildList.push('htmlmin'); // montyPython
...@@ -474,7 +473,32 @@ module.exports = function (grunt) { ...@@ -474,7 +473,32 @@ module.exports = function (grunt) {
474 'check', 473 'check',
475 ]); 474 ]);
476 475
477 grunt.registerTask('build', buildList); 476 grunt.registerTask('build', 'build the system', function() {
477 var featureFlags = {};
478 if (arguments.length) {
479 for (var i in arguments) {
480 featureFlags['BUILD_' + arguments[i].toUpperCase()] = true;
481 }
482 grunt.registerTask('writeFeatureFlags', 'write feature flags', function() {
483 var lines = [
484 '(function(container, propName) {',
485 'container = (container[propName] = container[propName] || {});',
486 ];
487 for (var flag in featureFlags) {
488 lines.push('require.config.featureFlags[' + JSON.stringify(flag) + ']=' + JSON.stringify(featureFlags[flag]) + ';');
489 }
490 //lines.push('return bundles;');
491 lines.push('})(require.config, \'featureFlags\');');
492 if (lines.length == 3) {
493 lines = [];
494 }
495 grunt.file.write('.grunt/holygrail/scripts/featureFlags.js', lines.join('\n'));
496 });
497 postCleanList.add('writeFeatureFlags');
498 }
499
500 grunt.task.run(buildList);
501 });
478 } 502 }
479 503
480 return { 504 return {
......