import type { TailwindcssPatchCommand, TailwindcssPatchCommandOptionDefinition } from './types' import process from 'node:process' import { DEFAULT_TOKEN_REPORT } from './token-output' export interface TailwindcssPatchCommandDefinition { description: string optionDefs: TailwindcssPatchCommandOptionDefinition[] } export type TailwindcssPatchCommandDefinitions = Record function createCwdOptionDefinition(description: string = 'Working directory'): TailwindcssPatchCommandOptionDefinition { return { flags: '--cwd ', description, config: { default: process.cwd() }, } } export function buildDefaultCommandDefinitions(): TailwindcssPatchCommandDefinitions { return { install: { description: 'Apply Tailwind CSS runtime patches', optionDefs: [createCwdOptionDefinition()], }, extract: { description: 'Collect generated class names into a cache file', optionDefs: [ createCwdOptionDefinition(), { flags: '--output ', description: 'Override output file path' }, { flags: '--format ', description: 'Output format (json|lines)' }, { flags: '--css ', description: 'Tailwind CSS entry CSS when using v4' }, { flags: '--no-write', description: 'Skip writing to disk' }, ], }, tokens: { description: 'Extract Tailwind tokens with file/position metadata', optionDefs: [ createCwdOptionDefinition(), { flags: '--output ', description: 'Override output file path', config: { default: DEFAULT_TOKEN_REPORT } }, { flags: '--format ', description: 'Output format (json|lines|grouped-json)', config: { default: 'json' }, }, { flags: '--group-key ', description: 'Grouping key for grouped-json output (relative|absolute)', config: { default: 'relative' }, }, { flags: '--no-write', description: 'Skip writing to disk' }, ], }, init: { description: 'Generate a tailwindcss-patch config file', optionDefs: [createCwdOptionDefinition()], }, migrate: { description: 'Migrate deprecated config fields to modern options', optionDefs: [ createCwdOptionDefinition(), { flags: '--config ', description: 'Migrate a specific config file path' }, { flags: '--workspace', description: 'Scan workspace recursively for config files' }, { flags: '--max-depth ', description: 'Maximum recursion depth for --workspace', config: { default: 6 } }, { flags: '--include ', description: 'Only migrate files that match this glob (repeatable)' }, { flags: '--exclude ', description: 'Skip files that match this glob (repeatable)' }, { flags: '--report-file ', description: 'Write migration report JSON to a file' }, { flags: '--backup-dir ', description: 'Write pre-migration backups into this directory' }, { flags: '--check', description: 'Exit with an error when migration changes are required' }, { flags: '--json', description: 'Print the migration report as JSON' }, { flags: '--dry-run', description: 'Preview changes without writing files' }, ], }, restore: { description: 'Restore config files from a previous migration report backup snapshot', optionDefs: [ createCwdOptionDefinition(), { flags: '--report-file ', description: 'Migration report file generated by migrate' }, { flags: '--dry-run', description: 'Preview restore targets without writing files' }, { flags: '--strict', description: 'Fail when any backup file is missing' }, { flags: '--json', description: 'Print the restore result as JSON' }, ], }, validate: { description: 'Validate migration report compatibility without modifying files', optionDefs: [ createCwdOptionDefinition(), { flags: '--report-file ', description: 'Migration report file to validate' }, { flags: '--strict', description: 'Fail when any backup file is missing' }, { flags: '--json', description: 'Print validation result as JSON' }, ], }, status: { description: 'Check which Tailwind patches are applied', optionDefs: [ createCwdOptionDefinition(), { flags: '--json', description: 'Print a JSON report of patch status' }, ], }, } }