/
link-typedefinitions.ts
38 lines (32 loc) · 1.27 KB
/
link-typedefinitions.ts
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
37
38
import { writeFileSync } from 'fs'
import { resolve } from 'path'
import { sync as globSync } from 'glob'
type FromWheretoImport = string
type OutputPath = string
type FilterFunction = (file: string) => boolean
const mappings: [FromWheretoImport, OutputPath?, FilterFunction?][] = [
['adapters'],
['adapter-svelte', 'svelte', (file) => file === 'svelte-store.d.ts'],
['adapter-react', 'react', (file) => file === 'react-context.d.ts'],
['core', 'cjs'],
['core', 'esm'],
['formatters'],
['locale-detector', 'detectors'],
['rollup-plugin', 'rollup'],
['webpack-plugin', 'webpack'],
]
mappings.forEach(([fromWheretoImport, outputPath = fromWheretoImport, mapperFunction]) => {
const files = globSync(resolve(__dirname, `../types/${fromWheretoImport}/src/**/*.d.ts`)).map((file) =>
resolve(file).substring(resolve(__dirname, `../types/${fromWheretoImport}/src/`).length + 1),
)
const filteredFiles = (mapperFunction && files.filter(mapperFunction)) || files
filteredFiles.forEach((file) => {
writeFileSync(
resolve(__dirname, `../${outputPath}/${file}`),
`export * from '../types/${fromWheretoImport}/src/${file.substring(0, file.length - 5)}'`,
{ encoding: 'utf8' },
)
})
// eslint-disable-next-line no-console
console.info(`types linked for '${outputPath}'`)
})