diff --git a/packages/core/package.json b/packages/core/package.json index 10b0210..5b5be99 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -52,8 +52,6 @@ "@unrouted/preset-api": "^0.6.0", "@unrouted/preset-node": "^0.6.0", "axios": "^1.7.7", - "boxen": "^8.0.1", - "chalk": "^5.3.0", "cheerio": "1.0.0", "chrome-launcher": "^1.1.2", "consola": "^3.2.3", diff --git a/packages/core/src/puppeteer/worker.ts b/packages/core/src/puppeteer/worker.ts index 44896fb..3381736 100644 --- a/packages/core/src/puppeteer/worker.ts +++ b/packages/core/src/puppeteer/worker.ts @@ -10,7 +10,7 @@ import type { } from '../types' import fs from 'node:fs' import { join } from 'node:path' -import chalk from 'chalk' +import { colorize } from 'consola/utils' import { get, sortBy, uniqBy } from 'lodash-es' import { matchPathToRule } from '../discovery' import { useLogger } from '../logger' @@ -208,7 +208,7 @@ export async function createUnlighthouseWorker(tasks: Record chalk.bold.magenta(`▸ ${name}:`) + const label = (name: string) => colorize('bold', colorize('magenta', (`▸ ${name}:`))) let mode = '' if (resolvedConfig.urls?.length) mode = 'Manual' @@ -347,21 +347,21 @@ export async function createUnlighthouse(userConfig: UserConfig, provider?: Prov catch (e) {} const title = [ - `⛵ ${chalk.bold.blueBright(AppName)} ${chalk.dim(`${provider?.name} @ v${version}`)}`, + `⛵ ${colorize('bold', colorize('blueBright', AppName))} ${colorize('dim', `${provider?.name} @ v${version}`)}`, ] if (Number(latestTag.replace('v', '').replace('.', '')) > Number(version.replace('.', ''))) { title.push(...[ '', `🎉 New version ${latestTag} available! Use the latest:`, - chalk.gray(` > ${chalk.underline(`npx unlighthouse@^${latestTag} --site ${resolvedConfig.site}`)}`), + colorize('gray', ` > ${colorize('underline', `npx unlighthouse@^${latestTag} --site ${resolvedConfig.site}`)}`), ]) } title.push(...[ '', `${label('Scanning')} ${resolvedConfig.site}`, - `${label('Route Discovery')} ${mode} ${ctx.routes.length > 1 ? (chalk.dim(`${ctx.routes.length} initial URLs`)) : ''}`, + `${label('Route Discovery')} ${mode} ${ctx.routes.length > 1 ? (colorize('dim', (`${ctx.routes.length} initial URLs`))) : ''}`, '', - chalk.dim(' 💖 Like Unlighthouse? Support the development: https://github.com/sponsors/harlan-zw'), + colorize('dim', (' 💖 Like Unlighthouse? Support the development: https://github.com/sponsors/harlan-zw')), ]) if (ctx.routeDefinitions?.length) title.push(`${label('Route Definitions')} ${ctx.routeDefinitions.length}`) @@ -369,13 +369,13 @@ export async function createUnlighthouse(userConfig: UserConfig, provider?: Prov process.stdout.write(successBox( // messages [ - ctx.runtimeSettings.clientUrl ? chalk.whiteBright(`Report: ${ctx.runtimeSettings.clientUrl}`) : '', + ctx.runtimeSettings.clientUrl ? colorize('whiteBright', `Report: ${ctx.runtimeSettings.clientUrl}`) : '', ].join('\n'), // title title.join('\n'), )) if (existsSync(join(ctx.runtimeSettings.generatedClientPath, 'reports', 'lighthouse.json')) && ctx.resolvedConfig.cache) - logger.info(`Restoring reports from cache. ${chalk.gray('You can disable this behavior by passing --no-cache.')}`) + logger.info(`Restoring reports from cache. ${colorize('gray', 'You can disable this behavior by passing --no-cache.')}`) } return ctx } diff --git a/packages/core/src/util/cliFormatting.ts b/packages/core/src/util/cliFormatting.ts index 70e5b1f..153370c 100644 --- a/packages/core/src/util/cliFormatting.ts +++ b/packages/core/src/util/cliFormatting.ts @@ -1,5 +1,5 @@ -import boxen from 'boxen' -import chalk from 'chalk' +import type { BoxOpts } from 'consola/utils' +import { colorize, box as makeBox } from 'consola/utils' import wrapAnsi from 'wrap-ansi' /** @@ -30,11 +30,11 @@ export function foldLines(string: string, spaces: number, firstLineSpaces: numbe return indentLines(wrapAnsi(string, charsPerLine), spaces, firstLineSpaces) } -export function box(message: string, title: string, options: any) { - return `${boxen([ - title || chalk.white('Nuxt Message'), +export function box(message: string, title: string, options?: BoxOpts) { + return `${makeBox([ + title, '', - chalk.white(foldLines(message, 0, 0, maxCharsPerLine())), + colorize('white', foldLines(message, 0, 0, maxCharsPerLine())), ].join('\n'), Object.assign({ borderColor: 'white', borderStyle: 'round', @@ -44,7 +44,9 @@ export function box(message: string, title: string, options: any) { } export function successBox(message: string, title: string) { - return box(message, title || chalk.green('✔ Nuxt Success'), { - borderColor: 'green', + return box(message, title, { + style: { + borderColor: 'green', + }, }) }