-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathesbuild.config.js
81 lines (81 loc) · 2.06 KB
/
esbuild.config.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import esbuild from 'esbuild'
import path from 'path'
import fs, { mkdirSync } from 'fs'
import { rootPath } from '#common/utils/file/getRootPath.js'
// 读取 package.json 文件内容
const packageJson = JSON.parse(
fs.readFileSync(path.resolve(rootPath, 'package.json'), 'utf-8')
)
const publishExcludeFields = [
'scripts',
'devDependencies',
'imports',
'main',
'config'
]
const clean = () => {
return new Promise((resolve, reject) => {
fs.rm(path.resolve(rootPath, 'pl-cli'), { recursive: true }, (err) => {
if (err) {
resolve()
} else {
resolve()
}
})
})
}
await clean()
await esbuild
.build({
entryPoints: ['bin/lk.js', 'bin/lf.js', 'bin/lc.js'],
outdir: 'pl-cli/.bin',
platform: 'node',
target: ['node20'],
format: 'esm',
bundle: true,
minify: true,
packages: 'external',
define: {
'process.env.VERSION': JSON.stringify(packageJson.version)
}
})
.then(() => {
// 构建完成后执行的操作
// 复制文件
const docs = fs.readdirSync(path.resolve(rootPath, 'docs'))
// 创建docs
mkdirSync(path.resolve(rootPath, 'pl-cli/docs'), { recursive: true })
docs.forEach((doc) => {
fs.copyFileSync(
path.resolve(rootPath, 'docs', doc),
path.resolve(rootPath, 'pl-cli/docs/', doc)
)
})
fs.copyFileSync(
path.resolve(rootPath, 'README.md'),
path.resolve(rootPath, 'pl-cli/README.md')
)
fs.copyFileSync(
path.resolve(rootPath, 'LICENSE'),
path.resolve(rootPath, 'pl-cli/LICENSE')
)
const newPackageJson = Object.assign(packageJson, {
bin: {
lk: '.bin/lk.js',
lf: '.bin/lf.js',
lc: '.bin/lc.js'
}
})
publishExcludeFields?.forEach((key) => {
delete newPackageJson[key]
})
fs.writeFileSync(
path.resolve(rootPath, 'pl-cli/package.json'),
JSON.stringify(newPackageJson)
)
console.log('[LP]脚本打包完成,查看目录[pl-cli].')
})
.catch((e) => {
console.error('[LP]脚本打包失败', e)
process.exit(1)
})