Skip to content

Commit

Permalink
feat(@142vip/utils): 移除prompt相关依赖,使用@142vip/utils模块,修改release、`…
Browse files Browse the repository at this point in the history
…clean`命令交互
  • Loading branch information
mmdapl committed Dec 12, 2024
1 parent bf7963c commit 6b6356f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 243 deletions.
6 changes: 3 additions & 3 deletions packages/fairy-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ Options:
-n,--nuxt 删除nuxt构建目录,包括.nuxt、.output目录 (default: false)
-d,--dist 删除dist目录 (default: false)
-m,--midway 删除midway构建目录 (default: false)
--turbo 删除turbo缓存目录 (default: false)
--vite 删除vite缓存目录 (default: false)
--deps 删除node_modules目录 (default: false)
-f,--force 强制删除,默认值:false (default: false)
--all 深度删除所有 (default: false)
--ignore-tips 忽略提示,直接删除 (default: false)
--dry-run 试运行,不做实际删除操作 (default: false)
--turbo 删除turbo缓存目录 (default: false)
--vite 删除vite缓存目录 (default: false)
--deps 删除node_modules目录 (default: false)
-h, --help display help for command
```

Expand Down
2 changes: 0 additions & 2 deletions packages/fairy-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@
"dependencies": {
"@142vip/release-version": "workspace:*",
"@142vip/utils": "workspace:*",
"@inquirer/prompts": "^5.3.8",
"commander": "^12.1.0",
"del": "^7.1.0",
"js-yaml": "^4.1.0",
"node-fetch": "^3.3.2",
"turbo": "^2.1.1"
},
"devDependencies": {
"@types/inquirer": "^9.0.7",
"@types/js-yaml": "^4.0.9"
},
"publishConfig": {
Expand Down
13 changes: 5 additions & 8 deletions packages/fairy-cli/src/commands/clean.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as process from 'node:process'
import confirm from '@inquirer/confirm'
import { deleteAsync } from 'del'
import type { Command } from 'commander'
import { promptConfirm } from '@142vip/utils'
import { CliCommandEnum } from '../shared'

/**
Expand Down Expand Up @@ -67,10 +67,7 @@ async function execCleanUp(args: CleanUpOptions) {

// 删除前,对话框确认
if (!args.ignoreTips) {
const deleted = await confirm({
message: '是否需要删除?',
default: true,
})
const deleted = await promptConfirm('是否需要删除?', true)

if (!deleted) {
// 不删除,非0退出
Expand Down Expand Up @@ -122,13 +119,13 @@ export async function cleanUpMain(program: Command) {
.option('-n,--nuxt', '删除nuxt构建目录,包括.nuxt、.output目录', false)
.option('-d,--dist', '删除dist目录', false)
.option('-m,--midway', '删除midway构建目录', false)
.option('--turbo', '删除turbo缓存目录', false)
.option('--vite', '删除vite缓存目录', false)
.option('--deps', '删除node_modules目录', false)
.option('-f,--force', '强制删除,默认值:false', false)
.option('--all', '深度删除所有', false)
.option('--ignore-tips', '忽略提示,直接删除', false)
.option('--dry-run', '试运行,不做实际删除操作', false)
.option('--turbo', '删除turbo缓存目录', false)
.option('--vite', '删除vite缓存目录', false)
.option('--deps', '删除node_modules目录', false)
.action(async (args: CleanUpOptions) => {
await execCleanUp(args)
})
Expand Down
39 changes: 7 additions & 32 deletions packages/fairy-cli/src/commands/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,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 { confirm, select } from '@inquirer/prompts'
import { vipColor } from '@142vip/utils'
import { promptConfirm, promptList, vipColor } from '@142vip/utils'
import {
CliCommandEnum,
getBranchName,
Expand All @@ -14,16 +13,6 @@ import {
releaseRoot,
} from '../shared'

// export interface ReleaseOptions {
// preid: string
// commit?: boolean | string
// tag?: boolean | string
// push?: boolean
// all?: boolean
// execute?: string
// package?: string
// }

interface ReleaseOptions extends Pick<VersionBumpOptions, 'preid' | 'tag' | 'commit' | 'push' | 'all' | 'execute'> {
package?: string
}
Expand All @@ -49,7 +38,6 @@ const defaultRepoName = 'main'

/**
* 版本发布
* @param args
*/
async function execNormalRelease(args: ReleaseOptions) {
// 指定包
Expand Down Expand Up @@ -95,24 +83,14 @@ function execVipRelease(args: VipReleaseExtraOptions) {
process.exit(0)
}

// 对话框
select({
message: `选择需要使用${vipColor.red('Release')}命令发布的模块名称:`,
choices: [
defaultRepoName,
...packageNames,
].map(name => ({
name,
value: name,
})),
// 不循环滚动
loop: false,
})
const choices = [
defaultRepoName,
...packageNames,
]
promptList(choices, `选择需要使用${vipColor.red('Release')}命令发布的模块名称:`)
.then(async (packageName) => {
// 确认框
const isRelease = await confirm({
message: `将对模块${vipColor.green(packageName)}进行版本迭代,是否继续操作?`,
})
const isRelease = await promptConfirm(`将对模块${vipColor.green(packageName)}进行版本迭代,是否继续操作?`)

if (!isRelease) {
console.log(vipColor.yellow('用户取消发布操作!!'))
Expand All @@ -135,7 +113,6 @@ function execVipRelease(args: VipReleaseExtraOptions) {

/**
* 功能迭代主功能
* @param program
*/
export async function releaseMain(program: Command) {
program
Expand All @@ -158,8 +135,6 @@ export async function releaseMain(program: Command) {
}, [])
.option('--vip', '是否为@142vip组织专用功能', false)
.action(async (args: ReleaseOptions & VipReleaseExtraOptions) => {
// console.log(CliCommandEnum.RELEASE, args)

// 发布时校验分支
if (args.branch != null) {
const branchName = getBranchName()
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"devDependencies": {
"@types/inquirer": "^9.0.7"
}
}
Loading

0 comments on commit 6b6356f

Please sign in to comment.