|
23 | 23 | import { existsSync, readFileSync } from 'node:fs'; |
24 | 24 | import { writeFile } from 'node:fs/promises'; |
25 | 25 | import { resolve } from 'node:path'; |
| 26 | +import { parseArgs } from 'node:util'; |
26 | 27 |
|
27 | 28 | import handlebars from 'handlebars'; |
28 | 29 | import { format } from 'prettier'; |
@@ -58,10 +59,20 @@ const ERRORS = { |
58 | 59 | new Error(`Failed to write Release post: Reason: ${reason}`), |
59 | 60 | }; |
60 | 61 |
|
| 62 | +const parsedArgs = parseArgs({ |
| 63 | + options: { |
| 64 | + force: { |
| 65 | + type: 'boolean', |
| 66 | + short: 'f', |
| 67 | + }, |
| 68 | + }, |
| 69 | + allowPositionals: true, |
| 70 | +}); |
| 71 | + |
61 | 72 | const ARGS = { |
62 | 73 | CURRENT_PATH: process.argv[1], |
63 | | - SPECIFIC_VERSION: process.argv[2] && process.argv[2].replace('--force', ''), |
64 | | - SHOULD_FORCE: (process.argv[3] || process.argv[2]) === '--force', |
| 74 | + SPECIFIC_VERSION: parsedArgs.positionals[0]?.replace(/^v/, ''), |
| 75 | + SHOULD_FORCE: Boolean(parsedArgs.values.force), |
65 | 76 | }; |
66 | 77 |
|
67 | 78 | // this allows us to get the current module working directory |
@@ -262,9 +273,6 @@ if (import.meta.url.startsWith('file:')) { |
262 | 273 | .then(renderPost) |
263 | 274 | .then(formatPost) |
264 | 275 | .then(writeToFile) |
265 | | - .then( |
266 | | - filepath => console.log('Release post created:', filepath), |
267 | | - error => console.error('Some error occurred here!', error.stack) |
268 | | - ); |
| 276 | + .then(filepath => console.log('Release post created:', filepath)); |
269 | 277 | } |
270 | 278 | } |
0 commit comments