Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@142vip/utils): 移除prompt相关依赖,使用@142vip/utils模块,修改releaseclean命令交互 #199

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -61,16 +61,13 @@
}

if (dirPatterns.length === 0) {
console.log('删除规则为空,不做删除操作处理,请传入有效参数!!')

Check warning on line 64 in packages/fairy-cli/src/commands/clean.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
process.exit(1)
}

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

if (!deleted) {
// 不删除,非0退出
Expand All @@ -79,7 +76,7 @@
}

// 需要删除的目录
console.log('删除规则:', dirPatterns)

Check warning on line 79 in packages/fairy-cli/src/commands/clean.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement

// 删除
const deletedDirs = await deleteAsync(dirPatterns, {
Expand All @@ -87,7 +84,7 @@
force: args.force,
dot: true,
})
console.log(deletedDirs)

Check warning on line 87 in packages/fairy-cli/src/commands/clean.ts

View workflow job for this annotation

GitHub Actions / 基础编译构建

Unexpected console statement
}

function generateDirPatterns(dirName: string | string[], delAll?: boolean) {
Expand Down Expand Up @@ -122,13 +119,13 @@
.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
Loading