50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { resolve } from "jsr:@std/path";
|
|
import { format, parse } from "jsr:@std/semver";
|
|
|
|
interface BumpArgs {
|
|
pluginDir?: string;
|
|
}
|
|
|
|
export async function bumpVersion(
|
|
args: BumpArgs,
|
|
level: "patch" | "minor" | "major",
|
|
) {
|
|
console.info("Bumping plugin version. Checking for required files");
|
|
const cwd = args.pluginDir ? resolve(Deno.cwd(), args.pluginDir) : Deno.cwd();
|
|
const manifestPath = resolve(cwd, "manifest.json");
|
|
const versionsPath = resolve(cwd, "versions.json");
|
|
|
|
const manifestText = await Deno.readTextFile(manifestPath);
|
|
const manifest = JSON.parse(manifestText);
|
|
const versionsText = await Deno.readTextFile(versionsPath);
|
|
const versions = JSON.parse(versionsText);
|
|
|
|
const appSemver = parse(manifest.version);
|
|
|
|
appSemver[level] += 1;
|
|
|
|
const newVersion = format(appSemver);
|
|
const newMinAppVersion = manifest.minAppVersion;
|
|
|
|
// Write new manifest
|
|
manifest.version = newVersion;
|
|
const newManifest = JSON.stringify(manifest, null, "\t");
|
|
|
|
// Write new minimum version, if required
|
|
if (!(Object.values(versions).includes(manifest.minAppVersion))) {
|
|
console.info(
|
|
"Minimum app version updated. Writing to versions file",
|
|
);
|
|
|
|
versions[newVersion] = newMinAppVersion;
|
|
const newVersions = JSON.stringify(versions, null, "\t");
|
|
|
|
await Deno.writeTextFile(versionsPath, newVersions);
|
|
}
|
|
|
|
console.info("Writing version to manifest");
|
|
|
|
await Deno.writeTextFile(manifestPath, newManifest);
|
|
|
|
console.log(`Bumped ${manifest.name} to version ${newVersion}`);
|
|
}
|