Skip to content

Commit

Permalink
chore: replace kleur with yoctocolors (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Aug 13, 2024
1 parent 4ad537b commit a0df9fa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"fs-extra": "^11.2.0",
"fzf": "^0.5.2",
"ini": "^4.1.3",
"kleur": "^4.1.5",
"yoctocolors": "^2.1.1",
"taze": "^0.16.3",

Check failure on line 68 in package.json

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected object keys to be in ascending order. 'taze' should be before 'yoctocolors'

Check failure on line 68 in package.json

View workflow job for this annotation

GitHub Actions / build (lts/*)

Expected object keys to be in ascending order. 'taze' should be before 'yoctocolors'
"terminal-link": "^3.0.0",
"tinyglobby": "^0.2.2",
Expand Down
12 changes: 9 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/commands/ni.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import process from 'node:process'
import type { Choice } from '@posva/prompts'
import prompts from '@posva/prompts'
import { Fzf } from 'fzf'
import c from 'kleur'
import { yellow } from 'yoctocolors'
import { parseNi } from '../parse'
import { runCli } from '../runner'
import { exclude } from '../utils'
Expand Down Expand Up @@ -74,7 +74,7 @@ runCli(async (agent, args, ctx) => {
const { mode } = await prompts({
type: 'select',
name: 'mode',
message: `install ${c.yellow(dependency.name)} as`,
message: `install ${yellow(dependency.name)} as`,
choices: [
{
title: 'prod',
Expand Down
4 changes: 2 additions & 2 deletions src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'node:process'
import type { Choice } from '@posva/prompts'
import c from 'kleur'
import { blue } from 'yoctocolors'
import { formatPackageWithUrl } from './utils'

export interface NpmPackage {
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function fetchNpmPackages(pattern: string): Promise<Choice[]> {

return result.objects.map(({ package: pkg }) => ({
title: formatPackageWithUrl(
`${pkg.name.padEnd(30, ' ')} ${c.blue(`v${pkg.version}`)}`,
`${pkg.name.padEnd(30, ' ')} ${blue(`v${pkg.version}`)}`,
pkg.links.repository ?? pkg.links.npm,
terminalColumns,
),
Expand Down
18 changes: 9 additions & 9 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import process from 'node:process'
import prompts from '@posva/prompts'
import type { Options as TinyExecOptions } from 'tinyexec'
import { x } from 'tinyexec'
import c from 'kleur'
import { blue, bold, cyan, dim, green, red, yellow } from 'yoctocolors'
import type { Agent } from 'package-manager-detector/agents'
import { AGENTS } from 'package-manager-detector/agents'
import { version } from '../package.json'
Expand Down Expand Up @@ -33,7 +33,7 @@ export async function runCli(fn: Runner, options: DetectOptions & { args?: strin
}
catch (error) {
if (error instanceof UnsupportedCommand && !options.programmatic)
console.log(c.red(`\u2717 ${error.message}`))
console.log(red(`\u2717 ${error.message}`))

if (!options.programmatic)
process.exit(1)
Expand Down Expand Up @@ -99,15 +99,15 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
nodeOptions: { cwd },
})

console.log(`@antfu/ni ${c.cyan(`v${version}`)}`)
console.log(`node ${c.green(await nodeVersionPromise)}`)
console.log(`@antfu/ni ${cyan(`v${version}`)}`)
console.log(`node ${green(await nodeVersionPromise)}`)
const [agent, agentVersion] = await Promise.all([agentPromise, agentVersionPromise])
if (agent)
console.log(`${agent.padEnd(10)} ${c.blue(agentVersion)}`)
console.log(`${agent.padEnd(10)} ${blue(agentVersion)}`)
else
console.log('agent no lock file')
const [globalAgent, globalAgentVersion] = await Promise.all([globalAgentPromise, globalAgentVersionPromise])
console.log(`${(`${globalAgent} -g`).padEnd(10)} ${c.blue(globalAgentVersion)}`)
console.log(`${(`${globalAgent} -g`).padEnd(10)} ${blue(globalAgentVersion)}`)
return
}

Expand All @@ -117,8 +117,8 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
}

if (args.length === 1 && ['-h', '--help'].includes(args[0])) {
const dash = c.dim('-')
console.log(c.green(c.bold('@antfu/ni')) + c.dim(` use the right package manager v${version}\n`))
const dash = dim('-')
console.log(green(bold('@antfu/ni')) + dim(` use the right package manager v${version}\n`))
console.log(`ni ${dash} install`)
console.log(`nr ${dash} run`)
console.log(`nlx ${dash} execute`)
Expand All @@ -128,7 +128,7 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
console.log(`na ${dash} agent alias`)
console.log(`ni -v ${dash} show used agent`)
console.log(`ni -i ${dash} interactive package management`)
console.log(c.yellow('\ncheck https://github.com/antfu/ni for more documentation.'))
console.log(yellow('\ncheck https://github.com/antfu/ni for more documentation.'))
return
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { existsSync, promises as fs } from 'node:fs'
import type { Buffer } from 'node:buffer'
import process from 'node:process'
import which from 'which'
import c from 'kleur'
import { dim } from 'yoctocolors'
import terminalLink from 'terminal-link'

export const CLI_TEMP_DIR = join(os.tmpdir(), 'antfu-ni')
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function writeFileSafe(
export function limitText(text: string, maxWidth: number) {
if (text.length <= maxWidth)
return text
return `${text.slice(0, maxWidth)}${c.dim('…')}`
return `${text.slice(0, maxWidth)}${dim('…')}`
}

export function formatPackageWithUrl(pkg: string, url?: string, limits = 80) {
Expand All @@ -108,7 +108,7 @@ export function formatPackageWithUrl(pkg: string, url?: string, limits = 80) {
{
fallback: (_, url) => (pkg.length + url.length > limits)
? pkg
: pkg + c.dim(` - ${url}`),
: pkg + dim(` - ${url}`),
},
)
: pkg
Expand Down

0 comments on commit a0df9fa

Please sign in to comment.