1
0

sync-ui-version.mjs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env node
  2. /**
  3. * Keep `@colbymchenry/codegraph-ui` on the engine's version number.
  4. *
  5. * The component package draws its screens from the engine's own JSON API, and
  6. * that API is versioned with the binary that serves it — a payload field can
  7. * appear or change shape in any engine release. So the two ship as one number:
  8. * `@colbymchenry/codegraph-ui@1.6.0` is the reader for `codegraph@1.6.0`, and a
  9. * host can pin them together without a compatibility table.
  10. *
  11. * This SYNCS rather than asserts, deliberately. The documented release flow is
  12. * "edit the version in package.json, run the Release workflow" — often as a
  13. * single-file edit in the GitHub web UI — and a check that failed the build
  14. * because a second file had not been edited would turn that into a two-step
  15. * dance for no gain. The same reasoning the workflow's package-lock sync step
  16. * already runs on.
  17. *
  18. * Idempotent: a re-run with the versions already equal writes nothing.
  19. */
  20. import { readFileSync, writeFileSync } from 'node:fs';
  21. import { fileURLToPath } from 'node:url';
  22. const root = fileURLToPath(new URL('../package.json', import.meta.url));
  23. const ui = fileURLToPath(new URL('../ui/package.json', import.meta.url));
  24. const engineVersion = JSON.parse(readFileSync(root, 'utf8')).version;
  25. const raw = readFileSync(ui, 'utf8');
  26. const manifest = JSON.parse(raw);
  27. if (manifest.version === engineVersion) {
  28. console.log(`[sync-ui-version] ui already at ${engineVersion}`);
  29. process.exit(0);
  30. }
  31. // A targeted replacement, not a re-serialise: rewriting the whole file would
  32. // reformat a manifest a human maintains and bury the one-line change in noise.
  33. const next = raw.replace(
  34. /("version"\s*:\s*)"[^"]*"/,
  35. (_match, prefix) => `${prefix}"${engineVersion}"`
  36. );
  37. if (next === raw) {
  38. console.error('[sync-ui-version] could not find a "version" field in ui/package.json');
  39. process.exit(1);
  40. }
  41. writeFileSync(ui, next);
  42. console.log(`[sync-ui-version] ui ${manifest.version} -> ${engineVersion}`);