pre-publish.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * Compatible with prevoius folder structure: `echarts/lib` exists in `node_modules`
  21. * (1) Build all files to CommonJS to `echarts/lib`.
  22. * (2) Remove __DEV__.
  23. * (3) Mount `echarts/src/export.js` to `echarts/lib/echarts.js`.
  24. */
  25. const path = require('path');
  26. const fsExtra = require('fs-extra');
  27. const {color, travelSrcDir, prePulishSrc} = require('zrender/build/helper');
  28. const ecDir = path.resolve(__dirname, '..');
  29. const srcDir = path.resolve(__dirname, '../src');
  30. const extensionSrcDir = path.resolve(__dirname, '../extension-src');
  31. const extensionDir = path.resolve(__dirname, '../extension');
  32. const libDir = path.resolve(__dirname, '../lib');
  33. const preamble = require('./preamble');
  34. module.exports = function () {
  35. fsExtra.removeSync(libDir);
  36. fsExtra.ensureDirSync(libDir);
  37. travelSrcDir(srcDir, ({fileName, relativePath, absolutePath}) => {
  38. prePulishSrc({
  39. inputPath: absolutePath,
  40. outputPath: path.resolve(libDir, relativePath, fileName),
  41. transform: transform,
  42. preamble: preamble.js
  43. });
  44. });
  45. travelSrcDir(extensionSrcDir, ({fileName, relativePath, absolutePath}) => {
  46. prePulishSrc({
  47. inputPath: absolutePath,
  48. outputPath: path.resolve(extensionDir, relativePath, fileName),
  49. transform: transform,
  50. preamble: preamble.js
  51. });
  52. });
  53. prePulishSrc({
  54. inputPath: path.resolve(ecDir, 'echarts.all.js'),
  55. outputPath: path.resolve(ecDir, 'index.js'),
  56. preamble: preamble.js
  57. });
  58. prePulishSrc({
  59. inputPath: path.resolve(ecDir, 'echarts.common.js'),
  60. outputPath: path.resolve(ecDir, 'index.common.js'),
  61. preamble: preamble.js
  62. });
  63. prePulishSrc({
  64. inputPath: path.resolve(ecDir, 'echarts.simple.js'),
  65. outputPath: path.resolve(ecDir, 'index.simple.js'),
  66. preamble: preamble.js
  67. });
  68. function transform({code, inputPath, outputPath}) {
  69. if (inputPath === path.resolve(ecDir, 'src/echarts.js')) {
  70. // Using `echarts/echarts.blank.js` to overwrite `echarts/lib/echarts.js`
  71. // for including exports API.
  72. code += `
  73. var ___ec_export = require("./export");
  74. (function () {
  75. for (var key in ___ec_export) {
  76. if (___ec_export.hasOwnProperty(key)) {
  77. exports[key] = ___ec_export[key];
  78. }
  79. }
  80. })();`;
  81. }
  82. return code;
  83. }
  84. console.log(color('fgGreen', 'bright')('All done.'));
  85. };