|
2 | 2 |
|
3 | 3 | import fs from 'node:fs/promises'; |
4 | 4 | import path from 'node:path'; |
| 5 | +import { parseArgs } from 'node:util'; |
5 | 6 | import { $, chalk } from 'zx'; |
6 | 7 |
|
7 | | -// Exit when error |
8 | 8 | $.verbose = false; |
9 | 9 |
|
10 | | -const args = process.argv.slice(2); |
11 | | -const bumpTypeArgs = args.find((arg) => arg.startsWith('--type=')); |
12 | | - |
13 | 10 | async function getCurrentVersion() { |
14 | 11 | const packageJsonPath = path.join( |
15 | 12 | process.cwd(), |
@@ -56,20 +53,33 @@ async function main() { |
56 | 53 | const currentVersion = await getCurrentVersion(); |
57 | 54 | console.log(chalk.blue(`Current version: ${currentVersion}`)); |
58 | 55 |
|
59 | | - // 2. Determine bump type |
60 | | - const bumpType = bumpTypeArgs ? bumpTypeArgs.split('=')[1] : 'patch'; |
| 56 | + // 2. Determine bump type and next release version |
| 57 | + const options = { |
| 58 | + type: { |
| 59 | + type: 'string', |
| 60 | + short: 't', |
| 61 | + default: 'patch', |
| 62 | + }, |
| 63 | + }; |
| 64 | + const args = process.argv.slice(3); |
| 65 | + const { values } = parseArgs({ args, options }); |
| 66 | + |
| 67 | + const bumpType = values.type; |
61 | 68 |
|
62 | 69 | if (!['major', 'minor', 'patch'].includes(bumpType)) { |
63 | 70 | console.error('Invalid bump type. Please select major, minor, or patch.'); |
64 | 71 | process.exit(1); |
65 | 72 | } |
66 | 73 |
|
| 74 | + console.log(chalk.blue(`Bump type: ${bumpType}`)); |
| 75 | + |
67 | 76 | const nextVersion = await getNextVersion(currentVersion, bumpType); |
68 | | - const branchName = `release-v${nextVersion}`; |
| 77 | + console.log(chalk.blue(`Next version: ${nextVersion}`)); |
69 | 78 |
|
| 79 | + // 3. Create and switch to new branch |
| 80 | + const branchName = `release-v${nextVersion}`; |
70 | 81 | console.log(chalk.blue(`Creating branch: ${branchName}`)); |
71 | 82 |
|
72 | | - // 3. Create and switch to new branch |
73 | 83 | await $`git checkout -b ${branchName}`; |
74 | 84 |
|
75 | 85 | // 4. Generate changeset file |
|
0 commit comments