build-acorn.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var fs = require("fs"), path = require("path")
  2. var stream = require("stream")
  3. var browserify = require("browserify")
  4. var babelify = require("babelify").configure({loose: "all"})
  5. process.chdir(path.resolve(__dirname, ".."))
  6. browserify({standalone: "acorn"})
  7. .plugin(require('browserify-derequire'))
  8. .transform(babelify)
  9. .require("./src/index.js", {entry: true})
  10. .bundle()
  11. .on("error", function (err) { console.log("Error: " + err.message) })
  12. .pipe(fs.createWriteStream("dist/acorn.js"))
  13. function acornShim(file) {
  14. var tr = new stream.Transform
  15. if (file == path.resolve(__dirname, "../src/index.js")) {
  16. var sent = false
  17. tr._transform = function(chunk, _, callback) {
  18. if (!sent) {
  19. sent = true
  20. callback(null, "module.exports = typeof acorn != 'undefined' ? acorn : _dereq_(\"./acorn\")")
  21. } else {
  22. callback()
  23. }
  24. }
  25. } else {
  26. tr._transform = function(chunk, _, callback) { callback(null, chunk) }
  27. }
  28. return tr
  29. }
  30. browserify({standalone: "acorn.loose"})
  31. .plugin(require('browserify-derequire'))
  32. .transform(acornShim)
  33. .transform(babelify)
  34. .require("./src/loose/index.js", {entry: true})
  35. .bundle()
  36. .on("error", function (err) { console.log("Error: " + err.message) })
  37. .pipe(fs.createWriteStream("dist/acorn_loose.js"))
  38. browserify({standalone: "acorn.walk"})
  39. .plugin(require('browserify-derequire'))
  40. .transform(acornShim)
  41. .transform(babelify)
  42. .require("./src/walk/index.js", {entry: true})
  43. .bundle()
  44. .on("error", function (err) { console.log("Error: " + err.message) })
  45. .pipe(fs.createWriteStream("dist/walk.js"))