diff --git a/package-lock.json b/package-lock.json index 0dab210..5682352 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@slawek/sk-az-tools", - "version": "0.4.2", + "version": "0.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@slawek/sk-az-tools", - "version": "0.4.2", + "version": "0.4.3", "license": "MIT", "dependencies": { "@azure/identity": "^4.13.0", diff --git a/package.json b/package.json index 55f5b6d..d6a0a5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@slawek/sk-az-tools", - "version": "0.4.2", + "version": "0.4.3", "type": "module", "files": [ "dist", @@ -10,6 +10,7 @@ "scripts": { "build": "rm -rf dist && tsc && chmod +x dist/cli.js", "create-pca": "node dist/create-pca.js", + "bump-patch": "node scripts/bump-patch.mjs", "make-deps": "node scripts/make-mermaid-func-deps.mjs", "clean": "rm -rf dist" }, @@ -25,7 +26,8 @@ "@slawek/sk-tools": ">=0.1.0", "azure-devops-node-api": "^15.1.2", "minimatch": "^10.1.2", - "open": "^10.1.0" + "open": "^10.1.0", + "semver": "^7.7.2" }, "devDependencies": { "@types/node": ">=24.0.0", diff --git a/scripts/bump-patch.mjs b/scripts/bump-patch.mjs new file mode 100755 index 0000000..34bbea9 --- /dev/null +++ b/scripts/bump-patch.mjs @@ -0,0 +1,48 @@ +#!/usr/bin/env node + +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import semver from 'semver'; + +function bump(fileName) { + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + + const filePath = path.resolve(__dirname, '..', fileName); + + if (!bump.nextVersion) { + const packageJsonPath = path.resolve(__dirname, '../package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); + const version = packageJson.version; + + if (typeof version !== 'string') { + throw new Error('package.json does not contain a string "version" field.'); + } + + const nextVersion = semver.inc(version, 'patch'); + + if (!nextVersion) { + throw new Error(`Unsupported semver format: "${version}"`); + } + + bump.nextVersion = nextVersion; + } + + if (!fs.existsSync(filePath)) { + throw new Error(`File not found: ${filePath}`); + } + + const json = JSON.parse(fs.readFileSync(filePath, 'utf8')); + json.version = bump.nextVersion; + + if (path.basename(filePath) === 'package-lock.json' && json.packages?.['']) { + json.packages[''].version = bump.nextVersion; + } + + fs.writeFileSync(filePath, `${JSON.stringify(json, null, 4)}\n`, 'utf8'); + console.log(`Bumped version in ${fileName} to ${bump.nextVersion}`); +} + +bump('package.json'); +bump('package-lock.json');