commit-release.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env node
  2. /**
  3. * Bump, stage, and commit a release in one command:
  4. * `pnpm release:commit <major|minor|patch|x.y.z>`. The namespaced tag stays
  5. * manual — create it from the merged release commit.
  6. */
  7. import path from 'node:path';
  8. import { spawnSync } from 'node:child_process';
  9. import { packageDirs, readJson, root } from './repo.mjs';
  10. const bump = process.argv[2];
  11. function run(command, args) {
  12. const result = spawnSync(command, args, {
  13. cwd: root,
  14. stdio: 'inherit',
  15. env: { ...process.env, CI: 'true' },
  16. });
  17. if (result.error) throw result.error;
  18. if (result.status !== 0) {
  19. process.exit(result.status ?? 1);
  20. }
  21. }
  22. if (!bump) {
  23. console.error('Usage: pnpm release:commit <major|minor|patch|x.y.z>');
  24. process.exit(1);
  25. }
  26. run('node', ['./scripts/bump-release.mjs', bump]);
  27. const version = readJson(path.join(root, packageDirs()[0], 'package.json')).version;
  28. run('git', [
  29. 'add',
  30. 'package.json',
  31. 'packages/*/package.json',
  32. '../../pnpm-lock.yaml',
  33. ]);
  34. run('git', ['commit', '-m', `release(node-addon-system): ${version}`]);
  35. console.log(`Committed release ${version}. Create the tag manually: git tag node-addon-system-v${version}`);