build.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // For the basic introductions on using this build script, see:
  2. //
  3. // <https://highlightjs.readthedocs.org/en/latest/building-testing.html>
  4. //
  5. // Otherwise, lets explain what each build target does in more detail, for
  6. // those that wish to know before running this script.
  7. //
  8. // Build Targets
  9. // -------------
  10. //
  11. // * browser
  12. //
  13. // The default target. This will package up the core `highlight.js` along
  14. // with all the language definitions into the file `highlight.pack.js` --
  15. // which will be compressed without including the option to disable it. It
  16. // also builds the documentation for our readthedocs page, mentioned
  17. // above, along with a local instance of the demo at:
  18. //
  19. // <https://highlightjs.org/static/demo/>.
  20. //
  21. // * cdn
  22. //
  23. // This will package up the core `highlight.js` along with all the
  24. // language definitions into the file `highlight.min.js` and compresses
  25. // all languages and styles into separate files. Since the target is for
  26. // CDNs -- like cdnjs and jsdelivr -- it doesn't matter if you put the
  27. // option to disable compression, this target is always be compressed. Do
  28. // keep in mind that we don't keep the build results in the main
  29. // repository; however, there is a separate repository for those that want
  30. // the CDN builds without using a third party site or building it
  31. // themselves. For those curious, head over to:
  32. //
  33. // <https://github.com/highlightjs/cdn-release>
  34. //
  35. // * node
  36. //
  37. // This build will transform the library into a CommonJS module. It
  38. // includes the generation of an `index.js` file that will be the main
  39. // file imported for use with Node.js or browserify. Do note that this
  40. // includes all languages by default and it might be too heavy to use for
  41. // browserify. Luckily, you can easily do two things to make the build
  42. // smaller; either specify the specific language/category you need or you
  43. // can use the browser or cdn builds and it will work like any CommonJS
  44. // file. Also with the CommonJS module, it includes the documentation for
  45. // our readthedocs page and the uncompressed styles. Getting this build is
  46. // pretty easy as it is the one that gets published to npm with the
  47. // standard `npm install highlight.js`, but you can also visit the package
  48. // page at:
  49. //
  50. // <https://www.npmjs.com/package/highlight.js>
  51. //
  52. // * all
  53. //
  54. // Builds every target and places the results into a sub-directory based
  55. // off of the target name relative to the `build` directory; for example,
  56. // "node" with go into `build/node`, "cdn" will go into `build/cdn`,
  57. // "browser" will go into `build/browser` and so forth.
  58. //
  59. // All build targets will end up in the `build` directory.
  60. 'use strict';
  61. let commander = require('commander');
  62. let path = require('path');
  63. let Queue = require('gear').Queue;
  64. let registry = require('./tasks');
  65. let build, dir = {};
  66. commander
  67. .usage('[options] [<language>...]')
  68. .option('-n, --no-compress', 'Disable compression')
  69. .option('-t, --target <name>', 'Build for target ' +
  70. '[all, browser, cdn, node]',
  71. /^(browser|cdn|node|all)$/i, 'browser')
  72. .parse(process.argv);
  73. commander.target = commander.target.toLowerCase();
  74. build = require(`./${commander.target}`);
  75. dir.root = path.dirname(__dirname);
  76. dir.build = path.join(dir.root, 'build');
  77. new Queue({ registry: registry })
  78. .clean(dir.build)
  79. .log('Starting build.')
  80. .series(build(commander, dir))
  81. .log('Finished build.')
  82. .run();