| 1 | // Sets one version on the root and every apps/* package.json, so a single tag names a release. Usage: bun scripts/bump-version.ts <major|minor|patch|x.y.z> |
| 2 | import { readdirSync, readFileSync |
| 3 | |
| 4 | const SEMVER = / |
| 5 | const VERSION_FIELD = / |
| 6 | |
| 7 | export function nextVersion(current |
| 8 | if (SEMVER.test |
| 9 | const match = |
| 10 | if (!match) |
| 11 | const [major, |
| 12 | if (bump === |
| 13 | if (bump === |
| 14 | if (bump === |
| 15 | throw new Error( |
| 16 | } |
| 17 | |
| 18 | if (import.meta.main |
| 19 | process.chdir(`${ |
| 20 | |
| 21 | const files = |
| 22 | "package.json", |
| 23 | ...readdirSync("apps" |
| 24 | .filter((entry) |
| 25 | .map((entry) |
| 26 | .filter((file) |
| 27 | try { |
| 28 | return VERSION_FIELD.test |
| 29 | } catch { |
| 30 | return false; |
| 31 | } |
| 32 | }), |
| 33 | ]; |
| 34 | |
| 35 | const current = |
| 36 | const version = |
| 37 | |
| 38 | // a field edit rather than JSON.stringify, so each file keeps its own formatting |
| 39 | for (const file |
| 40 | writeFileSync( |
| 41 | file, |
| 42 | readFileSync(file, " |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | console.log( |
| 47 | `${current} -> ${version |
| 48 | ); |
| 49 | console.log( |
| 50 | `Next: add a changelog entry, commit "release: ${version}", then tag v${ |
| 51 | ); |
| 52 | } |