diff --git a/bun.lockb b/bun.lockb index ef90ef2..df109b3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 5f1c25d..cdcc1e2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "narrow", + "name": "tawri", "version": "0.1.1", "description": "", "type": "module", @@ -13,7 +13,7 @@ "tauri": "tauri", "lint": "biome lint", "format": "biome format --write", - "bump": "bunx tauri-version patch" + "version": "bun run version.ts" }, "license": "MIT", "dependencies": { @@ -43,8 +43,10 @@ "@tailwindcss/typography": "^0.5.15", "@types/bun": "latest", "@types/node": "^22.10.2", + "@types/semver": "^7.5.8", "autoprefixer": "^10.4.20", "postcss": "^8.4.49", + "semver": "^7.6.3", "svelte": "^5.15.0", "svelte-check": "^4.1.1", "tailwindcss": "^3.4.17", diff --git a/version.ts b/version.ts new file mode 100644 index 0000000..71c8b65 --- /dev/null +++ b/version.ts @@ -0,0 +1,51 @@ +import { fail } from "node:assert"; +import { $ } from "bun"; +import { type ReleaseType, inc, valid as isValidVersion } from "semver"; + +const path = "./package.json"; +const variants: ReleaseType[] = [ + "major", + "premajor", + "minor", + "preminor", + "patch", + "prepatch", + "prerelease", +]; + +const isValidTarget = (subject: string): subject is ReleaseType => + (variants as string[]).includes(subject); + +const isDirty = async () => (await $`git status --porcelain`.quiet()).text(); + +const target = Bun.argv.pop(); +const json = await Bun.file(path).json(); +const { version: current } = json; + +if (!isValidVersion(current)) + throw new Error(`Invalid current version ${current}`); + +if (await isDirty()) + throw new Error( + "There are uncommitted changes. Commit them before releasing.", + ); + +const desired = isValidVersion(target) + ? target + : target && isValidTarget(target) + ? inc(current, target, "beta", "1") + : fail("invalid target version"); + +if (!desired) throw new Error("Failed to bump"); +console.debug(current, "—>", desired); + +await Bun.write( + path, + JSON.stringify(Object.assign(json, { version: desired }), null, 2), +); + +await $`git add ${path}`; +await $`git commit -m v${desired}`; +await $`git tag v${desired}`; +await $`git push`; +await $`git push --tags`; \ No newline at end of file