prepareNightly.js 1.6 KB

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