-
Notifications
You must be signed in to change notification settings - Fork 406
/
build-server.ts
50 lines (44 loc) · 1.23 KB
/
build-server.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
44
45
46
47
48
49
50
import path from 'path'
import { fileURLToPath } from 'url'
import esbuild from 'esbuild'
import fsExtra from 'fs-extra'
import { globSync } from 'glob'
const pkg = fsExtra.readJsonSync(path.join(process.cwd(), 'package.json'))
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const here = (...s: Array<string>) => path.join(__dirname, ...s)
const globsafe = (s: string) => s.replace(/\\/g, '/')
const allFiles = globSync(globsafe(here('../server/**/*.*')), {
ignore: [
'server/dev-server.js', // for development only
'**/tsconfig.json',
'**/eslint*',
'**/__tests__/**',
],
})
const entries = []
for (const file of allFiles) {
if (/\.(ts|js|tsx|jsx)$/.test(file)) {
entries.push(file)
} else {
const dest = file.replace(here('../server'), here('../server-build'))
fsExtra.ensureDirSync(path.parse(dest).dir)
fsExtra.copySync(file, dest)
console.log(`copied: ${file.replace(`${here('../server')}/`, '')}`)
}
}
console.log()
console.log('building...')
esbuild
.build({
entryPoints: entries,
outdir: here('../server-build'),
target: [`node${pkg.engines.node}`],
platform: 'node',
sourcemap: true,
format: 'esm',
logLevel: 'info',
})
.catch((error: unknown) => {
console.error(error)
process.exit(1)
})