lingeebuild-cli 0.0.0-stage → 0.0.364
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +148 -2
- package/bin/lingeebuild +186 -0
- package/package.json +23 -3
- package/postinstall.mjs +119 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
## 0.0.364 - 2026-11-23
|
|
4
|
+
|
|
5
|
+
### 新增
|
|
6
|
+
|
|
7
|
+
- `run` 命令新增 `--sandbox-mode` 参数,支持只读 `read-only`、可写工作区 `workspace-write` 和完整访问 `full-access`;新会话默认使用 `workspace-write`。
|
|
8
|
+
- 沙箱档位会保存在当前会话中,使用 `--continue` 或 `--session` 继续会话时无需重复指定。
|
|
9
|
+
|
|
10
|
+
### 修复
|
|
11
|
+
|
|
12
|
+
- 修复 Linux 服务器使用受限沙箱时,错误提示误报缺少 Windows 沙箱组件的问题;现在会明确说明当前版本在 Linux 上尚不支持受限沙箱,并给出 `--sandbox-mode full-access` 的命令示例。
|
|
13
|
+
- 修复 Work 会话已被服务端拒绝时,`auth status` 仍可能依据本地状态显示已登录的问题;现在查询状态会在线复核会话。
|
|
14
|
+
- 修复 MaaS 租户票据过期后,`models` 可能空输出且仍以成功状态退出的问题。命令会在请求前复核会话并刷新票据,目录接口返回 401/403 时自动换票并重试一次。
|
|
15
|
+
- 修复模型目录的鉴权、网络、HTTP 和响应格式错误被统一转换为空列表的问题;现在保留具体错误原因,并在没有可用模型时返回非零退出码。
|
|
16
|
+
- 修复 CLI 拉取模型目录后未同步模型映射与完整模型缓存的问题,确保模型能力、定制参数以及视觉、文生图场景可以正确解析。
|
|
17
|
+
|
|
18
|
+
### 文档
|
|
19
|
+
|
|
20
|
+
- npm 软件包新增使用说明和更新日志。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 opencode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,149 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lingeebuild CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
金蝶灵基 Build 命令行工具,可在终端中运行开发任务、管理模型,以及启动本地 Web 或服务端接口。
|
|
4
|
+
|
|
5
|
+
npm 软件包名为 `lingeebuild-cli`,安装后的命令为 `lingeebuild`。安装时会根据当前操作系统、CPU 架构和 C 库自动选择对应的平台二进制包。
|
|
6
|
+
|
|
7
|
+
## 环境要求
|
|
8
|
+
|
|
9
|
+
- 建议使用 Node.js 20 或更高版本及 npm。
|
|
10
|
+
- 支持 macOS、Linux 和 Windows 的 x64、ARM64 平台。
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g lingeebuild-cli
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
检查安装结果:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
lingeebuild --version
|
|
22
|
+
lingeebuild --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 快速开始
|
|
26
|
+
|
|
27
|
+
登录灵基 Work 平台:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
lingeebuild auth login
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
也可以通过手机扫码授权:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
lingeebuild auth login --qr
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
确认登录状态并查看当前租户可用的模型:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
lingeebuild auth status
|
|
43
|
+
lingeebuild models
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
在项目目录中运行任务:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
lingeebuild run "分析当前项目并修复发现的问题"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 常用命令
|
|
53
|
+
|
|
54
|
+
| 命令 | 用途 |
|
|
55
|
+
| --------------------------------------- | --------------------------- |
|
|
56
|
+
| `lingeebuild run "任务描述"` | 执行一次开发任务 |
|
|
57
|
+
| `lingeebuild run --continue "继续处理"` | 继续最近一次会话 |
|
|
58
|
+
| `lingeebuild models` | 列出当前可用的模型 |
|
|
59
|
+
| `lingeebuild auth status` | 查看平台登录状态 |
|
|
60
|
+
| `lingeebuild auth switch` | 切换当前租户 |
|
|
61
|
+
| `lingeebuild auth logout` | 退出平台登录 |
|
|
62
|
+
| `lingeebuild web` | 启动本地服务并打开 Web 界面 |
|
|
63
|
+
| `lingeebuild serve` | 启动无界面的本地服务端 |
|
|
64
|
+
|
|
65
|
+
查看某个命令的完整参数:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
lingeebuild run --help
|
|
69
|
+
lingeebuild auth --help
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 选择模型
|
|
73
|
+
|
|
74
|
+
按供应商筛选模型,并在运行时指定 `provider/model`:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
lingeebuild models kingdee-maas
|
|
78
|
+
lingeebuild run --model "kingdee-maas/<model-id>" "任务描述"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
调整当前默认模型的上下文窗口大小:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
lingeebuild model context 200000
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
平台登录态和 MaaS 租户票据会在执行模型目录等命令时按需复核、刷新;只有平台明确拒绝当前会话时才需要重新登录。
|
|
88
|
+
|
|
89
|
+
## 沙箱档位
|
|
90
|
+
|
|
91
|
+
`run` 命令支持通过 `--sandbox-mode` 设置会话沙箱档位:
|
|
92
|
+
|
|
93
|
+
| 档位 | 说明 |
|
|
94
|
+
| ----------------- | ---------------------------------------- |
|
|
95
|
+
| `read-only` | 只读,不允许修改文件 |
|
|
96
|
+
| `workspace-write` | 允许修改当前工作区,新会话默认使用此档位 |
|
|
97
|
+
| `full-access` | 使用当前系统账户的完整权限,仅限可信环境 |
|
|
98
|
+
|
|
99
|
+
在可信环境中显式选择完整访问:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
lingeebuild run --sandbox-mode full-access "查看项目结构"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
档位设置后保存在当前会话中,继续会话时无需重复指定:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
lingeebuild run --continue "继续查看入口文件"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
当前版本在 Linux 上尚不支持受限沙箱;在可信的 Linux 环境中可显式使用 `--sandbox-mode full-access`。
|
|
112
|
+
|
|
113
|
+
## 自动化与脚本
|
|
114
|
+
|
|
115
|
+
使用 JSONL 事件流并关闭交互等待,便于接入 CI 或其他自动化工具:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
lingeebuild run "执行测试并汇总结果" --format jsonl --no-interactive
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
也可以从文件或标准输入读取提示词:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
lingeebuild run --prompt-file ./task.md --no-interactive
|
|
125
|
+
cat ./task.md | lingeebuild run --prompt-file - --no-interactive
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 更新日志
|
|
129
|
+
|
|
130
|
+
### 0.0.364
|
|
131
|
+
|
|
132
|
+
- `run` 新增 `--sandbox-mode` 会话沙箱档位,支持 `read-only`、`workspace-write` 和 `full-access`。
|
|
133
|
+
- 修正 Linux 受限沙箱不可用时的错误提示,不再误报缺少 Windows 沙箱组件。
|
|
134
|
+
- 修复登录状态误报,以及 MaaS 租户票据过期导致 `models` 静默空输出的问题。
|
|
135
|
+
- 模型目录请求支持自动换票并重试,同时保留鉴权、网络和服务端错误原因。
|
|
136
|
+
- 修复 CLI 模型能力、定制参数及视觉、文生图场景的缓存同步问题。
|
|
137
|
+
|
|
138
|
+
完整更新日志见随软件包发布的 `CHANGELOG.md`。
|
|
139
|
+
|
|
140
|
+
## 更新与卸载
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm install -g lingeebuild-cli@latest
|
|
144
|
+
npm uninstall -g lingeebuild-cli
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 许可证
|
|
148
|
+
|
|
149
|
+
MIT
|
package/bin/lingeebuild
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const childProcess = require("child_process")
|
|
4
|
+
const fs = require("fs")
|
|
5
|
+
const path = require("path")
|
|
6
|
+
const os = require("os")
|
|
7
|
+
|
|
8
|
+
function run(target) {
|
|
9
|
+
const env = { ...process.env }
|
|
10
|
+
// 平台包 bin/lib 随带了比老发行版(麒麟等)系统库更新的 libstdc++,
|
|
11
|
+
// 内嵌 .node 在 /tmp 被 dlopen 时只能靠 LD_LIBRARY_PATH 解析依赖。
|
|
12
|
+
const libDir = path.join(path.dirname(target), "lib")
|
|
13
|
+
if (os.platform() === "linux" && fs.existsSync(libDir)) {
|
|
14
|
+
env.LD_LIBRARY_PATH = env.LD_LIBRARY_PATH ? `${libDir}:${env.LD_LIBRARY_PATH}` : libDir
|
|
15
|
+
}
|
|
16
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
17
|
+
stdio: "inherit",
|
|
18
|
+
env,
|
|
19
|
+
})
|
|
20
|
+
if (result.error) {
|
|
21
|
+
console.error(result.error.message)
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
25
|
+
process.exit(code)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const envPath = process.env.LINGEEBUILD_BIN_PATH ?? process.env.OPENCODE_BIN_PATH
|
|
29
|
+
if (envPath) {
|
|
30
|
+
run(envPath)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
34
|
+
const scriptDir = path.dirname(scriptPath)
|
|
35
|
+
|
|
36
|
+
const cached = path.join(scriptDir, ".lingeebuild")
|
|
37
|
+
if (fs.existsSync(cached)) {
|
|
38
|
+
run(cached)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const platformMap = {
|
|
42
|
+
darwin: "darwin",
|
|
43
|
+
linux: "linux",
|
|
44
|
+
win32: "windows",
|
|
45
|
+
}
|
|
46
|
+
const archMap = {
|
|
47
|
+
x64: "x64",
|
|
48
|
+
arm64: "arm64",
|
|
49
|
+
arm: "arm",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let platform = platformMap[os.platform()]
|
|
53
|
+
if (!platform) {
|
|
54
|
+
platform = os.platform()
|
|
55
|
+
}
|
|
56
|
+
let arch = archMap[os.arch()]
|
|
57
|
+
if (!arch) {
|
|
58
|
+
arch = os.arch()
|
|
59
|
+
}
|
|
60
|
+
const base = "lingeebuild-" + platform + "-" + arch
|
|
61
|
+
const binary = platform === "windows" ? "lingeebuild.exe" : "lingeebuild"
|
|
62
|
+
|
|
63
|
+
function supportsAvx2() {
|
|
64
|
+
if (arch !== "x64") return false
|
|
65
|
+
|
|
66
|
+
if (platform === "linux") {
|
|
67
|
+
try {
|
|
68
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
69
|
+
} catch {
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (platform === "darwin") {
|
|
75
|
+
try {
|
|
76
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
77
|
+
encoding: "utf8",
|
|
78
|
+
timeout: 1500,
|
|
79
|
+
})
|
|
80
|
+
if (result.status !== 0) return false
|
|
81
|
+
return (result.stdout || "").trim() === "1"
|
|
82
|
+
} catch {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (platform === "windows") {
|
|
88
|
+
const cmd =
|
|
89
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
90
|
+
|
|
91
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
92
|
+
try {
|
|
93
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
94
|
+
encoding: "utf8",
|
|
95
|
+
timeout: 3000,
|
|
96
|
+
windowsHide: true,
|
|
97
|
+
})
|
|
98
|
+
if (result.status !== 0) continue
|
|
99
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
100
|
+
if (out === "true" || out === "1") return true
|
|
101
|
+
if (out === "false" || out === "0") return false
|
|
102
|
+
} catch {
|
|
103
|
+
continue
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const names = (() => {
|
|
114
|
+
const avx2 = supportsAvx2()
|
|
115
|
+
const baseline = arch === "x64" && !avx2
|
|
116
|
+
|
|
117
|
+
if (platform === "linux") {
|
|
118
|
+
const musl = (() => {
|
|
119
|
+
try {
|
|
120
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
121
|
+
} catch {
|
|
122
|
+
// ignore
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
127
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
128
|
+
if (text.includes("musl")) return true
|
|
129
|
+
} catch {
|
|
130
|
+
return false
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return false
|
|
134
|
+
})()
|
|
135
|
+
|
|
136
|
+
if (musl) {
|
|
137
|
+
if (arch === "x64") {
|
|
138
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
139
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
140
|
+
}
|
|
141
|
+
return [`${base}-musl`, base]
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (arch === "x64") {
|
|
145
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
146
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
147
|
+
}
|
|
148
|
+
return [base, `${base}-musl`]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (arch === "x64") {
|
|
152
|
+
if (baseline) return [`${base}-baseline`, base]
|
|
153
|
+
return [base, `${base}-baseline`]
|
|
154
|
+
}
|
|
155
|
+
return [base]
|
|
156
|
+
})()
|
|
157
|
+
|
|
158
|
+
function findBinary(startDir) {
|
|
159
|
+
let current = startDir
|
|
160
|
+
for (;;) {
|
|
161
|
+
const modules = path.join(current, "node_modules")
|
|
162
|
+
if (fs.existsSync(modules)) {
|
|
163
|
+
for (const name of names) {
|
|
164
|
+
const candidate = path.join(modules, name, "bin", binary)
|
|
165
|
+
if (fs.existsSync(candidate)) return candidate
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const parent = path.dirname(current)
|
|
169
|
+
if (parent === current) {
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
current = parent
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const resolved = findBinary(scriptDir)
|
|
177
|
+
if (!resolved) {
|
|
178
|
+
console.error(
|
|
179
|
+
"It seems that your package manager failed to install the right version of the lingeebuild CLI for your platform. You can try manually installing " +
|
|
180
|
+
names.map((n) => `"${n}"`).join(" or ") +
|
|
181
|
+
" package",
|
|
182
|
+
)
|
|
183
|
+
process.exit(1)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
run(resolved)
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingeebuild-cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"description": "金蝶灵基 Build 命令行工具",
|
|
4
|
+
"bin": {
|
|
5
|
+
"lingeebuild": "./bin/lingeebuild"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
|
|
9
|
+
},
|
|
10
|
+
"version": "0.0.364",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"optionalDependencies": {
|
|
13
|
+
"lingeebuild-linux-x64-musl": "0.0.364",
|
|
14
|
+
"lingeebuild-linux-x64-baseline": "0.0.364",
|
|
15
|
+
"lingeebuild-darwin-arm64": "0.0.364",
|
|
16
|
+
"lingeebuild-linux-arm64": "0.0.364",
|
|
17
|
+
"lingeebuild-windows-x64": "0.0.364",
|
|
18
|
+
"lingeebuild-darwin-x64-baseline": "0.0.364",
|
|
19
|
+
"lingeebuild-darwin-x64": "0.0.364",
|
|
20
|
+
"lingeebuild-windows-arm64": "0.0.364",
|
|
21
|
+
"lingeebuild-linux-x64": "0.0.364",
|
|
22
|
+
"lingeebuild-linux-arm64-musl": "0.0.364",
|
|
23
|
+
"lingeebuild-linux-x64-baseline-musl": "0.0.364",
|
|
24
|
+
"lingeebuild-windows-x64-baseline": "0.0.364"
|
|
25
|
+
}
|
|
6
26
|
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import os from "os"
|
|
6
|
+
import { fileURLToPath } from "url"
|
|
7
|
+
import { createRequire } from "module"
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
const require = createRequire(import.meta.url)
|
|
11
|
+
|
|
12
|
+
function detectPlatformAndArch() {
|
|
13
|
+
// Map platform names
|
|
14
|
+
let platform
|
|
15
|
+
switch (os.platform()) {
|
|
16
|
+
case "darwin":
|
|
17
|
+
platform = "darwin"
|
|
18
|
+
break
|
|
19
|
+
case "linux":
|
|
20
|
+
platform = "linux"
|
|
21
|
+
break
|
|
22
|
+
case "win32":
|
|
23
|
+
platform = "windows"
|
|
24
|
+
break
|
|
25
|
+
default:
|
|
26
|
+
platform = os.platform()
|
|
27
|
+
break
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Map architecture names
|
|
31
|
+
let arch
|
|
32
|
+
switch (os.arch()) {
|
|
33
|
+
case "x64":
|
|
34
|
+
arch = "x64"
|
|
35
|
+
break
|
|
36
|
+
case "arm64":
|
|
37
|
+
arch = "arm64"
|
|
38
|
+
break
|
|
39
|
+
case "arm":
|
|
40
|
+
arch = "arm"
|
|
41
|
+
break
|
|
42
|
+
default:
|
|
43
|
+
arch = os.arch()
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { platform, arch }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function findBinary() {
|
|
51
|
+
const { platform, arch } = detectPlatformAndArch()
|
|
52
|
+
const packageName = `lingeebuild-${platform}-${arch}`
|
|
53
|
+
const binaryName = platform === "windows" ? "lingeebuild.exe" : "lingeebuild"
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// Use require.resolve to find the package
|
|
57
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
58
|
+
const packageDir = path.dirname(packageJsonPath)
|
|
59
|
+
const binaryPath = path.join(packageDir, "bin", binaryName)
|
|
60
|
+
|
|
61
|
+
if (!fs.existsSync(binaryPath)) {
|
|
62
|
+
throw new Error(`Binary not found at ${binaryPath}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { binaryPath, binaryName, packageDir }
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`Could not find package ${packageName}: ${error.message}`, { cause: error })
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function main() {
|
|
72
|
+
try {
|
|
73
|
+
if (os.platform() === "win32") {
|
|
74
|
+
// On Windows, the .exe is already included in the package and bin field points to it
|
|
75
|
+
// No postinstall setup needed
|
|
76
|
+
console.log("Windows detected: binary setup not needed (using packaged .exe)")
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// On non-Windows platforms, just verify the binary package exists
|
|
81
|
+
// Don't replace the wrapper script - it handles binary execution
|
|
82
|
+
const { binaryPath, packageDir } = findBinary()
|
|
83
|
+
const target = path.join(__dirname, "bin", ".lingeebuild")
|
|
84
|
+
if (fs.existsSync(target)) fs.unlinkSync(target)
|
|
85
|
+
try {
|
|
86
|
+
fs.linkSync(binaryPath, target)
|
|
87
|
+
} catch {
|
|
88
|
+
fs.copyFileSync(binaryPath, target)
|
|
89
|
+
}
|
|
90
|
+
fs.chmodSync(target, 0o755)
|
|
91
|
+
|
|
92
|
+
// 平台包 bin/lib 随带兼容老发行版的 libstdc++;复制到 wrapper 的 bin/lib,
|
|
93
|
+
// wrapper 启动二进制时注入 LD_LIBRARY_PATH(硬链接路径下同样生效)。
|
|
94
|
+
const libSrc = path.join(packageDir, "bin", "lib")
|
|
95
|
+
if (fs.existsSync(libSrc)) {
|
|
96
|
+
const libDest = path.join(__dirname, "bin", "lib")
|
|
97
|
+
fs.mkdirSync(libDest, { recursive: true })
|
|
98
|
+
for (const file of fs.readdirSync(libSrc)) {
|
|
99
|
+
const dest = path.join(libDest, file)
|
|
100
|
+
if (fs.existsSync(dest)) fs.unlinkSync(dest)
|
|
101
|
+
try {
|
|
102
|
+
fs.linkSync(path.join(libSrc, file), dest)
|
|
103
|
+
} catch {
|
|
104
|
+
fs.copyFileSync(path.join(libSrc, file), dest)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error("Failed to setup lingeebuild binary:", error.message)
|
|
110
|
+
process.exit(1)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
void main()
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error("Postinstall script error:", error.message)
|
|
118
|
+
process.exit(0)
|
|
119
|
+
}
|