|
| 1 | +#!/usr/bin/env tsx |
| 2 | + |
| 3 | +/** |
| 4 | + * Format only configuration files generated by generatePackages.ts |
| 5 | + * (tsconfig.json, tsconfig.build.json, vite.config.ts, package.json) |
| 6 | + * This script is used in prebuild to format these files without |
| 7 | + * reformatting .gen.ts files that were already formatted by the external script. |
| 8 | + */ |
| 9 | + |
| 10 | +import { execSync } from 'node:child_process' |
| 11 | +import { readdirSync, statSync } from 'node:fs' |
| 12 | +import { join } from 'node:path' |
| 13 | + |
| 14 | +const CONFIG_FILES = [ |
| 15 | + 'tsconfig.json', |
| 16 | + 'tsconfig.build.json', |
| 17 | + 'vite.config.ts', |
| 18 | + 'package.json', |
| 19 | +] |
| 20 | + |
| 21 | +function findConfigFiles(dir: string, fileList: string[] = []): string[] { |
| 22 | + const files = readdirSync(dir) |
| 23 | + for (const file of files) { |
| 24 | + const filePath = join(dir, file) |
| 25 | + const stat = statSync(filePath) |
| 26 | + if (stat.isDirectory()) { |
| 27 | + findConfigFiles(filePath, fileList) |
| 28 | + } else if (CONFIG_FILES.includes(file)) { |
| 29 | + fileList.push(filePath) |
| 30 | + } |
| 31 | + } |
| 32 | + return fileList |
| 33 | +} |
| 34 | + |
| 35 | +async function main(): Promise<void> { |
| 36 | + const rootDir = process.cwd() |
| 37 | + const packagesGeneratedDir = join(rootDir, 'packages_generated') |
| 38 | + const configFiles = findConfigFiles(packagesGeneratedDir) |
| 39 | + |
| 40 | + if (configFiles.length === 0) { |
| 41 | + console.log('No config files found to format') |
| 42 | + return |
| 43 | + } |
| 44 | + |
| 45 | + console.log(`Formatting ${configFiles.length} config file(s)...`) |
| 46 | + |
| 47 | + // Format all config files at once |
| 48 | + const filesArg = configFiles.map(f => `"${f}"`).join(' ') |
| 49 | + try { |
| 50 | + execSync( |
| 51 | + `pnpm biome format --write --config-path scripts/templates/biome.generated.json ${filesArg}`, |
| 52 | + { stdio: 'inherit' }, |
| 53 | + ) |
| 54 | + } catch (error) { |
| 55 | + console.error(`Error formatting config files:`, error) |
| 56 | + process.exit(1) |
| 57 | + } |
| 58 | + |
| 59 | + console.log('✅ Config files formatted successfully') |
| 60 | +} |
| 61 | + |
| 62 | +main().catch(error => { |
| 63 | + console.error(error) |
| 64 | + process.exit(1) |
| 65 | +}) |
0 commit comments