diff --git a/scripts/bump-patch.mjs b/scripts/bump-patch.mjs index 301ee19..5cb96cb 100755 --- a/scripts/bump-patch.mjs +++ b/scripts/bump-patch.mjs @@ -2,8 +2,8 @@ import fs from 'node:fs'; import path from 'node:path'; -import { parseArgs } from 'node:util'; import semver from 'semver'; +import { Command, Option } from 'commander'; function bump(fileName, version, releaseType = 'patch') { const filePath = path.resolve(process.cwd(), fileName); @@ -32,17 +32,13 @@ function bump(fileName, version, releaseType = 'patch') { return nextVersion; } -const { values } = parseArgs({ - options: { - 'release-type': { type: 'string', short: 'r' }, - }, - strict: true, - allowPositionals: false, -}); +const program = new Command(); +program + .name('bump-patch') + .description('Bump the version in package.json') + .addOption(new Option('-r, --release-type ', 'Release type (major, minor, patch)', 'patch') + .choices('release-type', ['major', 'minor', 'patch']) + ) + .parse(process.argv); -const releaseType = values['release-type'] ?? 'patch'; -if (!['major', 'minor', 'patch'].includes(releaseType)) { - throw new Error(`Invalid --release-type '${releaseType}'. Allowed: major, minor, patch.`); -} - -bump('package.json', undefined, releaseType); +bump('package.json', undefined, program.opts().releaseType);