Skip to content

Commit

Permalink
🔥 refactor(nyxr.ts): remove unused import and replace console.error w…
Browse files Browse the repository at this point in the history
…ith consolji.error

✨ feat(detect.ts): add consolji logging and replace console.warn with consolji.warn
🔥 refactor(fs.ts): remove unused import and replace console.warn with consolji.warn
🔥 refactor(gradient.ts): remove entire file as it is no longer used
🔥 refactor(runner.ts): remove eslint-disable and replace console.log with consolji.log
The changes made in this commit are mostly related to replacing console logging with consolji logging, which provides a more consistent and customizable logging experience. Unused imports were also removed, and the gradient.ts file was removed as it was no longer used.
  • Loading branch information
nyxb committed May 6, 2023
1 parent 5ac7584 commit d7fb017
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/commands/nyxr.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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',
})
Expand Down
7 changes: 4 additions & 3 deletions src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {}
Expand All @@ -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: [
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/fs.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)
}
}
Expand Down
36 changes: 0 additions & 36 deletions src/gradient.ts

This file was deleted.

26 changes: 13 additions & 13 deletions src/runner.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d7fb017

Please sign in to comment.