diff --git a/src/commands/cleanup.ts b/src/commands/cleanup.ts index aeb0debf..1e7005f5 100644 --- a/src/commands/cleanup.ts +++ b/src/commands/cleanup.ts @@ -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) }, }) diff --git a/src/utils/nuxt.ts b/src/utils/nuxt.ts index c0b5e29a..eaf541c2 100644 --- a/src/utils/nuxt.ts +++ b/src/utils/nuxt.ts @@ -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) {