-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
38 lines (32 loc) · 1013 Bytes
/
build.js
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 { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { copyFileSync, readdirSync } from 'fs'
import { build } from 'vite'
const toPascalcase = text => ` ${text}`.toLowerCase()
.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase())
const __dirname = dirname(fileURLToPath(import.meta.url))
const path = relativePath => resolve(__dirname, relativePath)
const getDirectories = source =>
readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
const libraries = getDirectories(path('./src/'))
.map(name => ({
name: toPascalcase(name),
entry: path(`./src/${name}/index.ts`),
fileName: name,
}))
for (const library of libraries) {
await build({
build: {
outDir: './dist',
minify: true,
lib: {
...library,
formats: ['es', 'umd', 'iife'],
},
emptyOutDir: false,
},
})
}
copyFileSync(path('./src/index.ts'), path('./dist/index.d.ts'))