prepareNightly.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const fs = require('fs');
  2. const packageJsonPath = __dirname + '/../package.json';
  3. const nightlyPackageName = 'zrender-nightly';
  4. function updateVersion(version) {
  5. const isNext = process.argv.includes('--next');
  6. const parts = /(\d+)\.(\d+)\.(\d+)($|\-)/.exec(version);
  7. if (!parts) {
  8. throw new Error(`Invalid version number ${version}`);
  9. }
  10. // Add date to version.
  11. const major = +parts[1];
  12. let minor = +parts[2];
  13. let patch = +parts[3];
  14. const isStable = !parts[4];
  15. if (isStable) {
  16. // It's previous stable version. Dev version should be higher.
  17. if (isNext) {
  18. // Increase minor version for next branch.
  19. minor++;
  20. patch = 0;
  21. }
  22. else {
  23. // Increase main version for master branch.
  24. patch++;
  25. }
  26. }
  27. const date = new Date().toISOString().replace(/:|T|\.|-/g, '').slice(0, 8);
  28. return `${major}.${minor}.${patch}-dev.${date}`;
  29. }
  30. const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
  31. packageJson.name = nightlyPackageName;
  32. packageJson.version = updateVersion(packageJson.version);
  33. fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');