Skip to content

Commit

Permalink
Merge pull request #201 from 142vip/feat/fairy-cli-commander
Browse files Browse the repository at this point in the history
feat(@142vip/fairy-cli): 移除`commander`模块,使用`VipCommander`进行终端`cli`定义
  • Loading branch information
mmdapl authored Dec 12, 2024
2 parents 10185ae + 22f00ea commit cedfe11
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 44 deletions.
1 change: 0 additions & 1 deletion packages/fairy-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"dependencies": {
"@142vip/release-version": "workspace:*",
"@142vip/utils": "workspace:*",
"commander": "^12.1.0",
"del": "^7.1.0",
"js-yaml": "^4.1.0",
"node-fetch": "^3.3.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { commandStandardExecutor } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

Expand All @@ -10,7 +10,7 @@ async function generateChangelog(args: ChangelogOptions) {
await commandStandardExecutor(`npx changelog ${args.dry ? '--dry' : ''}`)
}

export async function changelogMain(program: Command) {
export async function changelogMain(program: VipCommander) {
program
.command(CliCommandEnum.CHANGELOG)
.description('快速使用@142vip/changelog模块')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/clean.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as process from 'node:process'
import { deleteAsync } from 'del'
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { promptConfirm } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

Expand Down Expand Up @@ -112,7 +112,7 @@ function generateDirPatterns(dirName: string | string[], delAll?: boolean) {
/**
* fairy-cli clean 项目清理
*/
export async function cleanUpMain(program: Command) {
export async function cleanUpMain(program: VipCommander) {
program
.command(CliCommandEnum.CLEAN)
.description('清除开发、构建等环境下的无用目录')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

interface DeployOptions {
Expand All @@ -19,7 +19,7 @@ function DeployGithubPage() {}
*
* @param program
*/
export async function deployMain(program: Command) {
export async function deployMain(program: VipCommander) {
program
.command(CliCommandEnum.DEPLOY)
.description('项目部署')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { commandStandardExecutor } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

Expand Down Expand Up @@ -32,7 +32,7 @@ async function execInstall(args: InstallOptions) {
* install 命令入口
* @param program
*/
export async function installMain(program: Command) {
export async function installMain(program: VipCommander) {
program
.command(CliCommandEnum.INSTALL)
.aliases(['i', 'add'])
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { commandStandardExecutor } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

Expand All @@ -24,7 +24,7 @@ function doCodeLint(args: { fix: boolean }) {
* 基于Eslint校验
* - 参考:eslint-config模块
*/
export async function lintMain(program: Command) {
export async function lintMain(program: VipCommander) {
program
.command(CliCommandEnum.LINT)
.description('根据Eslint检查代码风格,支持代码格式化')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import process from 'node:process'
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { commandStandardExecutor } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

Expand Down Expand Up @@ -78,7 +78,7 @@ async function loginNpm(args: NpmOptions) {
/**
* login命令入口
*/
export async function loginMain(program: Command) {
export async function loginMain(program: VipCommander) {
program
.command(`${CliCommandEnum.LOGIN} <platform>`)
.description('登录远程平台,支持Docker和Npm')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { execCommand } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

Expand Down Expand Up @@ -59,7 +59,7 @@ async function publishNpm(args: NpmOptions) {
/**
* publish 命令入口
*/
export async function publishMain(program: Command) {
export async function publishMain(program: VipCommander) {
program
.command(CliCommandEnum.PUBLISH)
.description('publish to remote platform,eg. Docker Image & Npm Package')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/release.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import process from 'node:process'
import type { VersionBumpOptions } from '@142vip/release-version'
import { versionBump } from '@142vip/release-version'
import type { Command } from 'commander'
import type { VipCommander } from '@142vip/utils'
import { promptConfirm, promptList, vipColor } from '@142vip/utils'
import {
CliCommandEnum,
Expand Down Expand Up @@ -114,7 +114,7 @@ function execVipRelease(args: VipReleaseExtraOptions) {
/**
* 功能迭代主功能
*/
export async function releaseMain(program: Command) {
export async function releaseMain(program: VipCommander) {
program
.command(CliCommandEnum.RELEASE)
.description('release npm version')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/sync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'node:process'
import type { Command } from 'commander'
import fetch from 'node-fetch'
import type { VipCommander } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

/**
Expand Down Expand Up @@ -97,7 +97,7 @@ async function execSync(packageNames: string[]) {
/**
* sync命令入口
*/
export async function syncMain(program: Command): Promise<void> {
export async function syncMain(program: VipCommander): Promise<void> {
program
.command(CliCommandEnum.SYNC)
.description('同步npm仓库的模块包到cnpm仓库')
Expand Down
4 changes: 2 additions & 2 deletions packages/fairy-cli/src/commands/turbopack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fsSync from 'node:fs'
import * as process from 'node:process'
import type { VipCommander } from '@142vip/utils'
import { execShell } from '@142vip/utils'
import type { Command } from 'commander'
import { CliCommandEnum } from '../shared'

interface TurboPackOptions {
Expand Down Expand Up @@ -39,7 +39,7 @@ function getFilterRepo(repoNames: string[]) {
/**
* turbo命令入口
*/
export async function turboPackMain(program: Command) {
export async function turboPackMain(program: VipCommander) {
program
.command(CliCommandEnum.TURBO)
.description('TurboPack工具命令')
Expand Down
6 changes: 2 additions & 4 deletions packages/fairy-cli/src/fairy-cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as process from 'node:process'
import { Command } from 'commander'
import { VipCommander } from '@142vip/utils'
import { name, version } from '../package.json'

import {
Expand All @@ -16,9 +16,7 @@ import {
} from './commands'

export async function fairyCliMain() {
const program = new Command(name)
// 查看版本
program.version(version, '-v --version')
const program = new VipCommander(name, version)

// fairy-cli create 创建 todo

Expand Down
20 changes: 1 addition & 19 deletions pnpm-lock.yaml

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

0 comments on commit cedfe11

Please sign in to comment.