|
9 | 9 | .name('Ultracite')
|
10 | 10 | .description('Strict, opinionated linting config for modern TypeScript apps.');
|
11 | 11 |
|
| 12 | +program |
| 13 | + .command('init') |
| 14 | + .description('Initialize Ultracite in the current directory') |
| 15 | + .action(() => { |
| 16 | + try { |
| 17 | + // Create biome.json config |
| 18 | + const biomeConfig = { |
| 19 | + $schema: 'https://biomejs.dev/schemas/1.9.4/schema.json', |
| 20 | + extends: ['ultracite'], |
| 21 | + }; |
| 22 | + |
| 23 | + // Create .vscode/settings.json |
| 24 | + const vsCodeSettings = { |
| 25 | + 'typescript.tsdk': 'node_modules/typescript/lib', |
| 26 | + 'editor.defaultFormatter': 'biomejs.biome', |
| 27 | + 'editor.formatOnSave': true, |
| 28 | + 'editor.formatOnPaste': true, |
| 29 | + 'emmet.showExpandedAbbreviation': 'never', |
| 30 | + 'editor.codeActionsOnSave': { |
| 31 | + 'quickfix.biome': 'explicit', |
| 32 | + 'source.organizeImports.biome': 'explicit', |
| 33 | + }, |
| 34 | + '[typescript]': { |
| 35 | + 'editor.defaultFormatter': 'biomejs.biome', |
| 36 | + }, |
| 37 | + '[json]': { |
| 38 | + 'editor.defaultFormatter': 'biomejs.biome', |
| 39 | + }, |
| 40 | + '[javascript]': { |
| 41 | + 'editor.defaultFormatter': 'biomejs.biome', |
| 42 | + }, |
| 43 | + '[jsonc]': { |
| 44 | + 'editor.defaultFormatter': 'biomejs.biome', |
| 45 | + }, |
| 46 | + '[typescriptreact]': { |
| 47 | + 'editor.defaultFormatter': 'biomejs.biome', |
| 48 | + }, |
| 49 | + }; |
| 50 | + // Create or merge tsconfig.json |
| 51 | + let tsConfig = { |
| 52 | + compilerOptions: { |
| 53 | + strictNullChecks: true, |
| 54 | + }, |
| 55 | + }; |
| 56 | + |
| 57 | + try { |
| 58 | + const existingTsConfig = JSON.parse(execSync('cat tsconfig.json', { encoding: 'utf-8' })); |
| 59 | + tsConfig = { |
| 60 | + ...existingTsConfig, |
| 61 | + compilerOptions: { |
| 62 | + ...existingTsConfig.compilerOptions, |
| 63 | + ...tsConfig.compilerOptions, |
| 64 | + }, |
| 65 | + }; |
| 66 | + } catch (e) { |
| 67 | + // tsconfig.json doesn't exist, use default config |
| 68 | + } |
| 69 | + |
| 70 | + // Install dependencies |
| 71 | + execSync('pnpm add -D --save-exact ultracite @biomejs/biome'); |
| 72 | + |
| 73 | + // Write the config files |
| 74 | + execSync('mkdir -p .vscode'); |
| 75 | + execSync(`echo '${JSON.stringify(biomeConfig, null, 2)}' > biome.json`); |
| 76 | + execSync( |
| 77 | + `echo '${JSON.stringify(vsCodeSettings, null, 2)}' > .vscode/settings.json` |
| 78 | + ); |
| 79 | + execSync(`echo '${JSON.stringify(tsConfig, null, 2)}' > tsconfig.json`); |
| 80 | + |
| 81 | + console.log('Successfully initialized Ultracite configuration!'); |
| 82 | + } catch (error) { |
| 83 | + console.error('Failed to run Ultracite:', error.message); |
| 84 | + process.exit(1); |
| 85 | + } |
| 86 | + }); |
| 87 | + |
12 | 88 | program
|
13 | 89 | .command('lint')
|
14 | 90 | .description('Run Biome linter without fixing files')
|
|
0 commit comments