Skip to content

Commit

Permalink
feat: additional dirs for cleanDir command
Browse files Browse the repository at this point in the history
  • Loading branch information
kubicodes committed Jan 8, 2025
1 parent f116a97 commit 08c77cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/commands/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ export default defineCommand({
args: {
...cwdArgs,
...legacyRootDirArgs,
cleanDir: {
type: 'string',
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()))

Check failure on line 27 in src/commands/cleanup.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Unexpected parentheses around single function argument having a body with no curly braces

Check failure on line 27 in src/commands/cleanup.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Unexpected parentheses around single function argument having a body with no curly braces
: []

await cleanupNuxtDirs(nuxtOptions.rootDir, nuxtOptions.buildDir, customDirs)
},
})
32 changes: 19 additions & 13 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[]

Check failure on line 24 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Missing trailing comma

Check failure on line 24 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Missing trailing comma
) {
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))

Check failure on line 34 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Unexpected parentheses around single function argument having a body with no curly braces

Check failure on line 34 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Unexpected parentheses around single function argument having a body with no curly braces

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

await rmRecursive(dirsToClean)
}

export function nuxtVersionToGitIdentifier(version: string) {
Expand Down Expand Up @@ -57,7 +63,7 @@ function resolveNuxtManifest(nuxt: Nuxt): NuxtProjectManifest {
}

export async function writeNuxtManifest(
nuxt: Nuxt,
nuxt: Nuxt

Check failure on line 66 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Missing trailing comma

Check failure on line 66 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Missing trailing comma
): Promise<NuxtProjectManifest> {
const manifest = resolveNuxtManifest(nuxt)
const manifestPath = resolve(nuxt.options.buildDir, 'nuxt.json')
Expand All @@ -67,12 +73,12 @@ export async function writeNuxtManifest(
}

export async function loadNuxtManifest(
buildDir: string,
buildDir: string

Check failure on line 76 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Missing trailing comma

Check failure on line 76 in src/utils/nuxt.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Missing trailing comma
): Promise<NuxtProjectManifest | null> {
const manifestPath = resolve(buildDir, 'nuxt.json')
const manifest: NuxtProjectManifest | null = await fsp
.readFile(manifestPath, 'utf-8')
.then(data => JSON.parse(data) as NuxtProjectManifest)
.then((data) => JSON.parse(data) as NuxtProjectManifest)
.catch(() => null)
return manifest
}

0 comments on commit 08c77cf

Please sign in to comment.