-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
43 lines (37 loc) · 1.03 KB
/
build.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
39
40
41
42
43
import { readFile, readdir, writeFile, rm } from 'fs/promises'
import { build } from 'tsup'
async function buildNodes() {
const nodes = await readdir('./src/nodes')
const entry: string[] = []
for (const node of nodes)
entry.push(`./src/nodes/${node}/index.ts`, `./src/nodes/${node}/editor.ts`)
await build({
entry,
splitting: false,
sourcemap: false,
clean: true,
format: ['cjs'],
target: 'node20',
publicDir: 'public',
outDir: 'build'
})
for (const node of nodes) {
const [html, editor, main] = await Promise.all([
readFile(`./src/nodes/${node}/editor.html`, 'utf8'),
readFile(`./build/${node}/editor.js`, 'utf8'),
readFile(`./build/${node}/index.js`, 'utf8')
])
await writeFile(
`./build/${node}.html`,
`<script type="text/javascript">${editor}</script>${html}`,
'utf8'
)
await writeFile(`./build/${node}.js`, main, 'utf8')
await rm(`./build/${node}`, {
recursive: true,
force: true
})
}
process.exit(0)
}
buildNodes()