Skip to content

Commit

Permalink
fix: reference error in log handler
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jan 26, 2025
1 parent 046b1a9 commit e98e0a5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"extends": ["@radashi-org/biome-config"],
"files": {
"include": ["**/*.mjs"]
"include": ["**/*.mjs", "**/*.js"]
},
"linter": {
"rules": {
Expand Down
85 changes: 48 additions & 37 deletions packages/radashi-helper/bin/radashi-helper.js
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]
}
},
)

0 comments on commit e98e0a5

Please sign in to comment.