mirror of
https://github.com/murashit/codex-panel.git
synced 2026-07-22 06:57:10 +00:00
Share release version utilities
This commit is contained in:
parent
ddf155f917
commit
c79dd88a67
3 changed files with 38 additions and 66 deletions
|
|
@ -1,42 +1,12 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { compareVersions, isExpectedNextVersion, parseVersion, readJson } from "./release-utils.mjs";
|
||||
|
||||
function fail(message) {
|
||||
console.error(`release check failed: ${message}`);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
||||
async function readJson(file) {
|
||||
return JSON.parse(await readFile(file, "utf8"));
|
||||
}
|
||||
|
||||
function parseVersion(version) {
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
||||
if (!match) return null;
|
||||
return {
|
||||
major: Number(match[1]),
|
||||
minor: Number(match[2]),
|
||||
patch: Number(match[3]),
|
||||
};
|
||||
}
|
||||
|
||||
function compareVersions(a, b) {
|
||||
return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
||||
}
|
||||
|
||||
function isExpectedNextVersion(previous, current) {
|
||||
if (current.major === previous.major && current.minor === previous.minor) {
|
||||
return current.patch === previous.patch + 1;
|
||||
}
|
||||
if (current.major === previous.major && current.minor === previous.minor + 1) {
|
||||
return current.patch === 0;
|
||||
}
|
||||
if (current.major === previous.major + 1) {
|
||||
return current.minor === 0 && current.patch === 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const packageJson = await readJson("package.json");
|
||||
const packageLockJson = await readJson("package-lock.json");
|
||||
const manifestJson = await readJson("manifest.json");
|
||||
|
|
|
|||
|
|
@ -1,46 +1,12 @@
|
|||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { compareVersions, isExpectedNextVersion, parseVersion, readJson, writeJson } from "./release-utils.mjs";
|
||||
|
||||
function fail(message) {
|
||||
console.error(`release prepare failed: ${message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
async function readJson(file) {
|
||||
return JSON.parse(await readFile(file, "utf8"));
|
||||
}
|
||||
|
||||
async function writeJson(file, value) {
|
||||
await writeFile(file, `${JSON.stringify(value, null, 2)}\n`);
|
||||
}
|
||||
|
||||
function parseVersion(version) {
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
||||
if (!match) return null;
|
||||
return {
|
||||
major: Number(match[1]),
|
||||
minor: Number(match[2]),
|
||||
patch: Number(match[3]),
|
||||
};
|
||||
}
|
||||
|
||||
function compareVersions(a, b) {
|
||||
return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
||||
}
|
||||
|
||||
function isExpectedNextVersion(previous, current) {
|
||||
if (current.major === previous.major && current.minor === previous.minor) {
|
||||
return current.patch === previous.patch + 1;
|
||||
}
|
||||
if (current.major === previous.major && current.minor === previous.minor + 1) {
|
||||
return current.patch === 0;
|
||||
}
|
||||
if (current.major === previous.major + 1) {
|
||||
return current.minor === 0 && current.patch === 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const releaseVersion = process.argv[2];
|
||||
if (!releaseVersion) fail("usage: npm run release:prepare -- X.Y.Z");
|
||||
|
||||
|
|
|
|||
36
scripts/release-utils.mjs
Normal file
36
scripts/release-utils.mjs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { readFile, writeFile } from "node:fs/promises";
|
||||
|
||||
export async function readJson(file) {
|
||||
return JSON.parse(await readFile(file, "utf8"));
|
||||
}
|
||||
|
||||
export async function writeJson(file, value) {
|
||||
await writeFile(file, `${JSON.stringify(value, null, 2)}\n`);
|
||||
}
|
||||
|
||||
export function parseVersion(version) {
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
||||
if (!match) return null;
|
||||
return {
|
||||
major: Number(match[1]),
|
||||
minor: Number(match[2]),
|
||||
patch: Number(match[3]),
|
||||
};
|
||||
}
|
||||
|
||||
export function compareVersions(a, b) {
|
||||
return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
||||
}
|
||||
|
||||
export function isExpectedNextVersion(previous, current) {
|
||||
if (current.major === previous.major && current.minor === previous.minor) {
|
||||
return current.patch === previous.patch + 1;
|
||||
}
|
||||
if (current.major === previous.major && current.minor === previous.minor + 1) {
|
||||
return current.patch === 0;
|
||||
}
|
||||
if (current.major === previous.major + 1) {
|
||||
return current.minor === 0 && current.patch === 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Loading…
Reference in a new issue