forked from loo-y/iPhoneOrder.2023
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbunBuild.ts
54 lines (46 loc) · 1.64 KB
/
bunBuild.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
51
52
53
54
const { exec } = require('child_process')
import path from 'path'
const removeFile = (filePath: string, isForce?: boolean) => {
if (!filePath) return
return new Promise((resolve, reject) => {
const command = `rm ${isForce ? '-rf' : ''} ${filePath}`
try {
// @ts-ignore
exec(command, (err, stdout, stderr) => {
if (err) {
console.error('Error removing file:', err)
resolve(false)
} else {
console.log('File removed successfully', filePath)
resolve(true)
}
})
} catch (e) {
console.log('Error removing file catch:', e)
resolve(false)
}
})
}
async function bunBuild() {
const outDir = path.resolve(__dirname, './extension')
const contentScript = path.resolve(__dirname, './app/scripts/content/')
const builtContentScript = path.resolve(outDir, './content-script.js')
const injectScript = path.resolve(__dirname, './app/scripts/inject/')
const builtInjectScript = path.resolve(outDir, './inject-script.js')
const zipFIle = path.resolve(__dirname, './iPhoneOrder.zip')
// 临时移除 removeFile 调用, bun的bug。 TODO
// await Promise.all([
// removeFile(builtContentScript, true),
// removeFile(builtInjectScript, true),
// removeFile(zipFIle, true),
// ])
// @ts-ignore
await Bun.build({
entrypoints: [contentScript, injectScript],
target: 'browser',
minify: true,
outdir: outDir,
naming: '[dir]-script.[ext]',
})
}
bunBuild()