build.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env node
  2. var fs = require('fs');
  3. var querystring = require('querystring');
  4. var child_process = require('child_process');
  5. function run(command, callback) {
  6. console.log(command);
  7. child_process.exec(command, callback);
  8. }
  9. // Use browserify to package up source-map-support.js
  10. fs.writeFileSync('.temp.js', 'sourceMapSupport = require("./source-map-support");');
  11. run('node_modules/browserify/bin/cmd.js .temp.js', function(error, stdout) {
  12. if (error) throw error;
  13. // Wrap the code so it works both as a normal <script> module and as an AMD module
  14. var header = [
  15. '/*',
  16. ' * Support for source maps in V8 stack traces',
  17. ' * https://github.com/evanw/node-source-map-support',
  18. ' */',
  19. ].join('\n');
  20. var code = [
  21. '(this["define"] || function(name, callback) { this["sourceMapSupport"] = callback(); })("browser-source-map-support", function(sourceMapSupport) {',
  22. stdout.replace(/\bbyte\b/g, 'bite').replace(new RegExp(__dirname + '/', 'g'), '').replace(/@license/g, 'license'),
  23. 'return sourceMapSupport});',
  24. ].join('\n');
  25. // Use the online Google Closure Compiler service for minification
  26. fs.writeFileSync('.temp.js', querystring.stringify({
  27. compilation_level: 'SIMPLE_OPTIMIZATIONS',
  28. output_info: 'compiled_code',
  29. output_format: 'text',
  30. js_code: code
  31. }));
  32. run('curl -d @.temp.js "http://closure-compiler.appspot.com/compile"', function(error, stdout) {
  33. if (error) throw error;
  34. var code = header + '\n' + stdout;
  35. fs.unlinkSync('.temp.js');
  36. fs.writeFileSync('browser-source-map-support.js', code);
  37. fs.writeFileSync('amd-test/browser-source-map-support.js', code);
  38. });
  39. });
  40. // Build the AMD test
  41. run('node_modules/coffee-script/bin/coffee --map --compile amd-test/script.coffee', function(error) {
  42. if (error) throw error;
  43. });
  44. // Build the browserify test
  45. run('node_modules/coffee-script/bin/coffee --map --compile browserify-test/script.coffee', function(error) {
  46. if (error) throw error;
  47. run('node_modules/browserify/bin/cmd.js --debug browserify-test/script.js > browserify-test/compiled.js', function(error) {
  48. if (error) throw error;
  49. })
  50. });
  51. // Build the browser test
  52. run('node_modules/coffee-script/bin/coffee --map --compile browser-test/script.coffee', function(error) {
  53. if (error) throw error;
  54. });
  55. // Build the header test
  56. run('node_modules/coffee-script/bin/coffee --map --compile header-test/script.coffee', function(error) {
  57. if (error) throw error;
  58. var contents = fs.readFileSync('header-test/script.js', 'utf8');
  59. fs.writeFileSync('header-test/script.js', contents.replace(/\/\/# sourceMappingURL=.*/g, ''))
  60. });