2013-11-14 13:05:33 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
var fs = require('fs');
|
2015-02-23 04:14:18 +08:00
|
|
|
var path = require('path');
|
2013-11-14 13:05:33 +08:00
|
|
|
var querystring = require('querystring');
|
|
|
|
var child_process = require('child_process');
|
|
|
|
|
2015-02-23 04:14:18 +08:00
|
|
|
var browserify = path.join('node_modules', '.bin', 'browserify');
|
|
|
|
var coffee = path.join('node_modules', '.bin', 'coffee');
|
|
|
|
|
2014-07-03 23:38:55 +08:00
|
|
|
function run(command, callback) {
|
|
|
|
console.log(command);
|
|
|
|
child_process.exec(command, callback);
|
|
|
|
}
|
|
|
|
|
2013-11-14 13:05:33 +08:00
|
|
|
// Use browserify to package up source-map-support.js
|
|
|
|
fs.writeFileSync('.temp.js', 'sourceMapSupport = require("./source-map-support");');
|
2015-02-23 04:14:18 +08:00
|
|
|
run(browserify + ' .temp.js', function(error, stdout) {
|
2013-11-14 13:05:33 +08:00
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
// Wrap the code so it works both as a normal <script> module and as an AMD module
|
|
|
|
var header = [
|
|
|
|
'/*',
|
|
|
|
' * Support for source maps in V8 stack traces',
|
|
|
|
' * https://github.com/evanw/node-source-map-support',
|
|
|
|
' */',
|
|
|
|
].join('\n');
|
|
|
|
var code = [
|
|
|
|
'(this["define"] || function(name, callback) { this["sourceMapSupport"] = callback(); })("browser-source-map-support", function(sourceMapSupport) {',
|
2014-04-27 03:43:52 +08:00
|
|
|
stdout.replace(/\bbyte\b/g, 'bite').replace(new RegExp(__dirname + '/', 'g'), '').replace(/@license/g, 'license'),
|
2013-11-14 13:05:33 +08:00
|
|
|
'return sourceMapSupport});',
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
// Use the online Google Closure Compiler service for minification
|
|
|
|
fs.writeFileSync('.temp.js', querystring.stringify({
|
|
|
|
compilation_level: 'SIMPLE_OPTIMIZATIONS',
|
|
|
|
output_info: 'compiled_code',
|
|
|
|
output_format: 'text',
|
|
|
|
js_code: code
|
|
|
|
}));
|
2014-07-03 23:38:55 +08:00
|
|
|
run('curl -d @.temp.js "http://closure-compiler.appspot.com/compile"', function(error, stdout) {
|
2013-11-14 13:05:33 +08:00
|
|
|
if (error) throw error;
|
|
|
|
var code = header + '\n' + stdout;
|
|
|
|
fs.unlinkSync('.temp.js');
|
|
|
|
fs.writeFileSync('browser-source-map-support.js', code);
|
|
|
|
fs.writeFileSync('amd-test/browser-source-map-support.js', code);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build the AMD test
|
2015-02-23 04:14:18 +08:00
|
|
|
run(coffee + ' --map --compile amd-test/script.coffee', function(error) {
|
2013-11-14 13:05:33 +08:00
|
|
|
if (error) throw error;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build the browserify test
|
2015-02-23 04:14:18 +08:00
|
|
|
run(coffee + ' --map --compile browserify-test/script.coffee', function(error) {
|
2013-11-14 13:05:33 +08:00
|
|
|
if (error) throw error;
|
2015-02-23 04:14:18 +08:00
|
|
|
run(browserify + ' --debug browserify-test/script.js > browserify-test/compiled.js', function(error) {
|
2013-11-14 13:05:33 +08:00
|
|
|
if (error) throw error;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build the browser test
|
2015-02-23 04:14:18 +08:00
|
|
|
run(coffee + ' --map --compile browser-test/script.coffee', function(error) {
|
2014-07-03 23:38:55 +08:00
|
|
|
if (error) throw error;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build the header test
|
2015-02-23 04:14:18 +08:00
|
|
|
run(coffee + ' --map --compile header-test/script.coffee', function(error) {
|
2013-11-14 13:05:33 +08:00
|
|
|
if (error) throw error;
|
2014-07-03 23:38:55 +08:00
|
|
|
var contents = fs.readFileSync('header-test/script.js', 'utf8');
|
|
|
|
fs.writeFileSync('header-test/script.js', contents.replace(/\/\/# sourceMappingURL=.*/g, ''))
|
2013-11-14 13:05:33 +08:00
|
|
|
});
|