-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathalign_tsconfigs_references.mjs
36 lines (30 loc) · 1.32 KB
/
align_tsconfigs_references.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { readdirSync, readFileSync, statSync, writeFileSync } from 'fs'
import * as path from 'path'
const __dirname = path.dirname(new URL(import.meta.url).pathname)
const packagesDirs = readdirSync(path.resolve(__dirname, 'packages')).map(pkg_name =>
path.resolve(__dirname, 'packages', pkg_name),
)
packagesDirs.forEach(pkgDir => {
if (pkgDir.match('/storybook$') || pkgDir.match('/v2-migrate-v3$')) {
return
}
console.log('pkgDir', pkgDir)
const pkgJsonFile = path.resolve(pkgDir, 'package.json')
const pkgJsonFileExists = !!statSync(pkgJsonFile, { throwIfNoEntry: false })
if (!pkgJsonFileExists) return
const tsconfigJsonFile = path.resolve(pkgDir, 'tsconfig.json')
const tsconfigJsonFileExists = !!statSync(tsconfigJsonFile, { throwIfNoEntry: false })
if (!tsconfigJsonFileExists) return
const pkgJson = JSON.parse(readFileSync(pkgJsonFile, 'utf8'))
const tsconfigJson = JSON.parse(readFileSync(tsconfigJsonFile, 'utf8'))
tsconfigJson.references = [
...new Set(
Object.keys({
...pkgJson.devDependencies,
...pkgJson.peerDependencies,
...pkgJson.dependencies,
}).filter(depName => depName.startsWith('@moodlenet/')),
),
].map(_ => ({ path: `../${_.replace(/^@moodlenet\//, '')}` }))
writeFileSync(tsconfigJsonFile, JSON.stringify(tsconfigJson, null, 2) + '\n')
})