feat: enhance package version management in check-package-version script
This commit is contained in:
@@ -1,28 +1,53 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { readFileSync, writeFileSync } from "node:fs";
|
import { readFileSync, writeFileSync } from "node:fs";
|
||||||
import { execSync, spawnSync } from "node:child_process";
|
import { spawnSync } from "node:child_process";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
|
import { inc } from "semver";
|
||||||
|
|
||||||
const skAzToolsPackagePath = resolve("package.json");
|
const skAzToolsPackagePath = resolve("package.json");
|
||||||
|
const skAzToolsPackageLockPath = resolve("package-lock.json");
|
||||||
const skToolsPackagePath = resolve("../sk-tools", "package.json");
|
const skToolsPackagePath = resolve("../sk-tools", "package.json");
|
||||||
|
|
||||||
const skAzToolsPackage = JSON.parse(readFileSync(skAzToolsPackagePath, "utf-8"));
|
const skAzToolsPackage = JSON.parse(readFileSync(skAzToolsPackagePath, "utf-8"));
|
||||||
|
const skAzToolsPackageLock = JSON.parse(readFileSync(skAzToolsPackageLockPath, "utf-8"));
|
||||||
const skToolsPackage = JSON.parse(readFileSync(skToolsPackagePath, "utf-8"));
|
const skToolsPackage = JSON.parse(readFileSync(skToolsPackagePath, "utf-8"));
|
||||||
|
|
||||||
const { values } = parseArgs({
|
const { values } = parseArgs({
|
||||||
options: {
|
options: {
|
||||||
update: { type: "boolean", short: "u", description: "Update @slawek/sk-tools to the latest version." }
|
update: { type: "boolean", short: "u", description: "Update @slawek/sk-tools to the latest version." },
|
||||||
|
bump: { type: "string", short: "b", description: "Bump the version of @slawek/sk-az-tools in package.json. Allowed values: major, minor, patch." }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!["major", "minor", "patch"].includes(values.bump)) {
|
||||||
|
console.error(`Invalid bump type: ${values.bump}. Allowed values are: major, minor, patch.`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Package versions
|
// Package versions
|
||||||
console.log(`SK Tools version: ${skToolsPackage.version}`);
|
console.log(`SK Tools version: ${skToolsPackage.version}`);
|
||||||
console.log(`SK Azure Tools version: ${skAzToolsPackage.version}`);
|
console.log(`SK Azure Tools version: ${skAzToolsPackage.version}\n`);
|
||||||
|
|
||||||
if (values.update) {
|
if (values.bump) {
|
||||||
console.log(`\nUpdating package.json to use @slawek/sk-tools version ${skToolsPackage.version} or later...`);
|
const newVersion = inc(skAzToolsPackage.version, values.bump);
|
||||||
|
if (!newVersion) {
|
||||||
|
console.error(`Failed to bump version: ${skAzToolsPackage.version}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
skAzToolsPackage.version = newVersion;
|
||||||
|
writeFileSync(skAzToolsPackagePath, JSON.stringify(skAzToolsPackage, null, 4));
|
||||||
|
console.log(`Bumped SK Azure Tools version to: ${newVersion}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`SK Azure Tools Locked version: ${skAzToolsPackageLock.version}`);
|
||||||
|
|
||||||
|
// Update package.json if --update flag is set
|
||||||
|
// or if the version of @slawek/sk-az-tools in package.json
|
||||||
|
// is different than the version in package-lock.json.
|
||||||
|
if (values.update || skAzToolsPackage.version !== skToolsPackage.version) {
|
||||||
|
console.log(`Updating package.json...`);
|
||||||
skAzToolsPackage.dependencies["@slawek/sk-tools"] = `>=${skToolsPackage.version}`;
|
skAzToolsPackage.dependencies["@slawek/sk-tools"] = `>=${skToolsPackage.version}`;
|
||||||
writeFileSync(skAzToolsPackagePath, JSON.stringify(skAzToolsPackage, null, 4));
|
writeFileSync(skAzToolsPackagePath, JSON.stringify(skAzToolsPackage, null, 4));
|
||||||
// Install and link the updated package
|
// Install and link the updated package
|
||||||
|
|||||||
Reference in New Issue
Block a user