setNightlyVersion.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. //@ts-check
  6. const fs = require('fs');
  7. const cp = require('child_process');
  8. if (process.argv.length !== 3) {
  9. console.error(`usage: node setNightlyVersion.js <PATH_TO_PACKAGE_JSON_FILE>`);
  10. process.exit(1);
  11. }
  12. const packagejson = JSON.parse(fs.readFileSync(process.argv[2]).toString());
  13. const packageName = packagejson.name;
  14. if (packageName !== 'monaco-editor' && packageName !== 'monaco-editor-core') {
  15. console.error(`expected name to be 'monaco-editor' or 'monaco-editor-core'`);
  16. process.exit(1);
  17. }
  18. /** @type {string} */
  19. const latestVersion = (() => {
  20. const output = cp.execSync(`npm show ${packageName} version`).toString();
  21. const version = output.split(/\r\n|\r|\n/g)[0];
  22. if (!/\d+\.\d+\.\d+/.test(version)) {
  23. console.log('unrecognized package.json version: ' + version);
  24. process.exit(1);
  25. }
  26. return version;
  27. })();
  28. if (!/^0\.(\d+)\.(\d+)$/.test(latestVersion)) {
  29. console.error(`version ${latestVersion} does not match 0.x.y`);
  30. process.exit(1);
  31. }
  32. const devVersion = (() => {
  33. const pieces = latestVersion.split('.');
  34. const minor = parseInt(pieces[1], 10);
  35. const date = new Date();
  36. const yyyy = date.getUTCFullYear();
  37. const mm = String(date.getUTCMonth() + 1).padStart(2, '0');
  38. const dd = String(date.getUTCDate()).padStart(2, '0');
  39. return `0.${minor + 1}.0-dev.${yyyy}${mm}${dd}`;
  40. })();
  41. packagejson.version = devVersion;
  42. fs.writeFileSync(process.argv[2], JSON.stringify(packagejson, null, '\t') + '\n');