build.ls 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require! {
  2. '../library/fn/promise': Promise
  3. './config': {list, experimental, libraryBlacklist, es5SpecialCase, banner}
  4. fs: {readFile, writeFile, unlink}
  5. path: {basename, dirname, join}
  6. webpack, temp
  7. }
  8. module.exports = ({modules = [], blacklist = [], library = no, umd = on})->
  9. resolve, reject <~! new Promise _
  10. let @ = modules.reduce ((memo, it)-> memo[it] = on; memo), {}
  11. if @exp => for experimental => @[..] = on
  12. if @es5 => for es5SpecialCase => @[..] = on
  13. for ns of @
  14. if @[ns]
  15. for name in list
  16. if name.indexOf("#ns.") is 0 and name not in experimental
  17. @[name] = on
  18. if library => blacklist ++= libraryBlacklist
  19. for ns in blacklist
  20. for name in list
  21. if name is ns or name.indexOf("#ns.") is 0
  22. @[name] = no
  23. TARGET = temp.path {suffix: '.js'}
  24. err, info <~! webpack do
  25. entry: list.filter(~> @[it]).map ~>
  26. if library => join __dirname, '..', 'library', 'modules', it
  27. else join __dirname, '..', 'modules', it
  28. output:
  29. path: dirname TARGET
  30. filename: basename "./#TARGET"
  31. if err => return reject err
  32. err, script <~! readFile TARGET
  33. if err => return reject err
  34. err <~! unlink TARGET
  35. if err => return reject err
  36. if umd
  37. exportScript = """
  38. // CommonJS export
  39. if (typeof module != 'undefined' && module.exports) module.exports = __e;
  40. // RequireJS export
  41. else if (typeof define == 'function' && define.amd) define(function () { return __e; });
  42. // Export to global object
  43. else __g.core = __e;
  44. """
  45. else
  46. exportScript = ""
  47. resolve """
  48. #banner
  49. !function(__e, __g, undefined){
  50. 'use strict';
  51. #script
  52. #exportScript
  53. }(1, 1);
  54. """