-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
046b1a9
commit e98e0a5
Showing
2 changed files
with
49 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,55 @@ | ||
#!/usr/bin/env node | ||
import('../dist/cli.js').then(async ({ run, setPromptHandler, setLogHandler, setStdio, EarlyExitError, RadashiError }) => { | ||
setLogHandler(log) | ||
setPromptHandler(prompt) | ||
setStdio('inherit') | ||
import('../dist/cli.js').then( | ||
async ({ | ||
run, | ||
setPromptHandler, | ||
setLogHandler, | ||
setStdio, | ||
EarlyExitError, | ||
RadashiError, | ||
}) => { | ||
const { yellow } = await import('kleur/colors') | ||
|
||
try { | ||
await run(process.argv) | ||
} catch (error) { | ||
if (error instanceof EarlyExitError) { | ||
process.exit(0) | ||
setLogHandler(log) | ||
setPromptHandler(prompt) | ||
setStdio('inherit') | ||
|
||
try { | ||
await run(process.argv) | ||
} catch (error) { | ||
if (error instanceof EarlyExitError) { | ||
process.exit(0) | ||
} | ||
if (error instanceof RadashiError) { | ||
console.error(error.message) | ||
} else { | ||
console.error(error) | ||
} | ||
process.exit(1) | ||
} | ||
if (error instanceof RadashiError) { | ||
console.error(error.message) | ||
} else { | ||
console.error(error) | ||
|
||
function log(type, msg, ...args) { | ||
switch (type) { | ||
case 'info': | ||
console.log(msg, ...args) | ||
break | ||
case 'warn': | ||
console.warn(yellow('ATTN') + ' ' + msg, ...args) | ||
break | ||
case 'error': | ||
console.error(msg, ...args) | ||
break | ||
} | ||
} | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
function log(type, msg, ...args) { | ||
switch(type) { | ||
case 'info': | ||
console.log(msg, ...args) | ||
break | ||
case 'warn': | ||
console.warn(yellow('ATTN') + ' ' + msg, ...args) | ||
break | ||
case 'error': | ||
console.error(msg, ...args) | ||
break | ||
} | ||
} | ||
async function prompt(options) { | ||
const { default: prompts } = await import('prompts') | ||
|
||
async function prompt(options) { | ||
const { default: prompts } = await import('prompts') | ||
// Print a blank line to separate the prompt from the output. | ||
console.log() | ||
|
||
// Print a blank line to separate the prompt from the output. | ||
console.log() | ||
|
||
const answer = await prompts(options) | ||
return answer[options.name] | ||
} | ||
const answer = await prompts(options) | ||
return answer[options.name] | ||
} | ||
}, | ||
) |