Skip to content

Commit

Permalink
fix: drop boxen and chalk deps
Browse files Browse the repository at this point in the history
Fixes #230
  • Loading branch information
harlan-zw committed Sep 29, 2024
1 parent 39d853a commit df1029a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 0 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/puppeteer/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -208,7 +208,7 @@ export async function createUnlighthouseWorker(tasks: Record<UnlighthouseTask, T
reportData.push(formatBytes(response.seo.htmlSize))
}
reportData.push(`${monitor().donePercStr}% complete`)
logger.success(`Completed \`${taskName}\` for \`${routeReport.route.path}\`. ${chalk.gray(`(${reportData.join(' ')})`)}`)
logger.success(`Completed \`${taskName}\` for \`${routeReport.route.path}\`. ${colorize('gray', `(${reportData.join(' ')})`)}`)
// run the next task
runTaskIndex(idx + 1)
})
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/unlighthouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from './types'
import { existsSync } from 'node:fs'
import { isAbsolute, join } from 'node:path'
import chalk from 'chalk'
import { colorize } from 'consola/utils'
import { defu } from 'defu'
import fs from 'fs-extra'
import { createHooks } from 'hookable'
Expand Down Expand Up @@ -329,7 +329,7 @@ export async function createUnlighthouse(userConfig: UserConfig, provider?: Prov

if (provider?.name !== 'ci') {
// fancy CLI banner when we start
const label = (name: string) => chalk.bold.magenta(`▸ ${name}:`)
const label = (name: string) => colorize('bold', colorize('magenta', (`▸ ${name}:`)))
let mode = ''
if (resolvedConfig.urls?.length)
mode = 'Manual'
Expand All @@ -347,35 +347,35 @@ 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}`)

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
}
Expand Down
18 changes: 10 additions & 8 deletions packages/core/src/util/cliFormatting.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -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',
Expand All @@ -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',
},
})
}

0 comments on commit df1029a

Please sign in to comment.