Skip to content

Commit

Permalink
fix(crwrsca): Stop using parseArgs (#11112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jul 29, 2024
1 parent 5c61ee0 commit 0987dc3
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions packages/create-redwood-rsc-app/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// TODO: Really need to fix this, but I want to get this stuff merged first
// before I spend more time on it.
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import { parseArgs } from 'node:util'

export interface Config {
installationDir: string
verbose: boolean
Expand All @@ -14,32 +9,39 @@ export function initConfig() {
verbose: false,
}

const { positionals, values } = parseArgs({
options: {
help: {
short: 'h',
type: 'boolean',
},
verbose: {
short: 'v',
type: 'boolean',
},
version: {
short: 'V',
type: 'boolean',
},
},
strict: false,
})

if (values.verbose) {
const args = {
verbose: false,
help: false,
version: false,
}

// Skipping the first two arguments, which are the path to the node executable
// and the path to the script being executed, we find the first argument that
// does not start with a dash. This is the installation directory.
const installationDir = process.argv
.slice(2)
.find((arg) => !arg.startsWith('-'))

if (process.argv.includes('--verbose') || process.argv.includes('-v')) {
args.verbose = true
}

if (process.argv.includes('--help') || process.argv.includes('-h')) {
args.help = true
}

if (process.argv.includes('--version') || process.argv.includes('-V')) {
args.version = true
}

if (args.verbose) {
console.log('Parsed command line arguments:')
console.log(' arguments:', values)
console.log(' positionals:', positionals)
console.log(' arguments:', args)
console.log(' installationDir:', installationDir)
}

config.verbose = !!values.verbose
config.installationDir = positionals[0]
config.verbose = !!args.verbose
config.installationDir = installationDir ?? ''

return config
}

0 comments on commit 0987dc3

Please sign in to comment.