Skip to content

Commit 2ea95c5

Browse files
authored
refactor(@142vip/fairy-cli): 基于VipCommanderinitCommand方法,重写fairy工具链 (#494)
1 parent 3fa99c2 commit 2ea95c5

File tree

15 files changed

+63
-68
lines changed

15 files changed

+63
-68
lines changed

packages/fairy-cli/src/commands/changelog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VipCommander } from '@142vip/utils'
22
import { VipExecutor } from '@142vip/utils'
3-
import { CommandEnum, initFairyCliCommand } from '../enums'
3+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
44

55
interface ChangelogOptions {
66
dryRun?: boolean
@@ -19,8 +19,8 @@ async function generateChangelog(args: ChangelogOptions): Promise<void> {
1919
* - 生成CHANGELOG文档
2020
*/
2121
export async function changelogMain(program: VipCommander): Promise<void> {
22-
initFairyCliCommand(program, CommandEnum.CHANGELOG)
23-
.option('--dry-run', '试运行,生成`CHANGELOG`文档', false)
22+
program
23+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.CHANGELOG])
2424
.action(async (args: ChangelogOptions): Promise<void> => {
2525
await generateChangelog(args)
2626
})

packages/fairy-cli/src/commands/clean.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { VipCommander } from '@142vip/utils'
2-
import { VipColor, VipConsole, VipInquirer, vipLogger, VipNodeJS } from '@142vip/utils'
2+
import {
3+
VipColor,
4+
VipConsole,
5+
VipInquirer,
6+
vipLogger,
7+
VipNodeJS,
8+
} from '@142vip/utils'
39
import { deleteAsync } from 'del'
4-
import { CommandEnum, initFairyCliCommand } from '../enums'
10+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
511

612
/**
713
* 删除配置
@@ -129,7 +135,8 @@ async function execCleanUp(args: CleanUpOptions): Promise<void> {
129135
* fairy-cli clean 项目清理
130136
*/
131137
export async function cleanUpMain(program: VipCommander): Promise<void> {
132-
initFairyCliCommand(program, CommandEnum.CLEAN)
138+
program
139+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.CLEAN])
133140
.option('-n,--nuxt', '删除nuxt构建目录,包括.nuxt、.output目录', false)
134141
.option('-d,--dist', '删除dist目录', false)
135142
.option('-m,--midway', '删除midway构建目录', false)
@@ -141,8 +148,6 @@ export async function cleanUpMain(program: VipCommander): Promise<void> {
141148
.option('-f,--force', '强制删除,默认值:false', false)
142149
.option('-a,--all', '深度删除所有', false)
143150
.option('--ignore-tips', '忽略提示,直接删除', false)
144-
.option('--logger', '开启日志追踪模式', false)
145-
.option('--dry-run', '试运行,不做实际删除操作', false)
146151
.action(async (args: CleanUpOptions): Promise<void> => {
147152
await execCleanUp(args)
148153
})

packages/fairy-cli/src/commands/commit.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
VipMonorepo,
1515
VipNodeJS,
1616
} from '@142vip/utils'
17-
import { CommandEnum, initFairyCliCommand } from '../enums'
17+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
1818

1919
const GIT_NULL_SCOPE = '没有范围,那就选这个!!!'
2020

@@ -39,9 +39,8 @@ interface CommitOptions {
3939
* - 基于@142vip/commit-linter
4040
*/
4141
export async function commitMain(program: VipCommander): Promise<void> {
42-
initFairyCliCommand(program, CommandEnum.COMMIT)
43-
.option('--dry-run', '试运行,Git Commit 提交信息', false)
44-
.option('--vip', '@142vip组织专用功能', false)
42+
program
43+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.COMMIT])
4544
.option('--push', '是否要推送到远程', false)
4645
.action(async (vip, args: CommitOptions): Promise<void> => {
4746
if (vip) {

packages/fairy-cli/src/commands/copyright.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { VipCommander } from '@142vip/utils'
22
import { CopyrightFileType, VipCopyright } from '@142vip/copyright'
33
import { VipColor, VipConsole, VipInquirer, vipLogger, VipNodeJS } from '@142vip/utils'
4-
import { CommandEnum, initFairyCliCommand } from '../enums'
4+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
55

66
interface CopyrightOptions {
77
maxLineCount: number
@@ -15,11 +15,10 @@ interface CopyrightOptions {
1515
* - 参考 @142vip/copyright模块
1616
*/
1717
export async function copyrightMain(program: VipCommander): Promise<void> {
18-
initFairyCliCommand(program, CommandEnum.COPYRIGHT)
18+
program
19+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.COPYRIGHT])
1920
.option('-l,--max-line-count', '每页最大行数', value => Number.parseInt(value), 50)
2021
.option('-s,--max-source-count', '扫描的最大代码行数', value => Number.parseInt(value), 2000)
21-
.option('--logger', '开启日志追踪模式', true)
22-
.option('--dry-run', '试运行,生成软著源代码文档', false)
2322
.action(async (args: CopyrightOptions): Promise<void> => {
2423
const copyrightTitle = await VipInquirer.promptInputRequired('申请著作权登记的软件的全称:')
2524
const copyrightVersion = await VipInquirer.promptInputRequired('申请著作权登记的软件的版本号:')

packages/fairy-cli/src/commands/deploy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VipCommander } from '@142vip/utils'
22
import { VipConsole } from '@142vip/utils'
3-
import { CommandEnum, initFairyCliCommand } from '../enums'
3+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
44

55
interface DeployOptions {
66
githubPage: boolean
@@ -19,7 +19,8 @@ function DeployGithubPage() {}
1919
* deploy命令
2020
*/
2121
export async function deployMain(program: VipCommander): Promise<void> {
22-
initFairyCliCommand(program, CommandEnum.DEPLOY)
22+
program
23+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.DEPLOY])
2324
.option('-gh,--github-page', '部署到Github Pages', false)
2425
.action((args: DeployOptions) => {
2526
execDeploy(args)

packages/fairy-cli/src/commands/install.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VipCommander } from '@142vip/utils'
22
import { RegistryAddressEnum, VipInquirer, VipNpm } from '@142vip/utils'
3-
import { CommandEnum, initFairyCliCommand } from '../enums'
3+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
44

55
interface InstallOptions {
66
registry?: string
@@ -32,7 +32,8 @@ async function execInstall(installType: InstallTypeEnum, args: InstallOptions):
3232
* install 命令入口
3333
*/
3434
export async function installMain(program: VipCommander): Promise<void> {
35-
initFairyCliCommand(program, CommandEnum.INSTALL)
35+
program
36+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.INSTALL])
3637
.option('-f,--force', '强制lock文件更新', false)
3738
.option('--registry', `NPM模块的源地址,默认:${RegistryAddressEnum.VIP_NPM_ALIBABA}`, RegistryAddressEnum.VIP_NPM_ALIBABA)
3839
.action(async (args: InstallOptions): Promise<void> => {

packages/fairy-cli/src/commands/lint.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VipCommander } from '@142vip/utils'
22
import { VipExecutor } from '@142vip/utils'
3-
import { CommandEnum, initFairyCliCommand } from '../enums'
3+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
44

55
interface LintOptions {
66
fix: boolean
@@ -19,7 +19,8 @@ async function execLint(args: LintOptions): Promise<void> {
1919
* - 参考:eslint-config模块
2020
*/
2121
export async function lintMain(program: VipCommander): Promise<void> {
22-
initFairyCliCommand(program, CommandEnum.LINT)
22+
program
23+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.LINT])
2324
.option('-c,--config', 'Eslint配置文件路径', false)
2425
.option('-f,--fix', '是否需要基于Eslint规则自动修复', false)
2526
.action(async (args: LintOptions) => {

packages/fairy-cli/src/commands/login.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VipCommander } from '@142vip/utils'
22
import { VipColor, VipConsole, VipDocker, VipInquirer, vipLogger } from '@142vip/utils'
3-
import { CommandEnum, initFairyCliCommand } from '../enums'
3+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
44

55
enum LoginPlatformEnum {
66
DOCKER = 'DOCKER',
@@ -48,7 +48,8 @@ async function loginNpm(): Promise<void> {
4848
* - npx fa login
4949
*/
5050
export async function loginMain(program: VipCommander): Promise<void> {
51-
initFairyCliCommand(program, CommandEnum.LOGIN)
51+
program
52+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.LOGIN])
5253
.action(async () => {
5354
const loginType = await VipInquirer.promptSelect('选择需要登录的平台:', Object.values(LoginPlatformEnum))
5455
if (loginType === LoginPlatformEnum.DOCKER) {

packages/fairy-cli/src/commands/publish.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
VipInquirer,
88
vipLogger,
99
} from '@142vip/utils'
10-
import { CommandEnum, initFairyCliCommand } from '../enums'
10+
import { CLI_COMMAND_DETAIL, CommandEnum } from '../enums'
1111

1212
interface PublishOptions {
1313
registry?: string
@@ -41,9 +41,9 @@ async function publishNpm(args: PublishOptions): Promise<void> {
4141
* - npx fa publish
4242
*/
4343
export async function publishMain(program: VipCommander): Promise<void> {
44-
initFairyCliCommand(program, CommandEnum.PUBLISH)
44+
program
45+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.PUBLISH])
4546
.option('-r,--registry', `NPM包的仓库地址,默认: ${RegistryAddressEnum.NPM}`, RegistryAddressEnum.NPM)
46-
.option('-dry,--dry-run', '试运行,不会进行发布', false)
4747
.action(async (args: PublishOptions): Promise<void> => {
4848
await publishNpm(args)
4949
})

packages/fairy-cli/src/commands/release.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { VersionBumpOptions } from '@142vip/release-version'
22
import type { VipCommander } from '@142vip/utils'
3-
import { printPreCheckRelease, releaseMonorepoPkg, releaseRoot } from '@142vip/fairy-cli'
3+
import {
4+
CLI_COMMAND_DETAIL,
5+
printPreCheckRelease,
6+
releaseMonorepoPkg,
7+
releaseRoot,
8+
} from '@142vip/fairy-cli'
49
import { versionBump } from '@142vip/release-version'
510
import {
611
DEFAULT_RELEASE_ROOT_NAME,
@@ -14,7 +19,7 @@ import {
1419
VipPackageJSON,
1520
} from '@142vip/utils'
1621
import { name } from '../../package.json'
17-
import { CommandEnum, initFairyCliCommand } from '../enums'
22+
import { CommandEnum } from '../enums'
1823

1924
interface ReleaseOptions extends Pick<VersionBumpOptions, 'preid' | 'tag' | 'commit' | 'push' | 'all' | 'execute'> {
2025
package?: string
@@ -47,7 +52,6 @@ async function execNormalRelease(args: ReleaseOptions): Promise<void> {
4752

4853
// 指定文件更新版本
4954
await versionBump({
50-
files: [],
5155
...args.preid ? { preid: args.preid } : { perid: 'alpha' },
5256
// 是否需要标记
5357
...args.tag ? { tag: args.tag } : {},
@@ -99,7 +103,8 @@ async function execVipRelease(args: VipReleaseExtraOptions): Promise<void> {
99103
* 功能迭代主功能
100104
*/
101105
export async function releaseMain(program: VipCommander): Promise<void> {
102-
initFairyCliCommand(program, CommandEnum.RELEASE)
106+
program
107+
.initCommand(CLI_COMMAND_DETAIL[CommandEnum.RELEASE])
103108
.option('--push', '推送到Git远程', true)
104109
.option('--preid <preid>', 'ID for prerelease')
105110
.option('--commit <msg>', '提交信息', false)
@@ -110,7 +115,6 @@ export async function releaseMain(program: VipCommander): Promise<void> {
110115
.option('--package <package>', '指定需要发布的包')
111116
.option('--branch <branch>', '指定分支进行发布', 'next')
112117
.option('--check-release', '发布仓库主版本时,校验Monorepo中子模块版本', false)
113-
.option('--vip', '@142vip组织专用功能', false)
114118
.option('-F, --filter <filter>', '模块的路径,例如:"./package/*"', (value: string, previous: string[]) => {
115119
if (!value)
116120
return [value]

0 commit comments

Comments
 (0)