From d7fb01737b66f704ca3976159ed552d10e97ff16 Mon Sep 17 00:00:00 2001 From: nyxb Date: Sat, 6 May 2023 21:01:24 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20refactor(nyxr.ts):=20remove=20un?= =?UTF-8?q?used=20import=20and=20replace=20console.error=20with=20consolji?= =?UTF-8?q?.error=20=E2=9C=A8=20feat(detect.ts):=20add=20consolji=20loggin?= =?UTF-8?q?g=20and=20replace=20console.warn=20with=20consolji.warn=20?= =?UTF-8?q?=F0=9F=94=A5=20refactor(fs.ts):=20remove=20unused=20import=20an?= =?UTF-8?q?d=20replace=20console.warn=20with=20consolji.warn=20?= =?UTF-8?q?=F0=9F=94=A5=20refactor(gradient.ts):=20remove=20entire=20file?= =?UTF-8?q?=20as=20it=20is=20no=20longer=20used=20=F0=9F=94=A5=20refactor(?= =?UTF-8?q?runner.ts):=20remove=20eslint-disable=20and=20replace=20console?= =?UTF-8?q?.log=20with=20consolji.log=20The=20changes=20made=20in=20this?= =?UTF-8?q?=20commit=20are=20mostly=20related=20to=20replacing=20console?= =?UTF-8?q?=20logging=20with=20consolji=20logging,=20which=20provides=20a?= =?UTF-8?q?=20more=20consistent=20and=20customizable=20logging=20experienc?= =?UTF-8?q?e.=20Unused=20imports=20were=20also=20removed,=20and=20the=20gr?= =?UTF-8?q?adient.ts=20file=20was=20removed=20as=20it=20was=20no=20longer?= =?UTF-8?q?=20used.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/nyxr.ts | 6 +++--- src/detect.ts | 7 ++++--- src/fs.ts | 3 ++- src/gradient.ts | 36 ------------------------------------ src/runner.ts | 26 +++++++++++++------------- 5 files changed, 22 insertions(+), 56 deletions(-) delete mode 100644 src/gradient.ts diff --git a/src/commands/nyxr.ts b/src/commands/nyxr.ts index 5f1a23a..33daaab 100644 --- a/src/commands/nyxr.ts +++ b/src/commands/nyxr.ts @@ -1,7 +1,7 @@ -/* eslint-disable unused-imports/no-unused-vars */ import c from 'kleur' import { Fzf } from 'fzf' import * as tyck from '@tyck/prompts' +import { consolji } from 'consolji' import { dump, load } from '../storage' import { parseNyxr } from '../parse' import { getPackageJSON } from '../fs' @@ -18,7 +18,7 @@ runCli(async (agent, args, ctx) => { if (args[0] === '-') { if (!storage.lastRunCommand) { - console.error('No last command found') + consolji.error('No last command found') process.exit(1) } args[0] = storage.lastRunCommand @@ -56,7 +56,7 @@ runCli(async (agent, args, ctx) => { description: limitText(description, terminalColumns - 15), })) - const fzf = new Fzf(raw, { + const _fzf = new Fzf(raw, { selector: item => `${item.key} ${item.description}`, casing: 'case-insensitive', }) diff --git a/src/detect.ts b/src/detect.ts index 07ca8d6..81b00d0 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -4,6 +4,7 @@ import { execaCommand } from 'execa' import { findUp } from 'find-up' import terminalLink from 'terminal-link' import * as tyck from '@tyck/prompts' +import { consolji } from 'consolji' import type { Agent } from './agents' import { AGENTS, INSTALL_PAGE, LOCKS } from './agents' import { cmdExists } from './utils' @@ -40,7 +41,7 @@ export async function detect({ autoInstall, cwd }: DetectOptions = {}) { else if (name in AGENTS) agent = name else - console.warn('[nyxi] Unknown packageManager:', pkg.packageManager) + consolji.warn('[nyxi] Unknown packageManager:', pkg.packageManager) } } catch {} @@ -53,7 +54,7 @@ export async function detect({ autoInstall, cwd }: DetectOptions = {}) { // If no package manager is detected, prompt the user to choose one if (!agent) { const defaultAgent = await getDefaultAgent() - if (defaultAgent === 'prompt') { + if ((defaultAgent as any) === 'prompt') { agent = await tyck.select({ message: 'Please choose a package manager:', options: [ @@ -71,7 +72,7 @@ export async function detect({ autoInstall, cwd }: DetectOptions = {}) { // auto install if (agent && !cmdExists(agent.split('@')[0])) { if (!autoInstall) { - console.warn(`[nyxi] Detected ${agent} but it doesn't seem to be installed.\n`) + consolji.warn(`[nyxi] Detected ${agent} but it doesn't seem to be installed.\n`) if (process.env.CI) process.exit(1) diff --git a/src/fs.ts b/src/fs.ts index 9554cab..1e78dfd 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -1,5 +1,6 @@ import { resolve } from 'node:path' import fs from 'node:fs' +import { consolji } from 'consolji' export function getPackageJSON(cwd = process.cwd()): any { const path = resolve(cwd, 'package.json') @@ -11,7 +12,7 @@ export function getPackageJSON(cwd = process.cwd()): any { return data } catch (e) { - console.warn('Failed to parse package.json') + consolji.warn('Failed to parse package.json') process.exit(0) } } diff --git a/src/gradient.ts b/src/gradient.ts deleted file mode 100644 index a2a2f06..0000000 --- a/src/gradient.ts +++ /dev/null @@ -1,36 +0,0 @@ -import chalk from 'chalk' -import ora from 'ora' -import gradient from 'gradient-string' - -const GREEN = '#14F195' -const PURPLE = '#9945FF' -const RED = '#ed4245' -const YELLOW = '#fee75c' - -export const nyxGradient = gradient(GREEN, PURPLE) -export const nyxGreen = chalk.hex(GREEN) -export const nyxPurple = chalk.hex(PURPLE) -export const nyxRed = chalk.hex(RED) -export const yellow = chalk.hex(YELLOW) - -export function nyxLoader(text: string) { - return ora({ - text, - spinner: { - frames: [' ', nyxGreen('> '), nyxGreen('>> '), nyxGreen('>>>')], - }, - }) -} - -export function info(...args: any[]) { - // eslint-disable-next-line no-console - console.log(nyxGreen.bold('>>>'), ...args) -} - -export function error(...args: any[]) { - console.error(nyxRed.bold('>>>'), ...args) -} - -export function warn(...args: any[]) { - console.error(yellow.bold('>>>'), ...args) -} diff --git a/src/runner.ts b/src/runner.ts index 5997dd5..e082b63 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -1,8 +1,8 @@ -/* eslint-disable no-console */ import { resolve } from 'node:path' import * as tyck from '@tyck/prompts' import { execaCommand } from 'execa' import c from 'kleur' +import { consolji } from 'consolji' import { version } from '../package.json' import type { Agent } from './agents' import { agents } from './agents' @@ -28,7 +28,7 @@ export async function runCli(fn: Runner, options: DetectOptions = {}) { } catch (error) { if (error instanceof UnsupportedCommand) - console.log(c.red(`\u2717 ${error.message}`)) + consolji.log(c.red(`\u2717 ${error.message}`)) process.exit(1) } @@ -43,21 +43,21 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = { let command if (args.length === 1 && (args[0] === '--version' || args[0] === '-v')) { - console.log(`@nyxb/nyxi v${version}`) + consolji.log(`@nyxb/nyxi v${version}`) return } if (args.length === 1 && ['-h', '--help'].includes(args[0])) { const dash = c.dim('-') - console.log(c.green(c.bold('@nyxb/nyxi')) + c.dim(` use the right package manager v${version}\n`)) - console.log(`nyxi ${dash} install`) - console.log(`nyxr ${dash} run`) - console.log(`nyxlx ${dash} execute`) - console.log(`nyxu ${dash} upgrade`) - console.log(`nyxun ${dash} uninstall`) - console.log(`nyxci ${dash} clean install`) - console.log(`nyxa ${dash} agent alias`) - console.log(c.yellow('\ncheck https://github.com/nyxb/nyxi for more documentation.')) + consolji.log(c.green(c.bold('@nyxb/nyxi')) + c.dim(` use the right package manager v${version}\n`)) + consolji.log(`nyxi ${dash} install`) + consolji.log(`nyxr ${dash} run`) + consolji.log(`nyxlx ${dash} execute`) + consolji.log(`nyxu ${dash} upgrade`) + consolji.log(`nyxun ${dash} uninstall`) + consolji.log(`nyxci ${dash} clean install`) + consolji.log(`nyxa ${dash} agent alias`) + consolji.log(c.yellow('\ncheck https://github.com/nyxb/nyxi for more documentation.')) return } @@ -102,7 +102,7 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = { command = voltaPrefix.concat(' ').concat(command) if (debug) { - console.log(command) + consolji.log(command) return }