cli-release.mjs 1.5 KB

12345678910111213141516171819202122232425262728293031
  1. import { readFileSync } from 'node:fs';
  2. import path from 'node:path';
  3. export function versionFromTag(tag) {
  4. // Accept canonical SemVer release/prerelease tags, with no build metadata.
  5. const number = '(?:0|[1-9][0-9]*)';
  6. const identifier = '(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)';
  7. if (typeof tag !== 'string' || tag.trim() !== tag || !new RegExp(`^v${number}\\.${number}\\.${number}(?:-${identifier}(?:\\.${identifier})*)?$`).test(tag)) {
  8. throw new Error('Release tag must be vX.Y.Z or vX.Y.Z-prerelease (canonical SemVer).');
  9. }
  10. return tag.slice(1);
  11. }
  12. export function cliBuildVersion(root, tag = process.env.MCODE_RELEASE_TAG) {
  13. const version = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')).version;
  14. const tuiVersion = JSON.parse(readFileSync(path.join(root, 'packages/tui/package.json'), 'utf8')).version;
  15. if (version !== tuiVersion) throw new Error('Root and TUI package versions must match.');
  16. if (tag != null && versionFromTag(tag) !== version) throw new Error('Release tag must match root and TUI package versions. Run the release command before tagging.');
  17. return version;
  18. }
  19. // These modules stay outside the JS bundle and must travel with an installation.
  20. export const cliExternalModules = [
  21. 'better-sqlite3',
  22. '@mariozechner/clipboard',
  23. '@vscode/ripgrep',
  24. '@larksuiteoapi/node-sdk',
  25. ];
  26. export const cliReleaseTargets = ['ubuntu-latest', 'macos-latest'].flatMap(os =>
  27. ['22.19.0', '24.2.0', '25', '26'].map(node => ({ os, node })));