@zleap-ai/app-cli 0.0.0-stage → 0.10.1

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 CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @zleap-ai/app-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ zleapOS 云开发命令行工具 `zleap-app` 的 npm 发行版。安装时 npm 只会下载与你的系统匹配的那一个预编译二进制
4
+ (`@zleap-ai/app-cli-<os>-<arch>`),不需要 Go 环境。
5
+
6
+ ```bash
7
+ npx @zleap-ai/app-cli # 查看版本与命令列表
8
+ npm i -D @zleap-ai/app-cli # 作为项目开发依赖(脚手架默认已加)
9
+ npx zleap-app check ./dist
10
+ ```
11
+
12
+ 支持平台:macOS(arm64 / x64)、Linux(x64 / arm64)、Windows(x64 / arm64)。
13
+
14
+ ## 常用命令
15
+
16
+ | 阶段 | 命令 |
17
+ | -------- | -------------------------------------------------------------------- |
18
+ | 登录 | `zleap-app auth login --target https://os.example.com --app-key <appid>`(appid 在云开发控制台「创建应用」获得) |
19
+ | 检查打包 | `zleap-app check <目录或zip>`、`zleap-app pack <目录> --output app.zip` |
20
+ | 上传安装 | `zleap-app publish <目录或zip>`、`zleap-app install <app_id>` |
21
+ | 资源准备 | `zleap-app prepare <app_id> --version-id <id> --request-id <32位hex>` |
22
+ | 诊断 | `zleap-app diagnose <app_id>`、`zleap-app runtime-logs <app_id>` |
23
+ | 版本 | `zleap-app versions / update / rollback / uninstall <app_id>` |
24
+ | 上架 | `zleap-app market-publish <package_id> --app-key <key>` |
25
+ | MCP | `zleap-app mcp serve --workspace <绝对路径> --target <OS 地址>` |
26
+
27
+ 完整说明见 zleapOS 云开发文档「从开发到上线」。
28
+
29
+ ## 排障
30
+
31
+ - **找不到平台包**:安装时不要使用 `--no-optional` / `--omit=optional`;跨平台拷贝 `node_modules` 后需重新安装。
32
+ - **自行构建的二进制**:设置环境变量 `ZLEAP_APP_BINARY=/path/to/zleap-app`,入口会直接使用它。
33
+ - 退出码与原生 CLI 一致:`2` 为普通失败,`6` 为 `COMMIT_UNKNOWN`(结果未知,先查询原操作,不要直接重试)。
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // zleap-app 的 npm 入口:找到当前平台的预编译二进制,原样透传参数、标准输入输出与退出码。
4
+ // MCP(zleap-app mcp serve)依赖 stdio 透传,这里不能向 stdout 写任何额外内容。
5
+
6
+ const { spawn } = require('node:child_process');
7
+ const { resolveBinary, BinaryNotFoundError } = require('../lib/resolve.js');
8
+
9
+ let binary;
10
+ try {
11
+ binary = resolveBinary();
12
+ } catch (error) {
13
+ if (error instanceof BinaryNotFoundError) {
14
+ process.stderr.write(`zleap-app: ${error.message}\n`);
15
+ process.exit(127);
16
+ }
17
+ throw error;
18
+ }
19
+
20
+ const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit', windowsHide: true });
21
+
22
+ const forward = (signal) => {
23
+ if (!child.killed) child.kill(signal);
24
+ };
25
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
26
+ process.on(signal, () => forward(signal));
27
+ }
28
+
29
+ child.on('error', (error) => {
30
+ process.stderr.write(`zleap-app: 无法启动 ${binary}:${error.message}\n`);
31
+ process.exit(127);
32
+ });
33
+
34
+ child.on('exit', (code, signal) => {
35
+ if (signal) {
36
+ process.removeAllListeners(signal);
37
+ process.kill(process.pid, signal);
38
+ return;
39
+ }
40
+ process.exit(code ?? 1);
41
+ });
package/lib/resolve.js ADDED
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+ // 解析当前平台对应的 zleap-app 预编译二进制。
3
+ // 查找顺序:ZLEAP_APP_BINARY 环境变量 → 平台子包(optionalDependencies)→ 报错并给出修复建议。
4
+ // 不在安装阶段联网下载,也不回退到其他平台的二进制。
5
+
6
+ const fs = require('node:fs');
7
+ const path = require('node:path');
8
+
9
+ // 平台子包命名为「主包名-平台-架构」,主包改名(kit.config.json)时自动跟随。
10
+ const BASE = require('../package.json').name;
11
+
12
+ const SUPPORTED = new Set([
13
+ 'darwin-arm64',
14
+ 'darwin-x64',
15
+ 'linux-x64',
16
+ 'linux-arm64',
17
+ 'win32-x64',
18
+ 'win32-arm64',
19
+ ]);
20
+
21
+ function platformKey(platform = process.platform, arch = process.arch) {
22
+ return `${platform}-${arch}`;
23
+ }
24
+
25
+ function binaryName(platform = process.platform) {
26
+ return platform === 'win32' ? 'zleap-app.exe' : 'zleap-app';
27
+ }
28
+
29
+ function platformPackage(platform = process.platform, arch = process.arch) {
30
+ return `${BASE}-${platformKey(platform, arch)}`;
31
+ }
32
+
33
+ class BinaryNotFoundError extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = 'BinaryNotFoundError';
37
+ }
38
+ }
39
+
40
+ function resolveBinary(options = {}) {
41
+ const env = options.env || process.env;
42
+ const platform = options.platform || process.platform;
43
+ const arch = options.arch || process.arch;
44
+ const requireResolve = options.resolve || require.resolve;
45
+
46
+ const override = env.ZLEAP_APP_BINARY;
47
+ if (override) {
48
+ if (!fs.existsSync(override)) {
49
+ throw new BinaryNotFoundError(`ZLEAP_APP_BINARY 指向的文件不存在:${override}`);
50
+ }
51
+ return override;
52
+ }
53
+
54
+ const key = platformKey(platform, arch);
55
+ if (!SUPPORTED.has(key)) {
56
+ throw new BinaryNotFoundError(
57
+ `暂不提供 ${key} 平台的 zleap-app 预编译版本。` +
58
+ '可以从源码构建(go build ./cmd/zleap-app),再通过环境变量 ZLEAP_APP_BINARY 指定路径。',
59
+ );
60
+ }
61
+
62
+ const pkg = platformPackage(platform, arch);
63
+ let manifestPath;
64
+ try {
65
+ manifestPath = requireResolve(`${pkg}/package.json`);
66
+ } catch {
67
+ throw new BinaryNotFoundError(
68
+ `没有找到平台包 ${pkg}。\n` +
69
+ '常见原因:安装时使用了 --no-optional / --omit=optional,或在另一个平台上安装后拷贝了 node_modules。\n' +
70
+ `修复:重新安装依赖(不要省略 optionalDependencies),或执行 npm install ${pkg}。`,
71
+ );
72
+ }
73
+ const binary = path.join(path.dirname(manifestPath), 'bin', binaryName(platform));
74
+ if (!fs.existsSync(binary)) {
75
+ throw new BinaryNotFoundError(`平台包 ${pkg} 已安装,但缺少可执行文件:${binary}`);
76
+ }
77
+ return binary;
78
+ }
79
+
80
+ module.exports = { resolveBinary, platformKey, platformPackage, binaryName, BinaryNotFoundError, SUPPORTED };
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@zleap-ai/app-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.10.1",
4
+ "description": "zleapOS 云开发命令行工具 zleap-app(init / check / pack / publish / install / prepare / test / MCP),按平台自动选用预编译二进制",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/RuoFeng2015/zleap-app-kit.git",
9
+ "directory": "packages/app-cli"
10
+ },
11
+ "type": "commonjs",
12
+ "bin": {
13
+ "zleap-app": "bin/zleap-app.js"
14
+ },
15
+ "main": "lib/resolve.js",
16
+ "files": [
17
+ "bin",
18
+ "lib",
19
+ "README.md"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "optionalDependencies": {
25
+ "@zleap-ai/app-cli-darwin-arm64": "0.10.1",
26
+ "@zleap-ai/app-cli-darwin-x64": "0.10.1",
27
+ "@zleap-ai/app-cli-linux-x64": "0.10.1",
28
+ "@zleap-ai/app-cli-linux-arm64": "0.10.1",
29
+ "@zleap-ai/app-cli-win32-x64": "0.10.1",
30
+ "@zleap-ai/app-cli-win32-arm64": "0.10.1"
31
+ },
32
+ "keywords": [
33
+ "zleap",
34
+ "zleapos",
35
+ "app-cloud",
36
+ "cli",
37
+ "mcp"
38
+ ]
39
+ }