-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
pack.ts
45 lines (39 loc) · 1.15 KB
/
pack.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
import cp from "child_process"
import fs from "fs"
import os from "os"
import path from "path"
import {task, BuildError} from "../task"
function npm_pack() {
const dist = "build/dist"
if (!fs.existsSync(dist)) {
fs.mkdirSync(dist, {recursive: true})
}
const npm = process.platform != "win32" ? "npm" : "npm.cmd"
const {status, stdout, stderr} = cp.spawnSync(npm, ["pack", `--pack-destination=${dist}`], {stdio: "pipe", encoding: "utf-8"})
if (status !== 0) {
console.error(stdout)
console.error(stderr)
throw new BuildError("pack", `failed to run '${npm} pack'`)
}
const tgz = stdout.trim()
if (!tgz.endsWith(".tgz")) {
throw new BuildError("pack", "can't find tgz archive name in the output")
}
const tgz_latest = path.join(dist, "bokeh-bokehjs.tgz")
if (fs.existsSync(tgz_latest)) {
fs.unlinkSync(tgz_latest)
}
try {
fs.symlinkSync(tgz, tgz_latest)
} catch (error: unknown) {
if (error instanceof Error) {
const e = error as NodeJS.ErrnoException
if (e.errno === os.constants.errno.EPERM) {
fs.copyFileSync(tgz, tgz_latest)
}
}
}
}
task("pack", async () => {
npm_pack()
})