Skip to content

Commit

Permalink
feat: optimize cli use (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe committed Mar 26, 2024
1 parent 4fad8a4 commit 617ded9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* eslint-disable no-console */

import { default as gradientString } from 'gradient-string';
import { default as _gradientString } from 'gradient-string';

export const defaultColors = ['#FF1CF7', '#B249F8'] as const;

export const gradientString = _gradientString;

export class Logger {
constructor() {}
Expand All @@ -22,12 +26,10 @@ export class Logger {
}

static gradient(
conent: string | number | boolean,
content: string | number | boolean,
options?: { colors?: tinycolor.ColorInput[] }
) {
const defaultColors = ['#FF1CF7', '#B249F8'] as const;

this.log(gradientString(...(options?.colors ?? defaultColors))(String(conent)));
this.log(gradientString(...(options?.colors ?? defaultColors))(String(content)));
}

static newLine(lines?: number) {
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Logger } from './logger';

export function getCommandDescAndLog(log: string, desc: string) {
Logger.gradient(log);

return desc;
}
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { default as chalk } from 'chalk';
import { Command } from 'commander';

import { Logger } from '@helpers/logger';
import { getCommandDescAndLog } from '@helpers/utils';

import pkg from '../package.json';

Expand All @@ -11,14 +12,18 @@ import { NextUIComponents } from './constants/component';
const nextui = new Command();

nextui
.name(chalk.bold(Logger.gradient('NextUI CLI')))
.description(pkg.description)
.name('nextui')
.usage('[command]')
.description(
`${chalk.blue(
getCommandDescAndLog(
`\nNextUI CLI\n\n${pkg.description}\n`,
'NextUI ---- 🚀 Beautiful, fast and modern React UI library.'
)
)}`
)
.version(pkg.version, '-v, --version', 'Output the current version')
.helpOption('-h, --help', 'Display help for command')
.option('-n, --use-npm', 'Explicitly tell the CLI to install the dependencies using npm')
.option('-y, --use-yarn', 'Explicitly tell the CLI to install the dependencies using yarn')
.option('-p, --use-pnpm', 'Explicitly tell the CLI to install the dependencies using pnpm')
.option('-b, --use-bun', 'Explicitly tell the CLI to install the dependencies using bun')
.allowUnknownOption()
.action(action);

Expand Down

0 comments on commit 617ded9

Please sign in to comment.