-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`; |