-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.ts
42 lines (39 loc) · 1.01 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
#!/usr/bin/env node
import { build } from 'esbuild'
import glob from 'glob'
import fs from 'fs-extra'
import { $, chalk } from 'zx'
import { version } from './package.json'
const isDevelop = process.env.NODE_ENV === 'develop'
const files = glob.sync('src/**/*.ts')
void (async () => {
console.time('Build Success')
await $`rm -rf dist`
await build({
entryPoints: files,
outdir: 'dist',
target: ['esnext'],
bundle: true,
minify: true,
format: 'esm',
watch: isDevelop,
sourcemap: isDevelop ? 'inline' : false
}).then(async (res) => {
try {
await $`cp -r public/* dist`
if (isDevelop) {
// 使用 tsc 做类型检查,不生成编译文件
await $`tsc --watch --noEmit`
} else {
await $`tsc --noEmit`
await $`zip -q -r yapi-interface-extension-v${version}.zip dist`
}
console.timeEnd('Build Success')
} catch (error) {
res.stop?.()
throw error
}
})
})().catch((error) => {
console.error(chalk.red(error))
})