@ziniao-open/cli 0.1.0-beta.98 → 0.1.1-beta.5
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/README.md +8 -37
- package/package.json +4 -2
- package/scripts/install.js +42 -1
- package/scripts/legacy-cli.js +179 -0
- package/scripts/remove-ziniao-cli-shims.sh +82 -0
- package/scripts/setup-ziniao-cli.sh +85 -50
package/README.md
CHANGED
|
@@ -10,37 +10,16 @@
|
|
|
10
10
|
npm install -g @ziniao-open/cli
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
source "$(npm root -g)/@ziniao-open/cli/scripts/setup-ziniao-cli.sh"
|
|
17
|
-
```
|
|
13
|
+
安装时会自动下载当前平台对应的预编译二进制(支持 macOS / Linux / Windows × amd64 / arm64),并做 SHA-256 校验。
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
全局安装或更新时会自动清理同一 npm 前缀内的旧包 `@ziniao-agent/cli`、`zn-open-eco` 入口,以及已识别的旧版紫鸟技能,并告知清理结果。同名新版技能会保留,后续统一使用 `ziniao-cli`。本地项目依赖安装不执行这项清理。
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
. "$(npm root -g)\@ziniao-open\cli\scripts\setup-ziniao-cli.ps1"
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
也可以在安装后手动修复:
|
|
17
|
+
如果同时使用紫鸟桌面客户端,安装后可执行 `ziniao-cli doctor` 检查环境;PATH 异常时可用:
|
|
26
18
|
|
|
27
19
|
```bash
|
|
28
20
|
ziniao-cli doctor fix-path
|
|
29
21
|
```
|
|
30
22
|
|
|
31
|
-
遍历当前 PATH 并清理正式目录之外的 `ziniao.exe` 文件(默认只预览):
|
|
32
|
-
|
|
33
|
-
```powershell
|
|
34
|
-
& "$(npm root -g)\@ziniao-open\cli\scripts\remove-ziniao-cli-shims.ps1"
|
|
35
|
-
& "$(npm root -g)\@ziniao-open\cli\scripts\remove-ziniao-cli-shims.ps1" -Apply
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
脚本只探测 `ziniao.app` / `ziniao` 的安装目录;Windows 会优先查询卸载注册表中 `DisplayIcon` 包含 `ziniao.exe` 的条目,再从本体目录的 `resources/app.asar.unpacked/envkit/cli` 查找 CLI。Windows 使用 `%APPDATA%\ziniaobrowser\cli`,macOS/Linux 使用 `~/.local/bin`,在目标目录缺少 CLI 或文件内容发生变化时同步最新文件,并注册当前用户 PATH。找不到源文件时只提示并继续,不阻断 PATH 配置。若安装目录无法自动探测,可设置 `ZINIAO_INSTALL_DIR`;若目标位置不同,可设置 `ZINIAO_APP_CACHE_DIR`。
|
|
39
|
-
Windows 同时会把找到的紫鸟本体绝对路径写入 `%APPDATA%\ziniaobrowser\gui-path`,供 CLI 定位桌面客户端。
|
|
40
|
-
macOS/Linux 也会在找到桌面本体时写入对应的 `gui-path`(macOS 为 `~/Library/Application Support/ziniao/gui-path`,Linux 为 `${XDG_CONFIG_HOME:-~/.config}/ziniao/gui-path`)。
|
|
41
|
-
|
|
42
|
-
安装时会自动下载当前平台对应的预编译二进制(支持 macOS / Linux / Windows × amd64 / arm64),并做 SHA-256 校验。
|
|
43
|
-
|
|
44
23
|
## 快速开始
|
|
45
24
|
|
|
46
25
|
```bash
|
|
@@ -67,29 +46,21 @@ ziniao-cli --help
|
|
|
67
46
|
| 类别 | 命令 | 说明 |
|
|
68
47
|
|------|------|------|
|
|
69
48
|
| 基础 | `config` | apiKey 等配置初始化与查看 |
|
|
70
|
-
| 基础 | `doctor` |
|
|
49
|
+
| 基础 | `doctor` | 环境自检(认证、紫鸟客户端、Skills、本地浏览器桥) |
|
|
71
50
|
| 基础 | `completion` | 生成 shell 自动补全 |
|
|
72
51
|
| 通用 | `api <path>` | 调用任意紫鸟 OpenAPI 路径 |
|
|
73
52
|
| 桥接 | `zclaw` | 本地浏览器 Bridge(页面操作、店铺管理等) |
|
|
74
53
|
| 快捷 | `staff` / `store` / `account` / `department` / `role` / `device` / `page` / `automation` | 高频业务操作的封装 |
|
|
75
54
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
## 开发版打包
|
|
55
|
+
`page exec` 支持简单表达式 `--script`、UTF-8 标准输入 `--stdin` 或标准 Base64 `--base64`,三种方式恰选一种。复杂脚本与 Windows/macOS/Linux 示例见 [页面脚本输入与执行](skills/ziniao-page/references/ziniao-page-dom.md#page-exec-的执行语义)。
|
|
79
56
|
|
|
80
|
-
|
|
57
|
+
页面执行支持视口/全页/局部截图,以及基于截图的坐标点击、鼠标移动和滚动。用法见 [截图与坐标操作](skills/ziniao-page/references/ziniao-page-coordinates.md)。
|
|
81
58
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
打包还会用同一版本更新仓库根目录的 `ziniao-cli`。因此已执行 `ziniao-cli-use dev` 后,无须重新切换,下一次运行 `ziniao-cli` 就会使用刚打包的开发版。
|
|
85
|
-
|
|
86
|
-
开发版内置测试环境 `https://test-sbappstoreapi.ziniao.com` 与 `https://test-open.ziniao.com`,并默认使用独立配置目录 `~/.ziniao-cli-dev/`。正式发布包内置生产环境,使用 `~/.ziniao-cli/`;两者的 API Key 和配置不会互相读取。开发版首次运行时执行 `ziniao-cli config init` 即可配置测试环境。
|
|
59
|
+
完整列表见 `ziniao-cli --help`。
|
|
87
60
|
|
|
88
61
|
## AI Agent Skills
|
|
89
62
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
安装 Skill:
|
|
63
|
+
仓库提供开箱即用的 AI Agent Skill,覆盖账号、店铺、员工、部门等常见操作。
|
|
93
64
|
|
|
94
65
|
```bash
|
|
95
66
|
ziniao-cli skills install
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ziniao-open/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-beta.5",
|
|
4
4
|
"description": "紫鸟开放平台命令行工具,为开发者和 AI Agent 提供统一的接口调用入口。",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"bin": {
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"scripts/install.js",
|
|
15
|
+
"scripts/legacy-cli.js",
|
|
15
16
|
"scripts/run.js",
|
|
16
17
|
"scripts/setup-ziniao-cli.sh",
|
|
17
18
|
"scripts/setup-ziniao-cli.ps1",
|
|
18
|
-
"scripts/remove-ziniao-cli-shims.ps1"
|
|
19
|
+
"scripts/remove-ziniao-cli-shims.ps1",
|
|
20
|
+
"scripts/remove-ziniao-cli-shims.sh"
|
|
19
21
|
],
|
|
20
22
|
"engines": {
|
|
21
23
|
"node": ">=18"
|
package/scripts/install.js
CHANGED
|
@@ -29,7 +29,7 @@ const {
|
|
|
29
29
|
statSync,
|
|
30
30
|
unlinkSync,
|
|
31
31
|
} = require("node:fs");
|
|
32
|
-
const { basename, dirname, join } = require("node:path");
|
|
32
|
+
const { basename, dirname, join, relative } = require("node:path");
|
|
33
33
|
const { tmpdir } = require("node:os");
|
|
34
34
|
const { spawnSync } = require("node:child_process");
|
|
35
35
|
const { createHash } = require("node:crypto");
|
|
@@ -37,6 +37,8 @@ const https = require("node:https");
|
|
|
37
37
|
const http = require("node:http");
|
|
38
38
|
const { URL } = require("node:url");
|
|
39
39
|
|
|
40
|
+
const { findLegacyCLI, npmScope, uninstallLegacyPackage, cleanupLegacyLaunchers, scheduleLegacyVoltaCleanup } = require("./legacy-cli");
|
|
41
|
+
|
|
40
42
|
const PKG = require("../package.json");
|
|
41
43
|
const REPO_ROOT = join(__dirname, "..");
|
|
42
44
|
const BIN_DIR = join(REPO_ROOT, "bin");
|
|
@@ -300,7 +302,46 @@ async function main() {
|
|
|
300
302
|
await downloadAndInstall();
|
|
301
303
|
}
|
|
302
304
|
|
|
305
|
+
const pendingCleanup = await cleanLegacyComponents();
|
|
303
306
|
runDesktopCliSetup();
|
|
307
|
+
reportLegacyCLI(pendingCleanup);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async function cleanLegacyComponents() {
|
|
311
|
+
const scope = npmScope();
|
|
312
|
+
if (!scope) return; // Automatic migration is limited to global npm installs.
|
|
313
|
+
const args = ["skills", "cleanup-legacy"];
|
|
314
|
+
if (process.env.INIT_CWD) args.push("--project-dir", process.env.INIT_CWD);
|
|
315
|
+
// Clean skills first, while links into the old package can still be identified.
|
|
316
|
+
const result = spawnSync(TARGET_PATH, args, {
|
|
317
|
+
encoding: "utf8", windowsHide: true, timeout: 60000,
|
|
318
|
+
});
|
|
319
|
+
if (result.error || result.status !== 0) {
|
|
320
|
+
throw new Error(`旧技能自动清理失败: ${result.error?.message || result.stderr?.trim() || result.status}`);
|
|
321
|
+
}
|
|
322
|
+
const report = JSON.parse(result.stdout);
|
|
323
|
+
if (!report.ok || !Array.isArray(report.data?.removed)) throw new Error("旧技能清理结果无效");
|
|
324
|
+
for (const path of report.data.removed) log(`已清理旧技能: ${path}`);
|
|
325
|
+
const oldPackageRemoved = uninstallLegacyPackage({ scope });
|
|
326
|
+
if (oldPackageRemoved) log("已清理旧 npm 包: @ziniao-agent/cli");
|
|
327
|
+
const removed = cleanupLegacyLaunchers({ binDir: scope.binDir });
|
|
328
|
+
for (const path of removed) log(`已清理旧入口: ${path}`);
|
|
329
|
+
log(`当前 npm 范围旧版清理完成:旧技能 ${report.data.removed.length} 个,旧 npm 包 ${oldPackageRemoved ? 1 : 0} 个,残留入口 ${removed.length} 个。`);
|
|
330
|
+
const pendingCleanup = await scheduleLegacyVoltaCleanup({ scope });
|
|
331
|
+
if (pendingCleanup) log(`Volta 旧包清理已安排,结果日志: ${pendingCleanup.logPath}`);
|
|
332
|
+
return pendingCleanup;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function reportLegacyCLI(pendingCleanup) {
|
|
336
|
+
try {
|
|
337
|
+
const paths = findLegacyCLI();
|
|
338
|
+
for (const path of paths) {
|
|
339
|
+
if (pendingCleanup && relative(pendingCleanup.binDir, dirname(path)) === "") continue;
|
|
340
|
+
warn(`其他安装范围仍有旧入口,本次未清理: ${path}`);
|
|
341
|
+
}
|
|
342
|
+
} catch (err) {
|
|
343
|
+
warn(`旧 CLI 检查未完成: ${err.message}`);
|
|
344
|
+
}
|
|
304
345
|
}
|
|
305
346
|
|
|
306
347
|
main().catch((err) => fail(err.stack || err.message || String(err)));
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
const { statSync, lstatSync, readFileSync, unlinkSync, existsSync, mkdirSync, mkdtempSync, copyFileSync, openSync, closeSync, writeFileSync, appendFileSync } = require("node:fs");
|
|
2
|
+
const { join, resolve, dirname, isAbsolute, relative, delimiter } = require("node:path");
|
|
3
|
+
const { homedir } = require("node:os");
|
|
4
|
+
const { spawn, spawnSync } = require("node:child_process");
|
|
5
|
+
|
|
6
|
+
const LEGACY_PACKAGE = "@ziniao-agent/cli";
|
|
7
|
+
|
|
8
|
+
function legacyNames(platform) {
|
|
9
|
+
return platform === "win32"
|
|
10
|
+
? ["zn-open-eco", "zn-open-eco.exe", "zn-open-eco.cmd", "zn-open-eco.ps1", "zn-open-eco.bat"]
|
|
11
|
+
: ["zn-open-eco"];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Inspect names only. Never execute or replace an old binary or npm shim.
|
|
15
|
+
function findLegacyCLI({ path = process.env.PATH || "", platform = process.platform } = {}) {
|
|
16
|
+
const separator = platform === "win32" ? ";" : ":";
|
|
17
|
+
const found = new Set();
|
|
18
|
+
for (const dir of path.split(separator)) {
|
|
19
|
+
if (!dir) continue;
|
|
20
|
+
for (const name of legacyNames(platform)) {
|
|
21
|
+
const candidate = join(dir, name);
|
|
22
|
+
try {
|
|
23
|
+
if (statSync(candidate).isFile()) found.add(candidate);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (err.code !== "ENOENT" && err.code !== "ENOTDIR") throw err;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return [...found].sort();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function npmScope({ env = process.env, platform = process.platform } = {}) {
|
|
33
|
+
// Local postinstall must not re-enter npm's in-progress dependency transaction.
|
|
34
|
+
if (env.npm_config_global !== "true") return null;
|
|
35
|
+
const prefix = env.npm_config_prefix;
|
|
36
|
+
if (!prefix || !isAbsolute(prefix)) throw new Error("npm global prefix must be absolute");
|
|
37
|
+
return {
|
|
38
|
+
global: true, prefix,
|
|
39
|
+
modules: platform === "win32" ? join(prefix, "node_modules") : join(prefix, "lib", "node_modules"),
|
|
40
|
+
binDir: platform === "win32" ? prefix : join(prefix, "bin"),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Remove the old package through the same npm and prefix as this installation.
|
|
45
|
+
// Disabling lifecycle scripts prevents legacy hooks from running during cleanup.
|
|
46
|
+
function uninstallLegacyPackage({ scope, env = process.env }) {
|
|
47
|
+
if (!scope?.global) return false;
|
|
48
|
+
const oldPackage = join(scope.modules, "@ziniao-agent", "cli");
|
|
49
|
+
if (!existsSync(oldPackage)) return false;
|
|
50
|
+
const metadata = JSON.parse(readFileSync(join(oldPackage, "package.json"), "utf8"));
|
|
51
|
+
if (metadata.name !== "@ziniao-agent/cli") throw new Error(`unexpected old package at ${oldPackage}`);
|
|
52
|
+
if (!env.npm_execpath || !isAbsolute(env.npm_execpath)) throw new Error("npm lifecycle executable is unavailable");
|
|
53
|
+
const args = [env.npm_execpath, "uninstall", "@ziniao-agent/cli", "--prefix", scope.prefix,
|
|
54
|
+
"--ignore-scripts", "--offline", "--no-audit", "--no-fund"];
|
|
55
|
+
args.push("--global");
|
|
56
|
+
const result = spawnSync(process.execPath, args, {
|
|
57
|
+
cwd: scope.prefix, env, encoding: "utf8", windowsHide: true, timeout: 60000,
|
|
58
|
+
});
|
|
59
|
+
if (result.error || result.status !== 0 || existsSync(oldPackage)) {
|
|
60
|
+
throw new Error(`旧包自动清理失败: ${result.error?.message || result.stderr?.trim() || result.status}`);
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function voltaPackageRoot(home) {
|
|
66
|
+
const modules = process.platform === "win32" ? "node_modules" : "lib/node_modules";
|
|
67
|
+
return join(home, "tools", "image", "packages", LEGACY_PACKAGE, modules, LEGACY_PACKAGE);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A Volta npm lifecycle uses a staging prefix, not the installed package image.
|
|
71
|
+
// Match only this installation's Volta home; an explicit unrelated prefix is out of scope.
|
|
72
|
+
function activeVoltaHome(scope, env) {
|
|
73
|
+
if (!scope?.global) return null;
|
|
74
|
+
const home = env.VOLTA_HOME || (process.platform === "win32"
|
|
75
|
+
? join(env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "Volta")
|
|
76
|
+
: join(homedir(), ".volta"));
|
|
77
|
+
if (!isAbsolute(home)) return null;
|
|
78
|
+
const prefix = relative(home, scope.prefix).split("\\").join("/");
|
|
79
|
+
return /^tmp\/image\/packages\/(?:scope\/)?[^/]+$/.test(prefix)
|
|
80
|
+
|| prefix === "tools/image/packages/@ziniao-open/cli" ? home : null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function scheduleLegacyVoltaCleanup({ scope, env = process.env }) {
|
|
84
|
+
const home = activeVoltaHome(scope, env);
|
|
85
|
+
if (!home) return null;
|
|
86
|
+
const old = voltaPackageRoot(home);
|
|
87
|
+
if (!existsSync(old)) return null;
|
|
88
|
+
const metadata = JSON.parse(readFileSync(join(old, "package.json"), "utf8"));
|
|
89
|
+
if (metadata.name !== LEGACY_PACKAGE) throw new Error(`unexpected old package at ${old}`);
|
|
90
|
+
const name = process.platform === "win32" ? "volta.exe" : "volta";
|
|
91
|
+
// Windows environment keys are case-insensitive; match Node's spawn ordering.
|
|
92
|
+
const pathKey = Object.keys(env).sort().find((key) => key.toLowerCase() === "path");
|
|
93
|
+
const candidates = [join(home, "bin"), ...(env[pathKey] || "").split(delimiter)];
|
|
94
|
+
const executable = candidates.filter(isAbsolute).map((dir) => join(dir, name)).find((path) => {
|
|
95
|
+
try { return statSync(path).isFile(); } catch (err) {
|
|
96
|
+
if (err.code === "ENOENT" || err.code === "ENOTDIR") return false;
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (!executable) throw new Error("Volta 旧包清理未启动:找不到 volta 可执行文件");
|
|
101
|
+
|
|
102
|
+
// Volta moves staging after postinstall. Both the worker and its cwd must live elsewhere.
|
|
103
|
+
mkdirSync(join(home, "tmp"), { recursive: true });
|
|
104
|
+
const work = mkdtempSync(join(home, "tmp", "ziniao-legacy-cleanup-"));
|
|
105
|
+
const worker = join(work, "worker.js");
|
|
106
|
+
const logPath = join(work, "result.log");
|
|
107
|
+
copyFileSync(__filename, worker);
|
|
108
|
+
writeFileSync(logPath, JSON.stringify({ status: "scheduled", package: LEGACY_PACKAGE }) + "\n");
|
|
109
|
+
const output = openSync(logPath, "a");
|
|
110
|
+
try {
|
|
111
|
+
const child = spawn(process.execPath, [worker, "--volta-cleanup", executable], {
|
|
112
|
+
cwd: home, env: { ...env, VOLTA_HOME: home }, detached: true, windowsHide: true,
|
|
113
|
+
stdio: ["ignore", output, output],
|
|
114
|
+
});
|
|
115
|
+
// Wait for process creation only, never for the manager lock or uninstall completion.
|
|
116
|
+
await new Promise((done, reject) => {
|
|
117
|
+
child.once("error", reject);
|
|
118
|
+
child.once("spawn", () => { child.unref(); done(); });
|
|
119
|
+
});
|
|
120
|
+
} catch (err) {
|
|
121
|
+
appendFileSync(logPath, JSON.stringify({ status: "failed", message: err.message }) + "\n");
|
|
122
|
+
unlinkSync(worker);
|
|
123
|
+
throw err;
|
|
124
|
+
} finally {
|
|
125
|
+
closeSync(output);
|
|
126
|
+
}
|
|
127
|
+
return { status: "scheduled", logPath, binDir: join(home, "bin") };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function runLegacyVoltaCleanup(executable) {
|
|
131
|
+
try {
|
|
132
|
+
const old = voltaPackageRoot(process.env.VOLTA_HOME);
|
|
133
|
+
if (existsSync(old)) {
|
|
134
|
+
const metadata = JSON.parse(readFileSync(join(old, "package.json"), "utf8"));
|
|
135
|
+
if (metadata.name !== LEGACY_PACKAGE) throw new Error(`unexpected old package at ${old}`);
|
|
136
|
+
// The parent install holds Volta's lock. This independent worker can wait for it.
|
|
137
|
+
// Call Volta directly: npm in a lifecycle PATH can bypass Volta's shim.
|
|
138
|
+
const result = spawnSync(executable, ["uninstall", LEGACY_PACKAGE], {
|
|
139
|
+
encoding: "utf8", windowsHide: true, timeout: 60000, killSignal: "SIGKILL",
|
|
140
|
+
});
|
|
141
|
+
if (result.error || result.status !== 0 || existsSync(old)) {
|
|
142
|
+
throw new Error(result.error?.message || result.stderr?.trim() || `exit=${result.status}; old package remains`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
console.log(JSON.stringify({ status: "succeeded", package: LEGACY_PACKAGE }));
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error(JSON.stringify({ status: "failed", package: LEGACY_PACKAGE, message: err.message }));
|
|
148
|
+
process.exitCode = 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Delete fixed retired command names in this npm scope. Unlinking a symlink
|
|
153
|
+
// removes its entry only; its target and other npm scopes are left intact.
|
|
154
|
+
function cleanupLegacyLaunchers({ binDir, platform = process.platform }) {
|
|
155
|
+
if (!binDir) return [];
|
|
156
|
+
if (!isAbsolute(binDir)) throw new Error("cleanup bin directory must be absolute");
|
|
157
|
+
const removed = [];
|
|
158
|
+
for (const name of legacyNames(platform)) {
|
|
159
|
+
const path = resolve(binDir, name);
|
|
160
|
+
if (dirname(path) !== resolve(binDir)) throw new Error("launcher escapes npm bin directory");
|
|
161
|
+
let info;
|
|
162
|
+
try {
|
|
163
|
+
info = lstatSync(path);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (err.code === "ENOENT" || err.code === "ENOTDIR") continue;
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
if (!info.isFile() && !info.isSymbolicLink()) throw new Error(`旧入口不是文件或链接: ${path}`);
|
|
169
|
+
unlinkSync(path);
|
|
170
|
+
removed.push(path);
|
|
171
|
+
}
|
|
172
|
+
return removed;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
module.exports = { findLegacyCLI, npmScope, uninstallLegacyPackage, cleanupLegacyLaunchers, scheduleLegacyVoltaCleanup };
|
|
176
|
+
|
|
177
|
+
if (require.main === module && process.argv[2] === "--volta-cleanup") {
|
|
178
|
+
runLegacyVoltaCleanup(process.argv[3]);
|
|
179
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Find and optionally remove ziniao shims created in PATH directories.
|
|
3
|
+
# Run without --apply first to preview the files that would be removed.
|
|
4
|
+
|
|
5
|
+
apply=0
|
|
6
|
+
if [ "${1:-}" = "--apply" ]; then
|
|
7
|
+
apply=1
|
|
8
|
+
elif [ -n "${1:-}" ]; then
|
|
9
|
+
printf '%s\n' "[ziniao-cli-shims] ERROR: unsupported option: $1" >&2
|
|
10
|
+
exit 2
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
log() { printf '%s\n' "[ziniao-cli-shims] $*"; }
|
|
14
|
+
|
|
15
|
+
home_dir="${HOME:?HOME is not set}"
|
|
16
|
+
platform="$(uname -s 2>/dev/null || printf 'unknown')"
|
|
17
|
+
case "$platform" in
|
|
18
|
+
Darwin) default_dir="$home_dir/Library/Application Support/ziniaobrowser/cli" ;;
|
|
19
|
+
Linux) default_dir="${XDG_CONFIG_HOME:-$home_dir/.config}/ziniaobrowser/cli" ;;
|
|
20
|
+
*)
|
|
21
|
+
log "ERROR: unsupported operating system: $platform"
|
|
22
|
+
exit 1
|
|
23
|
+
;;
|
|
24
|
+
esac
|
|
25
|
+
|
|
26
|
+
target_dir="${ZINIAO_APP_CACHE_DIR:-${default_dir%/cli}}/cli"
|
|
27
|
+
found=0
|
|
28
|
+
old_ifs="$IFS"
|
|
29
|
+
IFS=:
|
|
30
|
+
for path_entry in ${PATH:-}; do
|
|
31
|
+
IFS="$old_ifs"
|
|
32
|
+
directory="${path_entry%/}"
|
|
33
|
+
[ -n "$directory" ] || continue
|
|
34
|
+
[ "$directory" = "${target_dir%/}" ] && continue
|
|
35
|
+
shim_path="$directory/ziniao"
|
|
36
|
+
[ -e "$shim_path" ] || [ -L "$shim_path" ] || continue
|
|
37
|
+
found=1
|
|
38
|
+
if [ "$apply" -eq 1 ]; then
|
|
39
|
+
rm -f -- "$shim_path"
|
|
40
|
+
log "Removed: $shim_path"
|
|
41
|
+
else
|
|
42
|
+
log "Would remove: $shim_path"
|
|
43
|
+
fi
|
|
44
|
+
IFS=:
|
|
45
|
+
done
|
|
46
|
+
IFS="$old_ifs"
|
|
47
|
+
|
|
48
|
+
stable_shim="$home_dir/.local/bin/ziniao"
|
|
49
|
+
if [ -e "$stable_shim" ] || [ -L "$stable_shim" ]; then
|
|
50
|
+
if [ "$stable_shim" != "$target_dir/ziniao" ]; then
|
|
51
|
+
found=1
|
|
52
|
+
if [ "$apply" -eq 1 ]; then
|
|
53
|
+
rm -f -- "$stable_shim"
|
|
54
|
+
log "Removed: $stable_shim"
|
|
55
|
+
else
|
|
56
|
+
log "Would remove: $stable_shim"
|
|
57
|
+
fi
|
|
58
|
+
fi
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
cache_found=0
|
|
62
|
+
if [ -d "$target_dir" ]; then
|
|
63
|
+
cache_found=1
|
|
64
|
+
if [ "$apply" -eq 1 ]; then
|
|
65
|
+
if [ -f "$target_dir/ziniao" ] || [ -L "$target_dir/ziniao" ]; then
|
|
66
|
+
rm -f -- "$target_dir/ziniao"
|
|
67
|
+
fi
|
|
68
|
+
if rmdir "$target_dir" 2>/dev/null; then
|
|
69
|
+
log "Removed CLI cache directory: $target_dir"
|
|
70
|
+
else
|
|
71
|
+
log "WARN: CLI cache directory is not empty; keeping it: $target_dir"
|
|
72
|
+
fi
|
|
73
|
+
else
|
|
74
|
+
log "Would remove CLI cache directory: $target_dir"
|
|
75
|
+
fi
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
if [ "$found" -eq 0 ] && [ "$cache_found" -eq 0 ]; then
|
|
79
|
+
log "No ziniao shims found in PATH directories."
|
|
80
|
+
elif [ "$apply" -eq 0 ]; then
|
|
81
|
+
log "Preview only. Re-run with --apply to remove these files."
|
|
82
|
+
fi
|
|
@@ -29,59 +29,66 @@ case "$platform" in
|
|
|
29
29
|
Darwin) platform_dir="darwin"; source_name="ziniao"; ;;
|
|
30
30
|
Linux) platform_dir="linux"; source_name="ziniao"; ;;
|
|
31
31
|
MINGW*|MSYS*|CYGWIN*)
|
|
32
|
-
fail "
|
|
32
|
+
fail "Windows shell detected; use PowerShell: scripts/setup-ziniao-cli.ps1"
|
|
33
33
|
return 1 2>/dev/null || exit 1
|
|
34
34
|
;;
|
|
35
|
-
*) fail "
|
|
35
|
+
*) fail "Unsupported operating system: $platform"; return 1 2>/dev/null || exit 1 ;;
|
|
36
36
|
esac
|
|
37
37
|
|
|
38
38
|
case "$machine" in
|
|
39
39
|
arm64|aarch64) arch_dir="arm64" ;;
|
|
40
40
|
x86_64|amd64) arch_dir="x64" ;;
|
|
41
|
-
*) fail "
|
|
41
|
+
*) fail "Unsupported CPU architecture: $machine"; return 1 2>/dev/null || exit 1 ;;
|
|
42
42
|
esac
|
|
43
43
|
|
|
44
|
-
home_dir="${HOME
|
|
45
|
-
|
|
46
|
-
first_existing_dir() {
|
|
47
|
-
for candidate in "$@"; do
|
|
48
|
-
if [ -d "$candidate" ]; then
|
|
49
|
-
printf '%s\n' "$candidate"
|
|
50
|
-
return 0
|
|
51
|
-
fi
|
|
52
|
-
done
|
|
53
|
-
return 1
|
|
54
|
-
}
|
|
44
|
+
home_dir="${HOME:?HOME is not set}"
|
|
55
45
|
|
|
56
46
|
find_source() {
|
|
57
|
-
source_rel="envkit/cli/$platform_dir/$arch_dir/$source_name"
|
|
58
47
|
if [ -n "${ZINIAO_CLI_SOURCE:-}" ] && [ -f "$ZINIAO_CLI_SOURCE" ]; then
|
|
59
48
|
printf '%s\n' "$ZINIAO_CLI_SOURCE"
|
|
60
49
|
return 0
|
|
61
50
|
fi
|
|
62
51
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if [ -
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
for candidate_arch in "$arch_dir" x64 arm64; do
|
|
53
|
+
source_rel="envkit/cli/$platform_dir/$candidate_arch/$source_name"
|
|
54
|
+
if [ -n "${ZINIAO_INSTALL_DIR:-}" ]; then
|
|
55
|
+
candidate="$ZINIAO_INSTALL_DIR/$source_rel"
|
|
56
|
+
if [ -f "$candidate" ]; then
|
|
57
|
+
printf '%s\n' "$candidate"
|
|
58
|
+
return 0
|
|
59
|
+
fi
|
|
68
60
|
fi
|
|
69
|
-
fi
|
|
70
61
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
for install_root in \
|
|
63
|
+
"/Applications/ziniao.app/Contents/Resources/app.asar.unpacked" \
|
|
64
|
+
"$home_dir/Applications/ziniao.app/Contents/Resources/app.asar.unpacked" \
|
|
65
|
+
"$home_dir/Library/Application Support/ziniaobrowser/app.asar.unpacked" \
|
|
66
|
+
"/opt/ziniao/resources/app.asar.unpacked"; do
|
|
67
|
+
candidate="$install_root/$source_rel"
|
|
68
|
+
if [ -f "$candidate" ]; then
|
|
69
|
+
printf '%s\n' "$candidate"
|
|
70
|
+
return 0
|
|
71
|
+
fi
|
|
72
|
+
done
|
|
81
73
|
done
|
|
82
74
|
return 1
|
|
83
75
|
}
|
|
84
76
|
|
|
77
|
+
log_source_candidates() {
|
|
78
|
+
[ -n "${ZINIAO_CLI_SOURCE:-}" ] && log "Checked CLI source path: $ZINIAO_CLI_SOURCE"
|
|
79
|
+
for candidate_arch in "$arch_dir" x64 arm64; do
|
|
80
|
+
source_rel="envkit/cli/$platform_dir/$candidate_arch/$source_name"
|
|
81
|
+
[ -n "${ZINIAO_INSTALL_DIR:-}" ] && log "Checked CLI source path: $ZINIAO_INSTALL_DIR/$source_rel"
|
|
82
|
+
for install_root in \
|
|
83
|
+
"/Applications/ziniao.app/Contents/Resources/app.asar.unpacked" \
|
|
84
|
+
"$home_dir/Applications/ziniao.app/Contents/Resources/app.asar.unpacked" \
|
|
85
|
+
"$home_dir/Library/Application Support/ziniaobrowser/app.asar.unpacked" \
|
|
86
|
+
"/opt/ziniao/resources/app.asar.unpacked"; do
|
|
87
|
+
log "Checked CLI source path: $install_root/$source_rel"
|
|
88
|
+
done
|
|
89
|
+
done
|
|
90
|
+
}
|
|
91
|
+
|
|
85
92
|
find_gui_executable() {
|
|
86
93
|
case "$platform_dir" in
|
|
87
94
|
darwin)
|
|
@@ -109,8 +116,10 @@ find_gui_executable() {
|
|
|
109
116
|
if [ -n "${ZINIAO_APP_CACHE_DIR:-}" ]; then
|
|
110
117
|
target_dir="$ZINIAO_APP_CACHE_DIR/cli"
|
|
111
118
|
else
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
case "$platform_dir" in
|
|
120
|
+
darwin) target_dir="$home_dir/Library/Application Support/ziniaobrowser/cli" ;;
|
|
121
|
+
*) target_dir="${XDG_CONFIG_HOME:-$home_dir/.config}/ziniaobrowser/cli" ;;
|
|
122
|
+
esac
|
|
114
123
|
fi
|
|
115
124
|
|
|
116
125
|
source_path="$(find_source || true)"
|
|
@@ -118,51 +127,77 @@ gui_executable_path="$(find_gui_executable || true)"
|
|
|
118
127
|
target_path="$target_dir/$source_name"
|
|
119
128
|
mkdir -p "$target_dir"
|
|
120
129
|
|
|
130
|
+
if [ -n "$source_path" ]; then
|
|
131
|
+
log "CLI source path: $source_path"
|
|
132
|
+
else
|
|
133
|
+
log_source_candidates
|
|
134
|
+
fi
|
|
135
|
+
|
|
121
136
|
if [ -n "$gui_executable_path" ]; then
|
|
122
137
|
case "$platform_dir" in
|
|
123
|
-
darwin) gui_path_file="$home_dir/Library/Application Support/
|
|
138
|
+
darwin) gui_path_file="$home_dir/Library/Application Support/ziniaobrowser/gui-path" ;;
|
|
124
139
|
*)
|
|
125
140
|
xdg_config_home="${XDG_CONFIG_HOME:-$home_dir/.config}"
|
|
126
|
-
gui_path_file="$xdg_config_home/
|
|
141
|
+
gui_path_file="$xdg_config_home/ziniaobrowser/gui-path"
|
|
127
142
|
;;
|
|
128
143
|
esac
|
|
129
144
|
if mkdir -p "$(dirname "$gui_path_file")" && printf '%s\n' "$gui_executable_path" > "$gui_path_file"; then
|
|
130
|
-
log "
|
|
145
|
+
log "Wrote GUI path hint: $gui_path_file"
|
|
131
146
|
else
|
|
132
|
-
log "WARN:
|
|
147
|
+
log "WARN: Could not write GUI path hint: $gui_path_file"
|
|
133
148
|
fi
|
|
134
149
|
fi
|
|
135
150
|
if [ -z "$source_path" ]; then
|
|
136
151
|
if [ -f "$target_path" ]; then
|
|
137
|
-
log "
|
|
152
|
+
log "CLI source was not found in the install directory; keeping the existing AppCache CLI: $target_path"
|
|
138
153
|
else
|
|
139
|
-
log "WARN:
|
|
154
|
+
log "WARN: ${source_name} was not found in the install directory; skipping copy. Set ZINIAO_INSTALL_DIR or ZINIAO_CLI_SOURCE to override."
|
|
140
155
|
fi
|
|
141
156
|
elif [ ! -f "$target_path" ] || ! cmp -s "$source_path" "$target_path"; then
|
|
142
157
|
cp "$source_path" "$target_path"
|
|
143
158
|
chmod 755 "$target_path"
|
|
144
|
-
log "
|
|
159
|
+
log "Synced CLI: $source_path -> $target_path"
|
|
145
160
|
else
|
|
146
|
-
log "AppCache CLI
|
|
161
|
+
log "AppCache CLI is up to date: $target_path"
|
|
147
162
|
fi
|
|
148
163
|
|
|
149
164
|
shim_installed=0
|
|
150
165
|
install_path_shim() {
|
|
151
166
|
[ -f "$target_path" ] || return 0
|
|
167
|
+
shim_dir="$home_dir/.local/bin"
|
|
168
|
+
shim_path="$shim_dir/$source_name"
|
|
169
|
+
mkdir -p "$shim_dir"
|
|
170
|
+
if [ -L "$shim_path" ] && [ "$(readlink "$shim_path" 2>/dev/null || true)" = "$target_path" ]; then
|
|
171
|
+
shim_installed=1
|
|
172
|
+
log "The CLI shim already points to the AppCache CLI: $shim_path"
|
|
173
|
+
elif [ ! -e "$shim_path" ]; then
|
|
174
|
+
if ln -s "$target_path" "$shim_path" 2>/dev/null; then
|
|
175
|
+
shim_installed=1
|
|
176
|
+
log "Created the CLI shim: $shim_path"
|
|
177
|
+
else
|
|
178
|
+
log "WARN: Could not create the CLI shim: $shim_path"
|
|
179
|
+
fi
|
|
180
|
+
else
|
|
181
|
+
log "A file already exists at the CLI shim path; leaving it unchanged: $shim_path"
|
|
182
|
+
fi
|
|
152
183
|
case ":${PATH:-}:" in
|
|
153
184
|
*:"$target_dir":*)
|
|
154
185
|
shim_installed=1
|
|
155
|
-
log "
|
|
186
|
+
log "The current PATH already contains the AppCache CLI directory: $target_dir"
|
|
187
|
+
;;
|
|
188
|
+
*:"$shim_dir":*)
|
|
189
|
+
[ "$shim_installed" -eq 1 ] && log "The current PATH contains the CLI shim directory: $shim_dir"
|
|
156
190
|
;;
|
|
157
191
|
*)
|
|
158
|
-
log "AppCache CLI
|
|
192
|
+
log "The AppCache CLI directory is not on the current PATH; no shim will be created elsewhere: $target_dir"
|
|
159
193
|
;;
|
|
160
194
|
esac
|
|
161
195
|
}
|
|
162
196
|
|
|
163
197
|
install_path_shim
|
|
164
198
|
|
|
165
|
-
|
|
199
|
+
shim_dir="$home_dir/.local/bin"
|
|
200
|
+
export PATH="$target_dir:$shim_dir${PATH:+:$PATH}"
|
|
166
201
|
|
|
167
202
|
profile=""
|
|
168
203
|
case "${SHELL:-}" in
|
|
@@ -177,21 +212,21 @@ if [ -z "$profile" ]; then
|
|
|
177
212
|
fi
|
|
178
213
|
|
|
179
214
|
marker="# ziniao-cli: AppCache CLI PATH"
|
|
180
|
-
path_line="export PATH=\"$target_dir:\$PATH\""
|
|
215
|
+
path_line="export PATH=\"$target_dir:$shim_dir:\$PATH\""
|
|
181
216
|
if ! grep -Fqx "$marker" "$profile" 2>/dev/null; then
|
|
182
217
|
mkdir -p "$(dirname "$profile")"
|
|
183
218
|
printf '\n%s\n' "$marker" >> "$profile"
|
|
184
|
-
log "
|
|
219
|
+
log "Added to shell profile: $profile"
|
|
185
220
|
fi
|
|
186
221
|
if ! grep -Fqx "$path_line" "$profile" 2>/dev/null; then
|
|
187
222
|
printf '%s\n' "$path_line" >> "$profile"
|
|
188
223
|
fi
|
|
189
224
|
|
|
190
225
|
if [ "$shim_installed" -eq 1 ]; then
|
|
191
|
-
log "CLI
|
|
226
|
+
log "The CLI is already on the current PATH; this terminal needs no PATH refresh"
|
|
192
227
|
elif [ "$is_sourced" -eq 1 ]; then
|
|
193
|
-
log "
|
|
228
|
+
log "The current shell PATH was refreshed"
|
|
194
229
|
else
|
|
195
|
-
log "
|
|
230
|
+
log "The current process PATH was refreshed; source \"$profile\" in the parent terminal"
|
|
196
231
|
fi
|
|
197
|
-
log "
|
|
232
|
+
log "Verification command: command -v $source_name"
|