Permalink
Browse files

Reduces file size by implementing flavors.

Build process updated accordingly
  • Loading branch information...
1 parent 6df1580 commit a84622bdfaeee93cfc1bca368f858d8e3e159f12 @xcambar committed Apr 22, 2012
Showing with 495 additions and 630 deletions.
  1. +44 −31 build.js
  2. +141 −268 build/shepherd.dev.js
  3. +1 −1 build/shepherd.min.js
  4. +1 −0 build/shepherd.server.js
  5. +120 −0 src/flavours/browser.js
  6. +146 −0 src/flavours/server.js
  7. +40 −329 src/shepherd.js
  8. +1 −0 test/index.html
  9. +1 −1 test/spec/shepherdSpec.js
View
@@ -10,49 +10,62 @@ var parserLocation = './lib/harmony-parser/harmony_parser.js',
whenLocation = './lib/when/when.js',
shepherdLocation = './src/shepherd.js';
-function run (min) {
+var flavourConfig = {
+ 'client-dev' : {
+ min: false,
+ flavourFile: './src/flavours/browser.js',
+ outputSuffix: 'dev'
+ },
+ 'client' : {
+ min: true,
+ flavourFile: './src/flavours/browser.js',
+ outputSuffix: 'min'
+ },
+ 'server' : {
+ min: true,
+ flavourFile: './src/flavours/server.js',
+ outputSuffix: 'server'
+ }
+};
+
+function run (flavourKey) {
+ var flavour = flavourConfig[flavourKey];
+
// Scopes the parser so it doesn't pollute globals
// Declaring exports to undefined avoids CommonJS exports
var parserCode = '(function() {var exports;' + fs.readFileSync(parserLocation).toString() + ';return harmony_parser;})();';
var shepherdCode = fs.readFileSync(shepherdLocation).toString();
var whenCode = '(function() {var module = {};' + fs.readFileSync(whenLocation).toString() + ';return module.exports;})();';
+ var flavourCode = fs.readFileSync(flavour.flavourFile).toString();
var output;
- if (min) {
- var parserAst = jsp.parse(parserCode);
- parserAst = pro.ast_mangle(parserAst, {defines: {require: ['name', 'undefined'], exports: ['name', 'undefined']}});
- parserAst = pro.ast_squeeze(parserAst);
- var parserMinified = pro.gen_code(parserAst, {beautify: false});
- var whenAst = jsp.parse(whenCode);
- whenAst = pro.ast_mangle(whenAst, {beautify: false, defines: {require: ['module', 'undefined']}});
- whenAst = pro.ast_squeeze(whenAst);
- var whenMinified = pro.gen_code(whenAst);
- var shepherdAst = jsp.parse(shepherdCode);
- shepherdAst = pro.ast_mangle(shepherdAst, {beautify: false, defines: {MINIFY: ['name', true], harmonyParser: ['name', parserMinified], when: ['name', whenMinified]}});
- shepherdAst = pro.ast_squeeze(shepherdAst);
- output = pro.gen_code(shepherdAst);
- } else {
- devCode = '(function () {' +
- 'var harmonyParser = ' + parserCode + ';\n' +
- 'var when = ' + whenCode + ';\n' +
- shepherdCode +
- '})()';
- var devAst = jsp.parse(devCode);
- output = pro.gen_code(devAst, {beautify: true});
+ devCode = '(function () {' +
+ 'var harmonyParser = ' + parserCode + ';\n' +
+ 'var when = ' + whenCode + ';\n' +
+ 'var flavour = ' + flavourCode + ';\n' +
+ shepherdCode +
+ '})()';
+ var devAst = jsp.parse(devCode);
+ if (flavour.min) {
+ devAst = pro.ast_mangle(devAst, {defines: {MINIFY: ['name', true]}});
+ devAst = pro.ast_squeeze(devAst);
}
- fs.writeFileSync('./build/shepherd.' + (min ? 'min' : 'dev') + '.js', output);
+ output = pro.gen_code(devAst, {beautify: !flavour.min});
+ fs.writeFileSync('./build/shepherd.' + flavour.outputSuffix + '.js', output);
}
function build () {
- var msg;
- try {
- run(true);
- run();
- msg = 'Shepherd built on: ' + (new Date()).toString();
- } catch (e) {
- msg = 'Build failed. (' + e.message + ')';
+ for (var i in flavourConfig) {
+ if (!flavourConfig.hasOwnProperty(i)) { continue;}
+ var msg;
+ try {
+ run(i);
+ msg = 'Built Shepherd with flavour ' + i + ' on: ' + (new Date()).toString();
+ } catch (e) {
+ msg = 'Build of flavour ' + i + ' failed. (' + e.message + ')';
+ }
+ console.log(msg);
}
- console.log(msg);
}
build();
Oops, something went wrong.

0 comments on commit a84622b

Please sign in to comment.