pre-publish.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Compatible with prevoius folder structure: `echarts/lib` exists in `node_modules`
  3. * (1) Build all files to CommonJS to `echarts/lib`.
  4. * (2) Remove __DEV__.
  5. * (3) Mount `echarts/src/export.js` to `echarts/lib/echarts.js`.
  6. */
  7. const path = require('path');
  8. const fsExtra = require('fs-extra');
  9. const {color, travelSrcDir, prePulishSrc} = require('zrender/build/helper');
  10. const ecDir = path.resolve(__dirname, '..');
  11. const srcDir = path.resolve(__dirname, '../src');
  12. const extensionSrcDir = path.resolve(__dirname, '../extension-src');
  13. const extensionDir = path.resolve(__dirname, '../extension');
  14. const libDir = path.resolve(__dirname, '../lib');
  15. module.exports = function () {
  16. fsExtra.removeSync(libDir);
  17. fsExtra.ensureDirSync(libDir);
  18. travelSrcDir(srcDir, ({fileName, relativePath, absolutePath}) => {
  19. prePulishSrc({
  20. inputPath: absolutePath,
  21. outputPath: path.resolve(libDir, relativePath, fileName),
  22. transform
  23. });
  24. });
  25. travelSrcDir(extensionSrcDir, ({fileName, relativePath, absolutePath}) => {
  26. prePulishSrc({
  27. inputPath: absolutePath,
  28. outputPath: path.resolve(extensionDir, relativePath, fileName),
  29. transform
  30. });
  31. });
  32. prePulishSrc({
  33. inputPath: path.resolve(ecDir, 'echarts.all.js'),
  34. outputPath: path.resolve(ecDir, 'index.js')
  35. });
  36. prePulishSrc({
  37. inputPath: path.resolve(ecDir, 'echarts.common.js'),
  38. outputPath: path.resolve(ecDir, 'index.common.js')
  39. });
  40. prePulishSrc({
  41. inputPath: path.resolve(ecDir, 'echarts.simple.js'),
  42. outputPath: path.resolve(ecDir, 'index.simple.js')
  43. });
  44. function transform({code, inputPath, outputPath}) {
  45. if (inputPath === path.resolve(ecDir, 'src/echarts.js')) {
  46. // Using `echarts/echarts.blank.js` to overwrite `echarts/lib/echarts.js`
  47. // for including exports API.
  48. code += `
  49. var ___ec_export = require("./export");
  50. (function () {
  51. for (var key in ___ec_export) {
  52. if (___ec_export.hasOwnProperty(key)) {
  53. exports[key] = ___ec_export[key];
  54. }
  55. }
  56. })();`;
  57. }
  58. return code;
  59. }
  60. console.log(color('fgGreen', 'bright')('All done.'));
  61. };