### Globally Install and Run next-cleaner Source: https://github.com/bhaskarrijal/next-cleaner/blob/main/README.md Install the next-cleaner package globally using npm, pnpm, or bun. Once installed globally, the `next-cleaner` command can be executed from any directory. ```bash npm install -g next-cleaner # or pnpm add -g next-cleaner # or bun add -g next-cleaner next-cleaner ``` -------------------------------- ### next-cleaner CLI Usage Examples (Bash) Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Provides examples of how to use the next-cleaner command-line interface (CLI) to perform various cleanup operations on a Next.js project. It covers common scenarios like quick cleanup, full cleanup, dry runs, and selective cleaning using different flags. ```bash # Flag reference with examples npx next-cleaner --help # Options: # -y, --yes Skip confirmation prompts # --no-public Skip cleaning public folder # --no-favicon Skip deleting favicon # --no-page Skip replacing page.tsx # --css Also clean globals.css # --layout Also clean layout.tsx # --all Clean everything (including css and layout) # -d, --dry-run Preview changes without modifying files # Common usage patterns: # 1. Quick cleanup with defaults (most common) npx next-cleaner -y # 2. Full cleanup for fresh start npx next-cleaner --all -y # 3. Preview before making changes npx next-cleaner --all --dry-run # 4. Cleanup but keep favicon npx next-cleaner -y --no-favicon # 5. Only reset CSS and layout (keep everything else) npx next-cleaner -y --no-public --no-favicon --no-page --css --layout # 6. Global installation for repeated use npm install -g next-cleaner next-cleaner -y # Run in any Next.js project ``` -------------------------------- ### ProjectInfo Interface Definition (TypeScript) Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Defines the structure for ProjectInfo, which holds details about a detected Next.js project, including its router type, directory paths, and configuration like TypeScript usage. This interface is crucial for understanding the project's setup before applying cleanup operations. ```typescript import type { ProjectInfo } from 'next-cleaner'; // ProjectInfo structure interface ProjectInfo { cwd: string; // Current working directory router: 'app' | 'pages' | 'unknown'; // Detected router type srcDir: boolean; // Whether src/ directory is used typescript: boolean; // Whether TypeScript is used appDir: string | null; // Path to app directory (e.g., 'src/app') pagesDir: string | null; // Path to pages directory (e.g., 'pages') publicDir: string; // Path to public directory ('public') } // Example usage with type checking function logProjectInfo(info: ProjectInfo): void { console.log(`Router: ${info.router}`); console.log(`Uses src/: ${info.srcDir}`); console.log(`TypeScript: ${info.typescript}`); console.log(`App dir: ${info.appDir ?? 'N/A'}`); console.log(`Pages dir: ${info.pagesDir ?? 'N/A'}`); } ``` -------------------------------- ### Basic Interactive CLI Usage for next-cleaner Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Demonstrates how to run the next-cleaner CLI in interactive mode using npx, pnpm, or bun. It shows the detection process and the interactive prompt for selecting files to clean, followed by the output of the cleanup operation. ```bash # Using npx (no installation required) npx next-cleaner # Using pnpm pnpm dlx next-cleaner # Using bun bunx next-cleaner # Output: # ℹ Detected Next.js project (App Router, src/) # ? What would you like to clean? # ◉ Public folder SVGs (next.svg, vercel.svg, etc.) # ◉ favicon.ico # ◉ page.tsx (replace with blank component) # ◯ globals.css (reset to minimal) # ◯ layout.tsx (remove Geist fonts) # ? Ready to clean 3 item(s). Proceed? (Y/n) # → Removing SVG files from public/ # deleted /my-app/public/next.svg # deleted /my-app/public/vercel.svg # → Removing favicon.ico # deleted /my-app/app/favicon.ico # → Replacing page.tsx # replaced /my-app/app/page.tsx # ✓ Cleanup complete! ``` -------------------------------- ### next-cleaner Command-Line Options Source: https://github.com/bhaskarrijal/next-cleaner/blob/main/README.md Demonstrates various ways to run next-cleaner with different options. These commands allow for interactive mode, skipping prompts, cleaning all optional items, previewing changes, and excluding specific cleaning actions. ```bash # Interactive mode (default) npx next-cleaner # Skip prompts, use defaults npx next-cleaner -y # Clean everything including CSS and layout npx next-cleaner --all # Preview changes without modifying files npx next-cleaner --dry-run # Skip specific items npx next-cleaner -y --no-public --no-favicon # Only clean optional items npx next-cleaner -y --css --layout ``` -------------------------------- ### CLI Usage - Basic Interactive Mode Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Run next-cleaner in interactive mode to select files for cleanup using a checkbox interface. ```APIDOC ## CLI Usage - Basic Interactive Mode Run the cleaner in interactive mode to select which files to clean with a checkbox interface. ```bash # Using npx (no installation required) npx next-cleaner # Using pnpm pnpm dlx next-cleaner # Using bun bunx next-cleaner ``` ### Example Output ``` # ℹ Detected Next.js project (App Router, src/) # ? What would you like to clean? # ◉ Public folder SVGs (next.svg, vercel.svg, etc.) # ◉ favicon.ico # ◉ page.tsx (replace with blank component) # ◯ globals.css (reset to minimal) # ◯ layout.tsx (remove Geist fonts) # ? Ready to clean 3 item(s). Proceed? (Y/n) # → Removing SVG files from public/ # deleted /my-app/public/next.svg # deleted /my-app/public/vercel.svg # → Removing favicon.ico # deleted /my-app/app/favicon.ico # → Replacing page.tsx # replaced /my-app/app/page.tsx # ✓ Cleanup complete! ``` ``` -------------------------------- ### CLI Usage - Non-Interactive Mode with Flags Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Utilize command-line flags to automate cleanup operations, suitable for CI/CD pipelines. ```APIDOC ## CLI Usage - Non-Interactive Mode with Flags Skip prompts and use command-line flags for automation and CI/CD pipelines. ### Common Flags - `-y`, `--yes`: Skip prompts and use default selections (public, favicon, page). - `--all`: Clean everything including optional CSS and layout. - `--dry-run`: Preview changes without modifying files. - `--no-public`: Skip cleaning public folder SVGs. - `--no-favicon`: Skip cleaning favicon.ico. - `--css`: Clean globals.css. - `--layout`: Clean layout.tsx. ### Examples ```bash # Skip prompts, use default selections npx next-cleaner -y # Clean everything npx next-cleaner --all # Preview changes without modifying files npx next-cleaner --dry-run # Selective cleaning - skip specific items npx next-cleaner -y --no-public --no-favicon # Only clean optional items (CSS and layout) npx next-cleaner -y --css --layout ``` ### Dry Run Example Output ``` # ℹ Detected Next.js project (App Router, src/) # ℹ Dry run mode - no files will be modified # → Removing SVG files from public/ # [dry-run] Would delete: /my-app/public/next.svg # [dry-run] Would delete: /my-app/public/vercel.svg # → Removing favicon.ico # [dry-run] Would delete: /my-app/app/favicon.ico # → Replacing page.tsx # [dry-run] Would replace: /my-app/app/page.tsx # ✓ Cleanup complete! ``` ``` -------------------------------- ### Non-Interactive CLI Usage with Flags for next-cleaner Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Illustrates non-interactive usage of the next-cleaner CLI with various flags. This includes skipping prompts with '-y', cleaning all optional items with '--all', previewing changes with '--dry-run', and selectively excluding or including items. ```bash # Skip prompts, use default selections (public, favicon, page) npx next-cleaner -y # Clean everything including optional CSS and layout npx next-cleaner --all # Preview changes without modifying files npx next-cleaner --dry-run # Output for dry-run: # ℹ Detected Next.js project (App Router, src/) # ℹ Dry run mode - no files will be modified # → Removing SVG files from public/ # [dry-run] Would delete: /my-app/public/next.svg # [dry-run] Would delete: /my-app/public/vercel.svg # → Removing favicon.ico # [dry-run] Would delete: /my-app/app/favicon.ico # → Replacing page.tsx # [dry-run] Would replace: /my-app/app/page.tsx # ✓ Cleanup complete! # Selective cleaning - skip specific items npx next-cleaner -y --no-public --no-favicon # Only clean optional items (CSS and layout) npx next-cleaner -y --css --layout ``` -------------------------------- ### Run next-cleaner using npx, pnpm, or bun Source: https://github.com/bhaskarrijal/next-cleaner/blob/main/README.md Execute the next-cleaner tool directly within your Next.js project directory using package manager's dlx or run commands. This is the primary method for invoking the cleaner. ```bash npx next-cleaner # or pnpm dlx next-cleaner # or bunx next-cleaner ``` -------------------------------- ### Programmatic Project Detection with next-cleaner API Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Shows how to use the `detectProject` function from the next-cleaner API to identify a Next.js project and retrieve its structural information. This function takes a directory path and returns an object with details like router type, src directory usage, and TypeScript configuration, or null if it's not a Next.js project. ```typescript import { detectProject } from 'next-cleaner'; const projectInfo = detectProject('/path/to/my-nextjs-app'); if (projectInfo) { console.log(projectInfo); // Output: // { // cwd: '/path/to/my-nextjs-app', // router: 'app', // 'app' | 'pages' | 'unknown' // srcDir: true, // true if using src/ directory // typescript: true, // true if tsconfig.json exists // appDir: 'src/app', // path to app directory or null // pagesDir: null, // path to pages directory or null // publicDir: 'public' // path to public directory // } } else { console.log('Not a Next.js project'); } ``` -------------------------------- ### Programmatic Cleanup Execution with next-cleaner API Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Demonstrates the usage of the `runCleaner` function from the next-cleaner API to perform cleanup operations on a detected Next.js project. It requires `ProjectInfo` obtained from `detectProject` and `CleanOptions` to specify which cleanup tasks to execute, such as removing public SVGs, favicon, or replacing page/layout/CSS files. The `dryRun` option allows for previewing changes. ```typescript import { detectProject, runCleaner } from 'next-cleaner'; import type { CleanOptions } from 'next-cleaner'; async function cleanProject() { const projectInfo = detectProject(process.cwd()); if (!projectInfo) { throw new Error('Not a Next.js project directory'); } const options: CleanOptions = { cleanPublic: true, // Remove SVG files from public/ cleanFavicon: true, // Delete app/favicon.ico cleanPage: true, // Replace page.tsx with blank component cleanGlobalsCss: false, // Keep globals.css as-is cleanLayout: false, // Keep layout.tsx as-is dryRun: false // Actually modify files (set true to preview) }; await runCleaner(projectInfo, options); console.log('Cleanup complete!'); } cleanProject().catch(console.error); ``` -------------------------------- ### Programmatic API - runCleaner Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Executes cleanup operations on a detected Next.js project based on specified options. ```APIDOC ## Programmatic API - runCleaner ### `runCleaner(project: ProjectInfo, options: CleanOptions): Promise` Executes the cleanup operations on the detected Next.js project based on the provided options. Removes SVG files from public folder, deletes favicon, and replaces page/layout/CSS files with minimal templates. #### Parameters - **project** (`ProjectInfo`) - Required - Information about the Next.js project, typically obtained from `detectProject`. - **options** (`CleanOptions`) - Required - Configuration options for the cleanup process. ```typescript interface CleanOptions { cleanPublic?: boolean; cleanFavicon?: boolean; cleanPage?: boolean; cleanGlobalsCss?: boolean; cleanLayout?: boolean; dryRun?: boolean; } ``` ### Request Example ```typescript import { detectProject, runCleaner } from 'next-cleaner'; import type { CleanOptions } from 'next-cleaner'; async function cleanProject() { const projectInfo = detectProject(process.cwd()); if (!projectInfo) { throw new Error('Not a Next.js project directory'); } const options: CleanOptions = { cleanPublic: true, cleanFavicon: true, cleanPage: true, cleanGlobalsCss: false, cleanLayout: false, dryRun: false }; await runCleaner(projectInfo, options); console.log('Cleanup complete!'); } cleanProject().catch(console.error); ``` ### Response This function does not return a value upon successful execution, but it modifies files in the project directory based on the `options` provided. It throws an error if the project detection fails or if any cleanup operation encounters an issue. ``` -------------------------------- ### Programmatic API - detectProject Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Detects if a directory is a Next.js project and returns its structural information. ```APIDOC ## Programmatic API - detectProject ### `detectProject(cwd: string): ProjectInfo | null` Detects if the given directory is a Next.js project and returns information about its structure including router type, source directory usage, and TypeScript configuration. #### Parameters - **cwd** (`string`) - Required - The current working directory to check. #### Returns - `ProjectInfo` object if it's a Next.js project, otherwise `null`. ```typescript interface ProjectInfo { cwd: string; router: 'app' | 'pages' | 'unknown'; srcDir: boolean; typescript: boolean; appDir: string | null; pagesDir: string | null; publicDir: string; } ``` ### Request Example ```typescript import { detectProject } from 'next-cleaner'; const projectInfo = detectProject('/path/to/my-nextjs-app'); if (projectInfo) { console.log(projectInfo); } else { console.log('Not a Next.js project'); } ``` ### Response Example ```json { "cwd": "/path/to/my-nextjs-app", "router": "app", "srcDir": true, "typescript": true, "appDir": "src/app", "pagesDir": null, "publicDir": "public" } ``` ``` -------------------------------- ### CleanOptions Interface Definition (TypeScript) Source: https://context7.com/bhaskarrijal/next-cleaner/llms.txt Defines the CleanOptions interface, which specifies the configuration settings for the next-cleaner cleanup process. These options control which specific files or types of files are targeted for cleaning, such as public assets, favicons, or CSS files. ```typescript import type { CleanOptions } from 'next-cleaner'; // CleanOptions structure interface CleanOptions { cleanPublic: boolean; // Remove SVG files from public folder cleanFavicon: boolean; // Delete favicon.ico from app directory cleanPage: boolean; // Replace page.tsx/index.tsx with blank component cleanGlobalsCss: boolean; // Reset globals.css to minimal Tailwind import cleanLayout: boolean; // Simplify layout.tsx, remove Geist fonts dryRun: boolean; // Preview changes without modifying files } // Full cleanup configuration const fullClean: CleanOptions = { cleanPublic: true, cleanFavicon: true, cleanPage: true, cleanGlobalsCss: true, cleanLayout: true, dryRun: false }; // Minimal cleanup (defaults) const minimalClean: CleanOptions = { cleanPublic: true, cleanFavicon: true, cleanPage: true, cleanGlobalsCss: false, cleanLayout: false, dryRun: false }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.