-
Notifications
You must be signed in to change notification settings - Fork 38
/
build.js
39 lines (37 loc) · 1.04 KB
/
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
39
const { readFile, writeFile } = require('fs/promises')
/**
* 带puppeteer的话,esbuild打包完跑不起来,先这么处理一下
*/
async function patch () {
const path = './src/handler/index.ts'
const handlerContent = (await readFile(path)).toString().replace('new ChatGPTHandler()', '//new ChatGPTHandler()')
await writeFile(path, handlerContent)
console.log('patch...')
}
async function unpatch () {
const path = './src/handler/index.ts'
const handlerContent = (await readFile(path)).toString().replace('//new ChatGPTHandler()', 'new ChatGPTHandler()')
await writeFile(path, handlerContent)
console.log('unpatch...')
}
async function build () {
await patch()
require('esbuild').build({
entryPoints: ['src/main.ts'],
bundle: true,
outfile: 'build/app.js',
platform: 'node',
minify: true,
external: [],
plugins: []
}).then((res) => {
console.log('builded app.js..')
require('pkg').exec('.')
}).then(() => {
unpatch()
}).catch(() => {
unpatch()
process.exit(1)
})
}
build()