Skip to content

Commit

Permalink
feat: 🚀 Support npx passing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 17, 2024
1 parent aa3ce02 commit a632d4c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@ function runCommand() {
.command('$0', description, () => {}, async (argv) => {
p.intro(`${capitalizeFirstLetter(name)}: ${description}. Supported by Viarotel v${version}`)

const inputDir = await p.text({
message: 'Enter the TypeScript project directory to convert:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
})
const { _: io, $0, ...cleantsOptions } = argv

const outputDir = await p.text({
message: 'Enter the output project directory:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
initialValue: './',
})
let inputDir = io[0]
let outputDir = io[1]

if (!inputDir) {
inputDir = await p.text({
message: 'Enter the TypeScript project directory to convert:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
})
}

if (!outputDir) {
outputDir = await p.text({
message: 'Enter the output project directory:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
initialValue: './',
})
}

const replaceInternalImports = await p.confirm({
message: 'Automatically replace the suffix of inline imports?',
Expand All @@ -40,7 +49,7 @@ function runCommand() {
spinner.text = `${stage}: ${progress.toFixed(2)}%`
}

const cleants = new Cleants(inputDir, outputDir, { progressCallback })
const cleants = new Cleants(inputDir, outputDir, { progressCallback, ...cleantsOptions })

await cleants.convert()

Expand Down

0 comments on commit a632d4c

Please sign in to comment.