2011-08-14 21:35:36 +00:00
|
|
|
var fs = require('fs'),
|
2011-11-28 04:55:36 +00:00
|
|
|
exec = require('child_process').exec;
|
2011-08-14 21:35:36 +00:00
|
|
|
|
2012-07-19 11:34:32 +00:00
|
|
|
var buildArgs = process.argv.slice(2),
|
|
|
|
|
buildArgsAsObject = { };
|
2011-08-14 21:35:36 +00:00
|
|
|
|
2012-07-19 11:34:32 +00:00
|
|
|
buildArgs.forEach(function(arg) {
|
|
|
|
|
var key = arg.split('=')[0],
|
|
|
|
|
value = arg.split('=')[1];
|
|
|
|
|
|
|
|
|
|
buildArgsAsObject[key] = value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var modulesToInclude = buildArgsAsObject.modules ? buildArgsAsObject.modules.split(',') : [ ];
|
|
|
|
|
var modulesToExclude = buildArgsAsObject.exclude ? buildArgsAsObject.exclude.split(',') : [ ];
|
|
|
|
|
|
2012-10-17 09:03:17 +00:00
|
|
|
var minifier = buildArgsAsObject.minifier || 'uglifyjs';
|
2011-11-28 04:55:36 +00:00
|
|
|
var mininfierCmd;
|
|
|
|
|
|
|
|
|
|
if (minifier === 'yui') {
|
|
|
|
|
mininfierCmd = 'java -jar lib/yuicompressor-2.4.2.jar dist/all.js -o dist/all.min.js';
|
|
|
|
|
}
|
|
|
|
|
else if (minifier === 'closure') {
|
|
|
|
|
mininfierCmd = 'java -jar lib/google_closure_compiler.jar --js dist/all.js --js_output_file dist/all.min.js';
|
|
|
|
|
}
|
2012-10-17 09:03:17 +00:00
|
|
|
else if (minifier === 'uglifyjs') {
|
2012-10-17 09:19:41 +00:00
|
|
|
mininfierCmd = 'uglifyjs -o dist/all.min.js dist/all.js';
|
2012-10-17 09:03:17 +00:00
|
|
|
}
|
2011-11-28 04:55:36 +00:00
|
|
|
|
2012-07-19 11:34:32 +00:00
|
|
|
var includeAllModules = modulesToInclude.length === 1 && modulesToInclude[0] === 'ALL';
|
|
|
|
|
var noStrict = 'no-strict' in buildArgsAsObject;
|
2011-08-14 21:35:36 +00:00
|
|
|
|
2012-07-19 11:34:32 +00:00
|
|
|
var distFileContents =
|
|
|
|
|
'/* build: `node build.js modules=' +
|
|
|
|
|
modulesToInclude.join(',') +
|
|
|
|
|
(modulesToExclude.length ? (' exclude=' + modulesToExclude.join(',')) : '') +
|
|
|
|
|
(noStrict ? ' no-strict' : '') +
|
|
|
|
|
'` */\n';
|
2011-08-14 21:35:36 +00:00
|
|
|
|
|
|
|
|
function appendFileContents(fileNames, callback) {
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
(function readNextFile() {
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
if (fileNames.length <= 0) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
var fileName = fileNames.shift();
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
if (!fileName) {
|
|
|
|
|
return readNextFile();
|
|
|
|
|
}
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
fs.readFile(__dirname + '/' + fileName, function (err, data) {
|
|
|
|
|
if (err) throw err;
|
2012-07-19 11:34:32 +00:00
|
|
|
if (noStrict) {
|
|
|
|
|
data = String(data).replace(/"use strict";?\n?/, '');
|
|
|
|
|
}
|
2011-08-14 21:35:36 +00:00
|
|
|
distFileContents += (data + '\n');
|
|
|
|
|
readNextFile();
|
|
|
|
|
});
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
})();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ifSpecifiedInclude(moduleName, fileName) {
|
2012-07-19 11:34:32 +00:00
|
|
|
var isInIncludedList = modulesToInclude.indexOf(moduleName) > -1;
|
|
|
|
|
var isInExcludedList = modulesToExclude.indexOf(moduleName) > -1;
|
|
|
|
|
|
|
|
|
|
// excluded list takes precedence over modules=ALL
|
|
|
|
|
return ((isInIncludedList || includeAllModules) && !isInExcludedList) ? fileName : '';
|
2011-08-14 21:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-24 09:21:32 +00:00
|
|
|
function ifSpecifiedDependencyInclude(included, excluded, fileName) {
|
|
|
|
|
return (
|
|
|
|
|
(
|
|
|
|
|
(modulesToInclude.indexOf(included) > -1 || includeAllModules) &&
|
|
|
|
|
(modulesToExclude.indexOf(excluded) == -1))
|
|
|
|
|
? fileName
|
|
|
|
|
: ''
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
var filesToInclude = [
|
|
|
|
|
|
|
|
|
|
'HEADER.js',
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2012-07-24 09:21:32 +00:00
|
|
|
ifSpecifiedDependencyInclude('text', 'cufon', 'lib/cufon.js'),
|
|
|
|
|
ifSpecifiedDependencyInclude('serialization', 'json', 'lib/json2.js'),
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
'src/log.js',
|
|
|
|
|
'src/observable.js',
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
'src/util/misc.js',
|
|
|
|
|
'src/util/lang_array.js',
|
|
|
|
|
'src/util/lang_object.js',
|
|
|
|
|
'src/util/lang_string.js',
|
|
|
|
|
'src/util/lang_function.js',
|
|
|
|
|
'src/util/lang_class.js',
|
|
|
|
|
'src/util/dom_event.js',
|
|
|
|
|
'src/util/dom_style.js',
|
|
|
|
|
'src/util/dom_misc.js',
|
|
|
|
|
'src/util/dom_request.js',
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2012-04-26 02:58:03 +00:00
|
|
|
ifSpecifiedInclude('easing', 'src/util/anim_ease.js'),
|
|
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
ifSpecifiedInclude('parser', 'src/parser.js'),
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2012-08-20 16:18:30 +00:00
|
|
|
'src/gradient.class.js',
|
2011-08-14 21:35:36 +00:00
|
|
|
'src/point.class.js',
|
|
|
|
|
'src/intersection.class.js',
|
|
|
|
|
'src/color.class.js',
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-11-28 04:55:36 +00:00
|
|
|
'src/static_canvas.class.js',
|
|
|
|
|
ifSpecifiedInclude('interaction', 'src/canvas.class.js'),
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
'src/canvas.animation.js',
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
ifSpecifiedInclude('serialization', 'src/canvas.serialization.js'),
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
'src/object.class.js',
|
|
|
|
|
'src/line.class.js',
|
|
|
|
|
'src/circle.class.js',
|
|
|
|
|
'src/triangle.class.js',
|
|
|
|
|
'src/ellipse.class.js',
|
|
|
|
|
'src/rect.class.js',
|
|
|
|
|
'src/polyline.class.js',
|
|
|
|
|
'src/polygon.class.js',
|
|
|
|
|
'src/path.class.js',
|
|
|
|
|
'src/path_group.class.js',
|
|
|
|
|
'src/group.class.js',
|
|
|
|
|
'src/image.class.js',
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2012-05-11 11:31:30 +00:00
|
|
|
ifSpecifiedInclude('object_straightening', 'src/object_straightening.js'),
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-10-26 05:34:54 +00:00
|
|
|
ifSpecifiedInclude('image_filters', 'src/image_filters.js'),
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
ifSpecifiedInclude('text', 'src/text.class.js'),
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2012-07-31 18:49:42 +00:00
|
|
|
ifSpecifiedInclude('node', 'src/node.js')
|
2011-08-14 21:35:36 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
appendFileContents(filesToInclude, function() {
|
|
|
|
|
fs.writeFile('dist/all.js', distFileContents, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
throw err;
|
2011-11-28 04:55:36 +00:00
|
|
|
}
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-11-28 04:55:36 +00:00
|
|
|
console.log('Built distribution to dist/all.js');
|
|
|
|
|
|
|
|
|
|
exec(mininfierCmd, function (error, output) {
|
|
|
|
|
if (!error) {
|
|
|
|
|
console.log('Minified using', minifier, 'to dist/all.min.js');
|
|
|
|
|
}
|
|
|
|
|
exec('gzip -c dist/all.min.js > dist/all.min.js.gz', function (error, output) {
|
|
|
|
|
console.log('Gzipped to dist/all.min.js.gz');
|
2012-05-13 14:47:45 +00:00
|
|
|
|
2011-11-28 04:55:36 +00:00
|
|
|
exec('ls -l dist', function (error, output) {
|
|
|
|
|
console.log(output.replace(/^.*/, ''));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2011-08-14 21:35:36 +00:00
|
|
|
});
|
|
|
|
|
});
|