#!/usr/bin/env node import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import TOML from '@iarna/toml'; const root = process.cwd(); const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf-8')) as Record; const workspace = TOML.parse(readFileSync(join(root, 'Cargo.toml'), 'utf-8')) as Record; const explore = TOML.parse(readFileSync(join(root, 'crates', 'omx-explore', 'Cargo.toml'), 'utf-8')) as Record; const runtimeCore = TOML.parse(readFileSync(join(root, 'crates', 'omx-runtime-core', 'Cargo.toml'), 'utf-8')) as Record; const mux = TOML.parse(readFileSync(join(root, 'crates', 'omx-mux', 'Cargo.toml'), 'utf-8')) as Record; const runtime = TOML.parse(readFileSync(join(root, 'native', 'omx-runtime', 'Cargo.toml'), 'utf-8')) as Record; const sparkshell = TOML.parse(readFileSync(join(root, 'native', 'omx-sparkshell', 'Cargo.toml'), 'utf-8')) as Record; const tagArgIndex = process.argv.indexOf('--tag'); const tag = tagArgIndex >= 0 ? process.argv[tagArgIndex + 1] : undefined; const pkgVersion = String(pkg.version || '').trim(); const workspaceVersion = String((workspace.workspace as Record)?.package as Record !== undefined ? ((workspace.workspace as Record).package as Record)?.version || '' : '').trim(); const problems: string[] = []; if (!pkgVersion) problems.push('package.json version is missing'); if (!workspaceVersion) problems.push('Cargo.toml [workspace.package].version is missing'); if (pkgVersion && workspaceVersion && pkgVersion !== workspaceVersion) { problems.push(`package.json version (${pkgVersion}) does not match workspace version (${workspaceVersion})`); } if ((explore.package as Record)?.version !== undefined && ((explore.package as Record).version as Record)?.workspace !== true) { problems.push('crates/omx-explore/Cargo.toml must use version.workspace = true'); } if ((runtimeCore.package as Record)?.version !== undefined && ((runtimeCore.package as Record).version as Record)?.workspace !== true) { problems.push('crates/omx-runtime-core/Cargo.toml must use version.workspace = true'); } if ((mux.package as Record)?.version !== undefined && ((mux.package as Record).version as Record)?.workspace !== true) { problems.push('crates/omx-mux/Cargo.toml must use version.workspace = true'); } if ((runtime.package as Record)?.version !== undefined && ((runtime.package as Record).version as Record)?.workspace !== true) { problems.push('native/omx-runtime/Cargo.toml must use version.workspace = true'); } if ((sparkshell.package as Record)?.version !== undefined && ((sparkshell.package as Record).version as Record)?.workspace !== true) { problems.push('native/omx-sparkshell/Cargo.toml must use version.workspace = true'); } if (tag && tag !== `v${pkgVersion}`) { problems.push(`release tag (${tag}) does not match package.json version (v${pkgVersion})`); } if (problems.length > 0) { for (const problem of problems) console.error(`[version-sync] ${problem}`); process.exit(1); } console.log(`[version-sync] OK package=${pkgVersion} workspace=${workspaceVersion}${tag ? ` tag=${tag}` : ''}`);