-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbuild.ts
50 lines (40 loc) · 1.53 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
43
44
45
46
47
48
49
50
import fs from 'fs-extra'
import { execa } from 'execa'
import { PathUtils } from '@nicepkg/gpt-runner-shared/node'
const dirname = PathUtils.getCurrentDirName(import.meta.url, () => __dirname)
const root = PathUtils.join(dirname, '..')
const dist = PathUtils.join(root, 'dist')
// is build vsix
const isBuildVsix = process.argv.includes('--vsix')
async function build() {
// remove <root>/dist
await fs.remove(dist)
const pkgPath = PathUtils.join(root, 'package.json')
const rawJSON = await fs.readFile(pkgPath, 'utf-8')
const pkg = JSON.parse(rawJSON)
pkg.name = 'gpt-runner'
await fs.writeJSON(pkgPath, pkg, { spaces: 2 })
await execa('tsup', { cwd: root, stdio: 'inherit' })
try {
// copy from <root>/node_modules/@nicepkg/gpt-runner-web/dist to <root>/dist/web
const webDistPath = PathUtils.join(root, 'dist/web')
await fs.copy(
PathUtils.join(root, 'node_modules/@nicepkg/gpt-runner-web/dist'),
webDistPath,
)
// copy from <root>/node_modules/@nicepkg/gpt-runner-shared/dist/json-schema to <root>/dist/json-schema
const jsonSchemaDistPath = PathUtils.join(root, 'dist/json-schema')
await fs.copy(
PathUtils.join(root, 'node_modules/@nicepkg/gpt-runner-shared/dist/json-schema'),
jsonSchemaDistPath,
)
if (!isBuildVsix)
return
console.log('\nBuild Vsix...\n')
await execa('vsce', ['package', '-o', 'dist/gpt-runner.vsix', '--no-dependencies'], { cwd: root, stdio: 'inherit' })
}
finally {
await fs.writeFile(pkgPath, rawJSON, 'utf-8')
}
}
build()