Skip to content

Commit

Permalink
feat(@142vip/fairy-cli): 支持turbo可选参数,删除turbo构建目录
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdapl committed Jul 17, 2024
1 parent 2f6d3b5 commit 7ba7be9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/fairy-cli/src/core/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CleanUpOptions extends DelOptions {
nuxt?: boolean
midway?: boolean
ignoreTips?: boolean
turbo?: boolean
}

/**
Expand All @@ -41,6 +42,11 @@ export async function execCleanUp(args: CleanUpOptions) {
dirPatterns.push(...generateDirPatterns(['run', 'logs'], args.all))
}

// 删除turbo缓存目录
if (args.turbo) {
dirPatterns.push(...generateDirPatterns('.turbo', args.all))
}

// 删除前,对话框确认
if (!args.ignoreTips) {
const deleted = await confirm({
Expand All @@ -61,6 +67,7 @@ export async function execCleanUp(args: CleanUpOptions) {
const deletedDirs = await deleteAsync(dirPatterns, {
dryRun: args.dryRun,
force: args.force,
dot: true,
})
console.log(deletedDirs)
}
Expand All @@ -77,11 +84,11 @@ function generateDirPatterns(dirName: string | string[], delAll?: boolean) {

if (delAll) {
// 删除程序上下文中所有的该目录
delDirs = delDirs.map(dir => `**/${dir}/*`)
delDirs = delDirs.map(dir => `**/${dir}`)
}
else {
// 只删除该目录
delDirs = delDirs.map(dir => `${dir}/*`)
delDirs = delDirs.map(dir => `${dir}`)
}

return delDirs
Expand Down
1 change: 1 addition & 0 deletions packages/fairy-cli/src/fairy-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ program
.option('--all', '深度删除所有', false)
.option('--ignore-tips', '忽略提示,直接删除', false)
.option('--dry-run', '试运行,不做实际删除操作', false)
.option('--turbo', '删除turbo缓存目录', true)
.action(async (args: CleanUpOptions) => {
await execCleanUp(args)
})
Expand Down

0 comments on commit 7ba7be9

Please sign in to comment.