From e98e0a53398a50652de6b4a51bff462fdde481f0 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Sun, 26 Jan 2025 12:21:39 -0500 Subject: [PATCH] fix: reference error in log handler --- biome.json | 2 +- packages/radashi-helper/bin/radashi-helper.js | 85 +++++++++++-------- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/biome.json b/biome.json index cee41b5..828939a 100644 --- a/biome.json +++ b/biome.json @@ -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": { diff --git a/packages/radashi-helper/bin/radashi-helper.js b/packages/radashi-helper/bin/radashi-helper.js index 408517d..d27a449 100755 --- a/packages/radashi-helper/bin/radashi-helper.js +++ b/packages/radashi-helper/bin/radashi-helper.js @@ -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] + } + }, +)