Skip to content

Commit fa3ba45

Browse files
authored
fix: format config files with script (#2671)
1 parent 2243fc8 commit fa3ba45

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"generatePackages": "pnpm dlx tsx ./scripts/generatePackages.ts",
1616
"generateGlobalSdkPackage": "pnpm dlx tsx ./scripts/updateGlobalSdkPackage.ts",
1717
"setupNewProducts": "pnpm dlx tsx ./scripts/setupNewProducts.ts",
18-
"prebuild": "pnpm run generatePackages && pnpm run generateAlias && pnpm biome format --write --config-path scripts/templates/biome.generated.json packages_generated/**/*.json packages_generated/**/*.config.ts && pnpm biome format --write packages packages/sdk scripts",
18+
"prebuild": "pnpm run generatePackages && pnpm run generateAlias && pnpm dlx tsx ./scripts/formatGeneratedConfigFiles.ts && pnpm biome format --write packages packages/sdk scripts",
1919
"build:packages": "pnpm turbo run build",
2020
"fix-import-extensions": "pnpm dlx tsx ./scripts/fix-import-extensions.ts",
2121
"build": "pnpm run build:packages && pnpm run fix-import-extensions",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)