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: additional dirs for cleanDir command #656

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion src/commands/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ export default defineCommand({
args: {
...cwdArgs,
...legacyRootDirArgs,
cleanDir: {
type: 'string',
required: false,
description: 'Additional directories to clean up',
},
},
async run(ctx) {
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir)
const { loadNuxtConfig } = await loadKit(cwd)
const nuxtOptions = await loadNuxtConfig({ cwd, overrides: { dev: true } })
await cleanupNuxtDirs(nuxtOptions.rootDir, nuxtOptions.buildDir)

const customDirs = ctx.args.cleanDir
? ctx.args.cleanDir.split(',').map(dir => resolve(cwd, dir.trim()))
: []

await cleanupNuxtDirs(nuxtOptions.rootDir, nuxtOptions.buildDir, customDirs)
},
})
26 changes: 16 additions & 10 deletions src/utils/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@ interface NuxtProjectManifest {
}
}

export async function cleanupNuxtDirs(rootDir: string, buildDir: string) {
export async function cleanupNuxtDirs(
rootDir: string,
buildDir: string,
customDirs?: string[],
) {
logger.info('Cleaning up generated Nuxt files and caches...')

await rmRecursive(
[
buildDir,
'.output',
'dist',
'node_modules/.vite',
'node_modules/.cache',
].map(dir => resolve(rootDir, dir)),
)
const defaultDirs = [
buildDir,
'.output',
'dist',
'node_modules/.vite',
'node_modules/.cache',
].map(dir => resolve(rootDir, dir))

const dirsToClean = [...defaultDirs, ...(customDirs || [])]

await rmRecursive(dirsToClean)
}

export function nuxtVersionToGitIdentifier(version: string) {
Expand Down
Loading