From 72f03659c4785f42ea6ceeb8e660fe6e87dd82e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20UB?= <22903142+adrian-ub@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:58:39 -0500 Subject: [PATCH] feat: change chalk by picocolors --- package.json | 2 +- pnpm-lock.yaml | 6 +++--- src/commands/add.ts | 6 +++--- src/commands/diff.ts | 12 ++++++------ src/commands/init.ts | 8 ++++---- src/utils/logger.ts | 18 +++++++++--------- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index ccdb0c2..741c6e1 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ }, "dependencies": { "@antfu/ni": "^0.23.0", - "chalk": "5.2.0", "citty": "^0.1.6", "cosmiconfig": "^8.1.3", "diff": "^5.1.0", @@ -64,6 +63,7 @@ "lodash.template": "^4.5.0", "node-fetch": "^3.3.0", "ora": "^6.1.2", + "picocolors": "^1.1.0", "prompts": "^2.4.2", "ts-morph": "^18.0.0", "tsconfig-paths": "^4.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ffe4337..b52577f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,9 +11,6 @@ importers: '@antfu/ni': specifier: ^0.23.0 version: 0.23.0 - chalk: - specifier: 5.2.0 - version: 5.2.0 citty: specifier: ^0.1.6 version: 0.1.6 @@ -44,6 +41,9 @@ importers: ora: specifier: ^6.1.2 version: 6.3.1 + picocolors: + specifier: ^1.1.0 + version: 1.1.0 prompts: specifier: ^2.4.2 version: 2.4.2 diff --git a/src/commands/add.ts b/src/commands/add.ts index 500f29c..36a788b 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -2,10 +2,10 @@ import { existsSync, promises as fs } from 'node:fs' import path from 'node:path' import process from 'node:process' -import chalk from 'chalk' import { defineCommand } from 'citty' import { execa } from 'execa' import ora from 'ora' +import pc from 'picocolors' import prompts from 'prompts' import { z } from 'zod' @@ -89,7 +89,7 @@ export const add = defineCommand({ const config = await getConfig(cwd) if (!config) { logger.warn( - `Configuration is missing. Please run ${chalk.green( + `Configuration is missing. Please run ${pc.green( `init`, )} to create a components.json file.`, ) @@ -179,7 +179,7 @@ export const add = defineCommand({ if (!overwrite) { logger.info( - `Skipped ${item.name}. To overwrite, run with the ${chalk.green( + `Skipped ${item.name}. To overwrite, run with the ${pc.green( '--overwrite', )} flag.`, ) diff --git a/src/commands/diff.ts b/src/commands/diff.ts index d0bf2f4..a9f9b9a 100644 --- a/src/commands/diff.ts +++ b/src/commands/diff.ts @@ -2,9 +2,9 @@ import { existsSync, promises as fs } from 'node:fs' import path from 'node:path' import process from 'node:process' -import chalk from 'chalk' import { defineCommand } from 'citty' import { type Change, diffLines } from 'diff' +import pc from 'picocolors' import { z } from 'zod' import { getConfig } from '../utils/get-config' @@ -66,7 +66,7 @@ export const diff = defineCommand({ const config = await getConfig(cwd) if (!config) { logger.warn( - `Configuration is missing. Please run ${chalk.green( + `Configuration is missing. Please run ${pc.green( `init`, )} to create a components.json file.`, ) @@ -116,7 +116,7 @@ export const diff = defineCommand({ } logger.break() logger.info( - `Run ${chalk.green(`diff `)} to see the changes.`, + `Run ${pc.green(`diff `)} to see the changes.`, ) process.exit(0) } @@ -128,7 +128,7 @@ export const diff = defineCommand({ if (!component) { logger.error( - `The component ${chalk.green(options.component)} does not exist.`, + `The component ${pc.green(options.component)} does not exist.`, ) process.exit(1) } @@ -202,10 +202,10 @@ async function printDiff(diff: Change[]): Promise { diff.forEach((part) => { if (part) { if (part.added) { - return process.stdout.write(chalk.green(part.value)) + return process.stdout.write(pc.green(part.value)) } if (part.removed) { - return process.stdout.write(chalk.red(part.value)) + return process.stdout.write(pc.red(part.value)) } return process.stdout.write(part.value) diff --git a/src/commands/init.ts b/src/commands/init.ts index 0734839..f8c6181 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -2,11 +2,11 @@ import { existsSync, promises as fs } from 'node:fs' import path from 'node:path' import process from 'node:process' -import chalk from 'chalk' import { defineCommand } from 'citty' import { execa } from 'execa' import template from 'lodash.template' import ora from 'ora' +import pc from 'picocolors' import prompts from 'prompts' import { z } from 'zod' @@ -101,7 +101,7 @@ export const init = defineCommand({ logger.info('') logger.info( - `${chalk.green( + `${pc.green( 'Success!', )} Project initialization completed. You may now add components.`, ) @@ -118,7 +118,7 @@ export async function promptForConfig( defaultConfig: Config | null = null, skip = false, ): Promise<{ style: string, tailwind: { config: string, css: string, baseColor: string, cssVariables: boolean, prefix?: string | undefined }, aliases: { components: string, utils: string, ui?: string | undefined }, resolvedPaths: { components: string, utils: string, ui: string, tailwindConfig: string, tailwindCss: string }, $schema?: string | undefined }> { - const highlight = (text: string): string => chalk.cyan(text) + const highlight = (text: string): string => pc.cyan(text) const styles = await getRegistryStyles() const baseColors = await getRegistryBaseColors() @@ -234,7 +234,7 @@ export async function promptForMinimalConfig( defaultConfig: Config, defaults = false, ): Promise<{ style: string, tailwind: { config: string, css: string, baseColor: string, cssVariables: boolean, prefix?: string | undefined }, aliases: { components: string, utils: string, ui?: string | undefined }, resolvedPaths: { components: string, utils: string, ui: string, tailwindConfig: string, tailwindCss: string }, $schema?: string | undefined }> { - const highlight = (text: string): string => chalk.cyan(text) + const highlight = (text: string): string => pc.cyan(text) let style = defaultConfig.style let baseColor = defaultConfig.tailwind.baseColor let cssVariables = defaultConfig.tailwind.cssVariables diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 5a6b924..8d666f5 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,18 +1,18 @@ /* eslint-disable no-console */ -import chalk from 'chalk' +import pc from 'picocolors' export const logger = { - error(...args: unknown[]) { - console.log(chalk.red(...args)) + error(args: string) { + console.log(pc.red(args)) }, - warn(...args: unknown[]) { - console.log(chalk.yellow(...args)) + warn(args: string) { + console.log(pc.yellow(args)) }, - info(...args: unknown[]) { - console.log(chalk.cyan(...args)) + info(args: string) { + console.log(pc.cyan(args)) }, - success(...args: unknown[]) { - console.log(chalk.green(...args)) + success(args: string) { + console.log(pc.green(args)) }, break() { console.log('')