|
20 | 20 | /* eslint-disable @typescript-eslint/naming-convention */ |
21 | 21 |
|
22 | 22 | import { argv, exit } from 'node:process'; |
| 23 | +import { parseArgs } from 'node:util'; |
23 | 24 | import * as shell from 'shelljs'; |
24 | 25 | import * as path from 'path'; |
25 | | -import { Command } from 'commander'; |
26 | 26 | import { logger } from './logger'; |
27 | 27 | import * as fs from 'fs'; |
28 | 28 | import * as ejs from 'ejs'; |
29 | 29 |
|
30 | | -const program = new Command(); |
31 | | - |
32 | 30 | interface Commit { |
33 | 31 | hash: string; |
34 | 32 | author: string; |
@@ -151,28 +149,74 @@ function commitAuthorAllowed(commit: Commit, authorFilter: string): boolean { |
151 | 149 | * @returns void |
152 | 150 | */ |
153 | 151 | export default function main(_args: string[], workingDir: string) { |
154 | | - program |
155 | | - .description('Generate changelog report for two branches of git repository') |
156 | | - .version('0.0.1', '-v, --version') |
157 | | - .usage('changelog [options]') |
158 | | - .option('-r, --range <range>', 'Commit range, e.g. origin/master..develop', 'origin/master..develop') |
159 | | - .option('-d, --dir <dir>', 'Working directory (default: working directory)') |
160 | | - .option('-m, --max <number>', 'Limit the number of commits to output') |
161 | | - .option('-o, --output <dir>', 'Output directory, will use console output if not defined') |
162 | | - .option('--skip <number>', 'Skip number commits before starting to show the commit output') |
163 | | - .option('-f, --format <format>', 'Output format (md, html)', 'md') |
164 | | - .option('-e --exclude <string>', 'Exclude authors from the output, comma-delimited list') |
165 | | - .parse(argv); |
166 | | - |
167 | 152 | if (argv.includes('-h') || argv.includes('--help')) { |
168 | | - program.outputHelp(); |
| 153 | + console.log(` |
| 154 | +Usage: changelog [options] |
| 155 | +
|
| 156 | +Generate changelog report for two branches of git repository |
| 157 | +
|
| 158 | +Options: |
| 159 | + -v, --version Output the version number |
| 160 | + -r, --range <range> Commit range, e.g. origin/master..develop (default: "origin/master..develop") |
| 161 | + -d, --dir <dir> Working directory (default: working directory) |
| 162 | + -m, --max <number> Limit the number of commits to output |
| 163 | + -o, --output <dir> Output directory, will use console output if not defined |
| 164 | + --skip <number> Skip number commits before starting to show the commit output |
| 165 | + -f, --format <format> Output format (md, html) (default: "md") |
| 166 | + -e, --exclude <string> Exclude authors from the output, comma-delimited list |
| 167 | + -h, --help Display help for command |
| 168 | +`); |
169 | 169 | exit(0); |
170 | 170 | } |
171 | 171 |
|
172 | | - const options = program.opts(); |
| 172 | + if (argv.includes('-v') || argv.includes('--version')) { |
| 173 | + console.log('0.0.1'); |
| 174 | + exit(0); |
| 175 | + } |
| 176 | + |
| 177 | + const { values } = parseArgs({ |
| 178 | + args: argv.slice(2), |
| 179 | + options: { |
| 180 | + range: { |
| 181 | + type: 'string', |
| 182 | + short: 'r', |
| 183 | + default: 'origin/master..develop' |
| 184 | + }, |
| 185 | + dir: { |
| 186 | + type: 'string', |
| 187 | + short: 'd' |
| 188 | + }, |
| 189 | + max: { |
| 190 | + type: 'string', |
| 191 | + short: 'm' |
| 192 | + }, |
| 193 | + output: { |
| 194 | + type: 'string', |
| 195 | + short: 'o' |
| 196 | + }, |
| 197 | + skip: { |
| 198 | + type: 'string' |
| 199 | + }, |
| 200 | + format: { |
| 201 | + type: 'string', |
| 202 | + short: 'f', |
| 203 | + default: 'md' |
| 204 | + }, |
| 205 | + exclude: { |
| 206 | + type: 'string', |
| 207 | + short: 'e' |
| 208 | + } |
| 209 | + }, |
| 210 | + allowPositionals: true |
| 211 | + }); |
173 | 212 |
|
174 | | - const dir = path.resolve(options.dir || workingDir); |
175 | | - const { range, skip, max, format, output, exclude } = options; |
| 213 | + const dir = path.resolve((values.dir as string) || workingDir); |
| 214 | + const range = values.range as string; |
| 215 | + const skip = values.skip ? parseInt(values.skip as string, 10) : undefined; |
| 216 | + const max = values.max ? parseInt(values.max as string, 10) : undefined; |
| 217 | + const format = values.format as string; |
| 218 | + const output = values.output as string | undefined; |
| 219 | + const exclude = values.exclude as string | undefined; |
176 | 220 |
|
177 | 221 | const remote = getRemote(dir); |
178 | 222 |
|
|
0 commit comments