sync-versions.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env node
  2. /**
  3. * Version Synchronization Script
  4. *
  5. * Keeps versions synchronized across:
  6. * - pyproject.toml (root)
  7. * - flowsint-app/package.json
  8. *
  9. * Usage: node scripts/sync-versions.js <new-version>
  10. */
  11. import { readFileSync, writeFileSync } from 'fs';
  12. import { join, dirname } from 'path';
  13. import { fileURLToPath } from 'url';
  14. const __filename = fileURLToPath(import.meta.url);
  15. const __dirname = dirname(__filename);
  16. const ROOT_DIR = join(__dirname, '..');
  17. function updatePyprojectVersion(version) {
  18. const pyprojectPath = join(ROOT_DIR, 'pyproject.toml');
  19. let content = readFileSync(pyprojectPath, 'utf8');
  20. // Update version in [project] section
  21. content = content.replace(
  22. /^version = ".*"$/m,
  23. `version = "${version}"`
  24. );
  25. writeFileSync(pyprojectPath, content, 'utf8');
  26. console.log(`✓ Updated pyproject.toml to ${version}`);
  27. }
  28. function updatePackageJsonVersion(version) {
  29. const packagePath = join(ROOT_DIR, 'flowsint-app', 'package.json');
  30. const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
  31. pkg.version = version;
  32. writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
  33. console.log(`✓ Updated flowsint-app/package.json to ${version}`);
  34. }
  35. function getCurrentVersion() {
  36. const packagePath = join(ROOT_DIR, 'flowsint-app', 'package.json');
  37. const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
  38. return pkg.version;
  39. }
  40. // Main execution
  41. const newVersion = process.argv[2];
  42. if (!newVersion) {
  43. console.log(`Current version: ${getCurrentVersion()}`);
  44. console.log('\nUsage: node scripts/sync-versions.js <version>');
  45. console.log('Example: node scripts/sync-versions.js 1.2.3');
  46. process.exit(1);
  47. }
  48. // Validate semantic version format
  49. if (!/^\d+\.\d+\.\d+(-[\w.]+)?$/.test(newVersion)) {
  50. console.error('Error: Invalid version format. Expected: X.Y.Z or X.Y.Z-suffix');
  51. process.exit(1);
  52. }
  53. try {
  54. updatePyprojectVersion(newVersion);
  55. updatePackageJsonVersion(newVersion);
  56. console.log(`\n✓ All versions synchronized to ${newVersion}`);
  57. } catch (error) {
  58. console.error('Error syncing versions:', error.message);
  59. process.exit(1);
  60. }