prepare.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. const fs = require('fs');
  20. const packageJsonPath = __dirname + '/../../package.json';
  21. const nightlyPackageName = 'echarts-nightly';
  22. const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
  23. function updateVersion(version) {
  24. const isNext = process.argv.includes('--next');
  25. const parts = /(\d+)\.(\d+)\.(\d+)($|\-)/.exec(version);
  26. if (!parts) {
  27. throw new Error(`Invalid version number ${version}`);
  28. }
  29. // Add date to version.
  30. const major = +parts[1];
  31. let minor = +parts[2];
  32. let patch = +parts[3];
  33. const isStable = !parts[4];
  34. if (isStable) {
  35. // It's previous stable version. Dev version should be higher.
  36. if (isNext) {
  37. // Increase minor version for next branch.
  38. minor++;
  39. patch = 0;
  40. }
  41. else {
  42. // Increase main version for master branch.
  43. patch++;
  44. }
  45. }
  46. const date = new Date().toISOString().replace(/:|T|\.|-/g, '').slice(0, 8);
  47. return `${major}.${minor}.${patch}-dev.${date}`;
  48. }
  49. packageJson.name = nightlyPackageName;
  50. packageJson.version = updateVersion(packageJson.version);
  51. fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
  52. const readmePath = __dirname + '/../../README.md';
  53. const readmeAttention = `<h3>
  54. <p><em>⚠️ ATTENTION PLEASE</em></p>
  55. <p><em>This is nightly build of Apache ECharts. Please DON't use it in your production environment.</em></p>
  56. </h3>`;
  57. const readmeContent = fs.readFileSync(readmePath, 'utf-8');
  58. if (!readmeContent.includes(readmeAttention)) {
  59. fs.writeFileSync(readmePath, `
  60. ${readmeAttention}
  61. ${readmeContent}
  62. `, 'utf-8');
  63. }