@lark-apaas/miaoda-cli 0.1.19-alpha.4bf5458 → 0.1.19-alpha.574dcb5
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 +34 -1
- package/dist/api/comment/api.js +42 -0
- package/dist/api/comment/index.js +6 -0
- package/dist/api/comment/types.js +2 -0
- package/dist/api/index.js +3 -1
- package/dist/cli/commands/comment/index.js +55 -0
- package/dist/cli/commands/deploy/modern.js +5 -3
- package/dist/cli/commands/index.js +8 -0
- package/dist/cli/commands/registry/index.js +102 -0
- package/dist/cli/handlers/app/init.js +6 -2
- package/dist/cli/handlers/comment/index.js +7 -0
- package/dist/cli/handlers/comment/list.js +62 -0
- package/dist/cli/handlers/comment/resolve.js +44 -0
- package/dist/cli/handlers/registry/add.js +54 -0
- package/dist/cli/handlers/registry/index.js +7 -0
- package/dist/cli/handlers/registry/list.js +48 -0
- package/dist/cli/handlers/registry/shared.js +25 -0
- package/dist/services/deploy/modern/patch/actions.js +4 -3
- package/dist/services/deploy/modern/patch/index.js +2 -2
- package/dist/services/deploy/modern/patch/routes.js +21 -12
- package/dist/services/registry/index.js +293 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,12 +11,17 @@ pnpm add -g @lark-apaas/miaoda-cli
|
|
|
11
11
|
## 使用
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
#
|
|
14
|
+
# 设置默认应用(需要应用上下文的命令从 MIAODA_APP_ID 读取)
|
|
15
15
|
export MIAODA_APP_ID=app_demo_xxx
|
|
16
16
|
|
|
17
17
|
# 文件操作
|
|
18
18
|
miaoda file ls
|
|
19
19
|
miaoda file upload ./local/path
|
|
20
|
+
|
|
21
|
+
# 评论操作
|
|
22
|
+
miaoda comment list --json
|
|
23
|
+
miaoda comment list --only-unresolved --json
|
|
24
|
+
miaoda comment resolve 1703677660120110076 --json
|
|
20
25
|
```
|
|
21
26
|
|
|
22
27
|
JSON 结构化输出(Agent 推荐):
|
|
@@ -41,9 +46,37 @@ miaoda file ls --output json
|
|
|
41
46
|
| `miaoda file ...` | 文件操作:上传、下载、元数据、签名下载、批量删除 |
|
|
42
47
|
| `miaoda db ...` | 数据操作:SQL 执行、表结构查询、数据导入导出 |
|
|
43
48
|
| `miaoda observability ...` | 线上日志、链路、前端源码堆栈反查、监控指标、运营指标 |
|
|
49
|
+
| `miaoda comment ...` | 应用评论:查看评论列表、解决评论 |
|
|
50
|
+
| `miaoda registry ...` | 组件 registry:列出 / copy-in design-html SDK 文件(本地执行) |
|
|
44
51
|
|
|
45
52
|
完整命令通过 `miaoda --help` 或 `miaoda <domain> --help` 查看。
|
|
46
53
|
|
|
54
|
+
## 组件 registry(design-html)
|
|
55
|
+
|
|
56
|
+
`miaoda registry` 为 design-html 技术栈提供 shadcn 式的「组件 registry」:把 SDK 文件**拷进**当前项目(copy-in),而非作为依赖安装。registry 是独立 npm 包,按运行时分发(design-html → buildless runtime → `@lark-apaas/coding-registry-buildless`)。
|
|
57
|
+
|
|
58
|
+
前置:当前目录(或 `--dir`)已走过 `miaoda app init`,`.spark/meta.json` 含 `stack=design-html`。
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# 列出可用 SDK 条目(输出各文件 USAGE 注释块原文,便于 Agent 直接读用法)
|
|
62
|
+
miaoda registry list
|
|
63
|
+
miaoda registry list --json
|
|
64
|
+
|
|
65
|
+
# 把条目 copy-in 到当前项目(自动按 USAGE 块的 Depends 解析依赖闭包一并拷入)
|
|
66
|
+
miaoda registry add deck-slide
|
|
67
|
+
miaoda registry add foo.css theme --dry-run # 只报告将写 / 将跳,不落盘
|
|
68
|
+
miaoda registry add deck-slide --overwrite # 目标已存在时覆盖(默认跳过以保护改动)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
要点:
|
|
72
|
+
|
|
73
|
+
- **条目**:registry 包根 `components/` · `scripts/` · `stylesheets/` 三个顶层目录(任意深度)下的代码文件即条目。USAGE 注释块**可选**(有则提供描述 + Depends,无则空描述、无依赖);包根直放文件、其它目录、非代码文件都不算条目。
|
|
74
|
+
- **寻址**:`add` / `Depends` 的 token 可写三种形式 —— `name`(去扩展名,如 `foo`)/ 完整文件名(如 `foo.css`)/ relPath(如 `stylesheets/foo.css`)。`name` **不要求唯一**,`list --json` 的 `file`(relPath)是永远无歧义的 canonical 地址。
|
|
75
|
+
- **多匹配全拉**:token 命中多个同名条目时全部 copy-in(如 `add foo` 把 `foo.jsx` + `foo.css` 一起拉),想只要其一就用完整文件名或 relPath。
|
|
76
|
+
- **拍平落地**:所有文件**拍平**到项目根(`scripts/deck-slide.js` → 项目 `deck-slide.js`,不保留子目录);闭包内同名 basename 撞车时后者覆盖前者。
|
|
77
|
+
- **skip-by-disk**:项目已有同名(拍平后的 basename)文件默认跳过,`--overwrite` 才覆盖;不写任何安装记账文件,项目文件树即状态。
|
|
78
|
+
- `--version <ver>` 指定 registry 包版本或 dist-tag(缺省 `latest`),`--dir <path>` 指定项目目录(缺省当前目录)。
|
|
79
|
+
|
|
47
80
|
## 全局参数
|
|
48
81
|
|
|
49
82
|
- `--json [fields]`:输出结构化 JSON,可选字段级选择(如 `--json id,name`)。
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComments = getComments;
|
|
4
|
+
exports.resolveComment = resolveComment;
|
|
5
|
+
const http_1 = require("../../utils/http");
|
|
6
|
+
const error_1 = require("../../utils/error");
|
|
7
|
+
/**
|
|
8
|
+
* 解析 lark-gw BaseResp 平铺信封:
|
|
9
|
+
* - HTTP 非 2xx → HttpError
|
|
10
|
+
* - StatusCode !== 0 → AppError(业务/下游失败,HTTP 通常仍 200)
|
|
11
|
+
* - 否则返回平铺响应体
|
|
12
|
+
*
|
|
13
|
+
* 注意:评论接口用大写 StatusCode/StatusMessage,与 utils/http.ts 的
|
|
14
|
+
* getInnerApi(小写 status_code)信封不同,故域内自带解析。
|
|
15
|
+
*/
|
|
16
|
+
async function parseBaseResp(response, url, errPrefix) {
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw new error_1.HttpError(response.status, url, `${errPrefix}: ${String(response.status)} ${response.statusText}`.trim());
|
|
19
|
+
}
|
|
20
|
+
const body = (await response.json());
|
|
21
|
+
if (body.StatusCode !== 0) {
|
|
22
|
+
throw new error_1.AppError('INTERNAL_API_ERROR', `${errPrefix}: ${body.StatusMessage ?? 'unknown error'}`);
|
|
23
|
+
}
|
|
24
|
+
return body;
|
|
25
|
+
}
|
|
26
|
+
/** GET /api/v1/studio/innerapi/apps/:appID/comments — 获取应用评论列表 */
|
|
27
|
+
async function getComments(appID, onlyUnresolved = false) {
|
|
28
|
+
const client = (0, http_1.getRuntimeHttpClient)();
|
|
29
|
+
let url = `/api/v1/studio/innerapi/apps/${encodeURIComponent(appID)}/comments`;
|
|
30
|
+
if (onlyUnresolved)
|
|
31
|
+
url += '?onlyUnresolved=true';
|
|
32
|
+
const response = await client.get(url);
|
|
33
|
+
const body = await parseBaseResp(response, url, 'Failed to list comments');
|
|
34
|
+
return body.comments ?? [];
|
|
35
|
+
}
|
|
36
|
+
/** POST /api/v1/studio/innerapi/apps/:appID/comments/:commentID/resolve — 解决评论 */
|
|
37
|
+
async function resolveComment(appID, commentID) {
|
|
38
|
+
const client = (0, http_1.getRuntimeHttpClient)();
|
|
39
|
+
const url = `/api/v1/studio/innerapi/apps/${encodeURIComponent(appID)}/comments/${encodeURIComponent(commentID)}/resolve`;
|
|
40
|
+
const response = await client.post(url);
|
|
41
|
+
await parseBaseResp(response, url, 'Failed to resolve comment');
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveComment = exports.getComments = void 0;
|
|
4
|
+
var api_1 = require("./api");
|
|
5
|
+
Object.defineProperty(exports, "getComments", { enumerable: true, get: function () { return api_1.getComments; } });
|
|
6
|
+
Object.defineProperty(exports, "resolveComment", { enumerable: true, get: function () { return api_1.resolveComment; } });
|
package/dist/api/index.js
CHANGED
|
@@ -33,16 +33,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.deploy = exports.app = exports.observability = exports.db = exports.file = exports.plugin = void 0;
|
|
36
|
+
exports.comment = exports.deploy = exports.app = exports.observability = exports.db = exports.file = exports.plugin = void 0;
|
|
37
37
|
const _plugin = __importStar(require("../api/plugin/index"));
|
|
38
38
|
const _file = __importStar(require("../api/file/index"));
|
|
39
39
|
const _db = __importStar(require("../api/db/index"));
|
|
40
40
|
const _observability = __importStar(require("../api/observability/index"));
|
|
41
41
|
const _app = __importStar(require("../api/app/index"));
|
|
42
42
|
const _deploy = __importStar(require("../api/deploy/index"));
|
|
43
|
+
const _comment = __importStar(require("../api/comment/index"));
|
|
43
44
|
exports.plugin = { ..._plugin };
|
|
44
45
|
exports.file = { ..._file };
|
|
45
46
|
exports.db = { ..._db };
|
|
46
47
|
exports.observability = { ..._observability };
|
|
47
48
|
exports.app = { ..._app };
|
|
48
49
|
exports.deploy = { ..._deploy };
|
|
50
|
+
exports.comment = { ..._comment };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerCommentCommands = registerCommentCommands;
|
|
4
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
5
|
+
const index_1 = require("../../../cli/handlers/comment/index");
|
|
6
|
+
function registerCommentCommands(program) {
|
|
7
|
+
const commentCmd = program
|
|
8
|
+
.command('comment')
|
|
9
|
+
.description('应用评论:查看评论列表、解决评论')
|
|
10
|
+
.usage('<command> [flags]');
|
|
11
|
+
commentCmd.action(() => {
|
|
12
|
+
commentCmd.outputHelp();
|
|
13
|
+
});
|
|
14
|
+
commentCmd.addHelpText('after', `
|
|
15
|
+
作用范围
|
|
16
|
+
操作当前应用的评论。应用上下文:--app-id <id> 或环境变量 MIAODA_APP_ID。
|
|
17
|
+
`);
|
|
18
|
+
const listCmd = commentCmd
|
|
19
|
+
.command('list')
|
|
20
|
+
.description('查看应用评论列表')
|
|
21
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
22
|
+
.option('--only-unresolved', '仅返回未解决的评论', false)
|
|
23
|
+
.addHelpText('after', `
|
|
24
|
+
JSON 输出
|
|
25
|
+
{"data": [{"comment_id": "...", "content": "...", "user_id": "...",
|
|
26
|
+
"finish": 0, "resolved": false, "create_time": 1700000000}]}
|
|
27
|
+
|
|
28
|
+
示例
|
|
29
|
+
$ miaoda comment list --json
|
|
30
|
+
$ miaoda comment list --only-unresolved --json
|
|
31
|
+
`);
|
|
32
|
+
listCmd.action((0, shared_1.withHelp)(listCmd, async (rawOpts) => {
|
|
33
|
+
(0, shared_1.rejectCliOverride)(listCmd, 'appId');
|
|
34
|
+
await (0, index_1.handleCommentList)({
|
|
35
|
+
appId: rawOpts.appId,
|
|
36
|
+
onlyUnresolved: rawOpts.onlyUnresolved,
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
const resolveCmd = commentCmd
|
|
40
|
+
.command('resolve')
|
|
41
|
+
.description('把一条评论标记为已解决')
|
|
42
|
+
.argument('<commentID>', '待解决的评论 ID')
|
|
43
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
44
|
+
.addHelpText('after', `
|
|
45
|
+
JSON 输出
|
|
46
|
+
{"data": {"comment_id": "...", "resolved": true}}
|
|
47
|
+
|
|
48
|
+
示例
|
|
49
|
+
$ miaoda comment resolve 1703677660120110076 --json
|
|
50
|
+
`);
|
|
51
|
+
resolveCmd.action((0, shared_1.withHelp)(resolveCmd, async (commentId, rawOpts) => {
|
|
52
|
+
(0, shared_1.rejectCliOverride)(resolveCmd, 'appId');
|
|
53
|
+
await (0, index_1.handleCommentResolve)(commentId, { appId: rawOpts.appId });
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
@@ -59,15 +59,17 @@ JSON 输出(stdout)
|
|
|
59
59
|
}));
|
|
60
60
|
const patchCmd = deployCmd
|
|
61
61
|
.command('patch')
|
|
62
|
-
.description('design-html 增量发布:按文件 create/update/delete,.html
|
|
62
|
+
.description('design-html 增量发布:按文件 create/update/delete,.html 增删时同步 routes.json')
|
|
63
63
|
.option('--create <relpath>', '新增文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
64
64
|
.option('--update <relpath>', '覆盖已有文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
65
65
|
.option('--delete <relpath>', '删除文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
66
66
|
.addHelpText('after', `
|
|
67
67
|
--dir 为项目目录(与 deploy 同名参数,默认当前目录)。
|
|
68
68
|
仅支持 design-html(design_local_deploy)。路径为工程根相对路径(= 服务端 latest 下 key),
|
|
69
|
-
禁绝对路径与 ".."。--create/--update
|
|
70
|
-
|
|
69
|
+
禁绝对路径与 ".."。--create/--update 的本地文件必须存在。.html 被新增/删除(路由集合变化)
|
|
70
|
+
时自动重算并随包更新 routes.json;纯 --update 现有 .html 只改内容,不动 routes.json。
|
|
71
|
+
routes.json 每项为 {path, file}:path 为相对路径(不含 base 前缀,由消费侧拼接),file 为
|
|
72
|
+
对应源文件(如 / → index.html)。
|
|
71
73
|
|
|
72
74
|
JSON 输出
|
|
73
75
|
{"data": {"upsertCount": <n>, "deleteCount": <n>, "actionsSent": <n>, "routesRegenerated": <bool>}}
|
|
@@ -9,6 +9,8 @@ const index_4 = require("../../cli/commands/app/index");
|
|
|
9
9
|
const index_5 = require("../../cli/commands/deploy/index");
|
|
10
10
|
const modern_1 = require("../../cli/commands/deploy/modern");
|
|
11
11
|
const index_6 = require("../../cli/commands/skills/index");
|
|
12
|
+
const index_7 = require("../../cli/commands/comment/index");
|
|
13
|
+
const index_8 = require("../../cli/commands/registry/index");
|
|
12
14
|
// scene 跟 dispatcher(MIAODA_APP_TYPE)同语义层级 —— app 业务类型维度,
|
|
13
15
|
// 对齐后端 devops app_common.AppType 枚举:
|
|
14
16
|
// 3 = AppType_APPLICATION(全栈应用,当前仅 nestjs-react-fullstack 一个 stack)
|
|
@@ -40,11 +42,13 @@ const SCENE_REGISTRARS = {
|
|
|
40
42
|
(0, index_1.registerFileCommands)(p);
|
|
41
43
|
(0, index_3.registerObservabilityCommands)(p);
|
|
42
44
|
(0, index_6.registerSkillsCommands)(p);
|
|
45
|
+
(0, index_7.registerCommentCommands)(p);
|
|
43
46
|
},
|
|
44
47
|
modern: (p) => {
|
|
45
48
|
(0, index_4.registerAppCommands)(p, { includeInit: true });
|
|
46
49
|
(0, modern_1.registerDeployCommandsModern)(p);
|
|
47
50
|
(0, index_6.registerSkillsCommands)(p);
|
|
51
|
+
(0, index_7.registerCommentCommands)(p);
|
|
48
52
|
},
|
|
49
53
|
// application scene(AppType_APPLICATION=3):
|
|
50
54
|
// 在 default 命令集基础上加 skills(按 meta.json.stack 拉对应 stack 技能)
|
|
@@ -56,6 +60,7 @@ const SCENE_REGISTRARS = {
|
|
|
56
60
|
(0, index_1.registerFileCommands)(p);
|
|
57
61
|
(0, index_3.registerObservabilityCommands)(p);
|
|
58
62
|
(0, index_6.registerSkillsCommands)(p);
|
|
63
|
+
(0, index_7.registerCommentCommands)(p);
|
|
59
64
|
},
|
|
60
65
|
// design scene(AppType_DESIGN=4):design-stack 仅 SSR 渲染、无后端业务逻辑、
|
|
61
66
|
// 无数据库、无 UGC 文件。命令集裁掉 db / file,保留 deploy / observability / app(init) / skills。
|
|
@@ -64,13 +69,16 @@ const SCENE_REGISTRARS = {
|
|
|
64
69
|
(0, index_5.registerDeployCommands)(p);
|
|
65
70
|
(0, index_3.registerObservabilityCommands)(p);
|
|
66
71
|
(0, index_6.registerSkillsCommands)(p);
|
|
72
|
+
(0, index_7.registerCommentCommands)(p);
|
|
67
73
|
},
|
|
68
74
|
// design-html scene(AppType_DESIGN_HTML=8):buildless 静态 HTML,
|
|
69
75
|
// 命令集与 modern 一致(app init/sync + modern 拆分版 deploy + skills),不挂 db/file/observability。
|
|
76
|
+
// 额外挂 registry(shadcn 式 copy-in SDK,design-html scene 专属)。
|
|
70
77
|
'design-html': (p) => {
|
|
71
78
|
(0, index_4.registerAppCommands)(p, { includeInit: true });
|
|
72
79
|
(0, modern_1.registerDeployCommandsModern)(p);
|
|
73
80
|
(0, index_6.registerSkillsCommands)(p);
|
|
81
|
+
(0, index_8.registerRegistryCommands)(p);
|
|
74
82
|
},
|
|
75
83
|
};
|
|
76
84
|
function readEnv(name) {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerRegistryCommands = registerRegistryCommands;
|
|
4
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
5
|
+
const index_1 = require("../../../cli/handlers/registry/index");
|
|
6
|
+
/**
|
|
7
|
+
* miaoda registry:design-html 技术栈的「组件 registry」(shadcn 式 copy-in)。
|
|
8
|
+
*
|
|
9
|
+
* registry 是独立 npm 包,按 runtime 命名分发(buildless runtime → @lark-apaas/coding-registry-buildless)。
|
|
10
|
+
* SDK 文件放在包根的 components/ · scripts/ · stylesheets/ 三个目录下(这三个顶层目录里的代码文件
|
|
11
|
+
* 才算条目);文件可带 USAGE 注释块(可选,声明描述 / 用法 / Depends)。CLI 抓 tarball、按
|
|
12
|
+
* .spark/meta.json.stack → runtime → 包名 选包,把 SDK 文件**拍平**copy-in 到用户项目根。
|
|
13
|
+
* 不写安装记账文件——项目文件树即状态(skip-by-disk)。
|
|
14
|
+
*/
|
|
15
|
+
function registerRegistryCommands(program) {
|
|
16
|
+
const registryCmd = program
|
|
17
|
+
.command('registry')
|
|
18
|
+
.description('组件 registry:列出 / copy-in design-html SDK 文件')
|
|
19
|
+
.usage('<command> [flags]');
|
|
20
|
+
registryCmd.action(() => {
|
|
21
|
+
registryCmd.outputHelp();
|
|
22
|
+
});
|
|
23
|
+
registryCmd.addHelpText('after', `
|
|
24
|
+
概念
|
|
25
|
+
- registry 包:独立 npm 包(按 runtime 命名)
|
|
26
|
+
- 条目 (entry):包根 components/ · scripts/ · stylesheets/ 顶层目录(任意深度)下的代码文件;
|
|
27
|
+
name = 文件名去扩展名(不要求唯一)。包根直放文件、其它目录、非代码文件都不算条目
|
|
28
|
+
- 寻址:add / Depends 的 token 可写三种形式——name(foo)/ 完整文件名(foo.css)/ relPath(stylesheets/foo.css)
|
|
29
|
+
- 多匹配全拉:token 命中多个同名条目时全部 copy-in(不报歧义);想只要其一就写完整文件名 / relPath
|
|
30
|
+
- USAGE 块:可选元数据,声明描述 / Exports / Usage / Depends;无 USAGE 也是条目(空描述、无依赖)
|
|
31
|
+
- Depends:从 USAGE 块解析的跨条目依赖,add 时传递解析、一并 copy-in
|
|
32
|
+
- add 落地:拍平到项目根(包根 scripts/x.js → 项目 x.js);同名 basename 撞车时后者覆盖前者
|
|
33
|
+
|
|
34
|
+
前置
|
|
35
|
+
当前目录(或 --dir)已走过 'miaoda app init'(.spark/meta.json 含 stack=design-html)
|
|
36
|
+
`);
|
|
37
|
+
registerRegistryList(registryCmd);
|
|
38
|
+
registerRegistryAdd(registryCmd);
|
|
39
|
+
}
|
|
40
|
+
function registerRegistryList(parent) {
|
|
41
|
+
const cmd = parent
|
|
42
|
+
.command('list')
|
|
43
|
+
.description('列出 registry 可用 SDK 条目,输出各文件的 USAGE 块原文')
|
|
44
|
+
.option('--dir <path>', '项目目录,默认当前目录', '.')
|
|
45
|
+
.option('--version <ver>', 'registry 包版本或 dist-tag,缺省 latest')
|
|
46
|
+
.addHelpText('after', `
|
|
47
|
+
输出
|
|
48
|
+
默认(pretty):各条目 USAGE 块原文拼接,带文件名分隔,给 Agent 直接读注释
|
|
49
|
+
|
|
50
|
+
JSON 输出
|
|
51
|
+
{"data": [{"name": "...", "file": "...", "usage": "<原文>", "dependsOn": [...]}, ...]}
|
|
52
|
+
(usage 保持 USAGE 块原文,不解析成结构化字段)
|
|
53
|
+
|
|
54
|
+
示例
|
|
55
|
+
$ miaoda registry list
|
|
56
|
+
$ miaoda registry list --json
|
|
57
|
+
`);
|
|
58
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
|
|
59
|
+
await (0, index_1.handleRegistryList)({
|
|
60
|
+
dir: rawOpts.dir,
|
|
61
|
+
version: rawOpts.version,
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
function registerRegistryAdd(parent) {
|
|
66
|
+
const cmd = parent
|
|
67
|
+
.command('add')
|
|
68
|
+
.description('把一个或多个 SDK 文件 copy-in 到当前项目(拍平到项目根,含 Depends 闭包)')
|
|
69
|
+
.argument('<token...>', 'name / 完整文件名 / relPath,可传多个;同名多匹配全拉,Depends 自动传递解析')
|
|
70
|
+
.option('--dir <path>', '项目目录,默认当前目录', '.')
|
|
71
|
+
.option('--version <ver>', 'registry 包版本或 dist-tag,缺省 latest')
|
|
72
|
+
.option('--overwrite', '目标文件已存在时覆盖(默认跳过以保护用户改动)', false)
|
|
73
|
+
.option('--dry-run', '只报告将写 / 将跳哪些文件,不落盘', false)
|
|
74
|
+
.addHelpText('after', `
|
|
75
|
+
行为
|
|
76
|
+
- token 寻址:name(foo)/ 完整文件名(foo.css)/ relPath(stylesheets/foo.css)任一形式
|
|
77
|
+
- 多匹配全拉:token 命中多个同名条目时全部 copy-in;想只要其一就写完整文件名 / relPath
|
|
78
|
+
- 解析 USAGE 块 Depends 传递闭包,把 SDK 文件**拍平**拷到项目根
|
|
79
|
+
(包根 scripts/deck-stage.js → 项目 deck-stage.js;同名 basename 撞车时后者覆盖前者)
|
|
80
|
+
- skip-by-disk:目标文件已存在默认跳过;--overwrite 才覆盖
|
|
81
|
+
- 不写任何安装记账文件(项目文件树即状态)
|
|
82
|
+
|
|
83
|
+
JSON 输出
|
|
84
|
+
{"data": {"registryVersion": "...", "requested": [...], "resolved": [...],
|
|
85
|
+
"added": [...], "skipped": [...], "dryRun": false}}
|
|
86
|
+
(resolved 为来源 relPath;added / skipped 为拍平后的落地 basename,如 deck-stage.js)
|
|
87
|
+
|
|
88
|
+
示例
|
|
89
|
+
$ miaoda registry add deck-slide
|
|
90
|
+
$ miaoda registry add deck-slide theme --dry-run
|
|
91
|
+
$ miaoda registry add deck-slide --overwrite --json
|
|
92
|
+
`);
|
|
93
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (names, rawOpts) => {
|
|
94
|
+
await (0, index_1.handleRegistryAdd)({
|
|
95
|
+
names,
|
|
96
|
+
dir: rawOpts.dir,
|
|
97
|
+
version: rawOpts.version,
|
|
98
|
+
overwrite: rawOpts.overwrite,
|
|
99
|
+
dryRun: rawOpts.dryRun,
|
|
100
|
+
});
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
@@ -69,8 +69,12 @@ async function handleAppInit(opts) {
|
|
|
69
69
|
const projectName = node_path_1.default.basename(targetDir);
|
|
70
70
|
const tplResult = (0, index_1.renderTemplate)({ stack, version, targetDir, projectName });
|
|
71
71
|
// 先建 logs/,防止 user 跑 dev 之前 AI/工具 redirect 到 logs/*.log 因为父目录不存在直接挂
|
|
72
|
-
// (dev.js / dev-local.js 自己也建 logs/,但只在它启动后;启动前的 shell redirect 会先于此)
|
|
73
|
-
|
|
72
|
+
// (dev.js / dev-local.js 自己也建 logs/,但只在它启动后;启动前的 shell redirect 会先于此)。
|
|
73
|
+
// 仅本地开发需要:沙箱环境由平台 supervisor 拉起 dev,无 init 前的 shell redirect 场景,
|
|
74
|
+
// 不预建 logs/ 以免在沙箱工作区留空目录。
|
|
75
|
+
if (!(0, env_1.isSandboxEnv)()) {
|
|
76
|
+
(0, logs_dir_1.ensureLogsDir)(targetDir);
|
|
77
|
+
}
|
|
74
78
|
// skills 同步软失败:拉不到 coding-steering 包不该阻断 writeSparkMeta /
|
|
75
79
|
// activateGitHooks(之前会让 .spark/meta.json 没写,下次 init 半渲染状态又得重跑全套)。
|
|
76
80
|
// 按运行环境(isSandboxEnv:MIAODA_DEP_CACHE_DIR 非空)分流 outputLayout,不绑 stack:
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleCommentResolve = exports.handleCommentList = void 0;
|
|
4
|
+
var list_1 = require("./list");
|
|
5
|
+
Object.defineProperty(exports, "handleCommentList", { enumerable: true, get: function () { return list_1.handleCommentList; } });
|
|
6
|
+
var resolve_1 = require("./resolve");
|
|
7
|
+
Object.defineProperty(exports, "handleCommentResolve", { enumerable: true, get: function () { return resolve_1.handleCommentResolve; } });
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.handleCommentList = handleCommentList;
|
|
37
|
+
const api = __importStar(require("../../../api/index"));
|
|
38
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
39
|
+
const output_1 = require("../../../utils/output");
|
|
40
|
+
const listSchema = {
|
|
41
|
+
columns: [
|
|
42
|
+
{ key: 'comment_id', label: 'id' },
|
|
43
|
+
{ key: 'finish' },
|
|
44
|
+
{ key: 'resolved' },
|
|
45
|
+
{ key: 'user_id', label: 'user' },
|
|
46
|
+
{ key: 'create_time', label: 'time', format: output_1.fmt.sec() },
|
|
47
|
+
{ key: 'content', format: output_1.fmt.truncate(80) },
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
async function handleCommentList(opts) {
|
|
51
|
+
const appId = (0, shared_1.resolveAppId)({ appId: opts.appId });
|
|
52
|
+
const comments = await api.comment.getComments(appId, opts.onlyUnresolved ?? false);
|
|
53
|
+
const rows = comments.map((c) => ({
|
|
54
|
+
comment_id: c.commentID,
|
|
55
|
+
content: c.content,
|
|
56
|
+
user_id: c.userID,
|
|
57
|
+
finish: c.finish,
|
|
58
|
+
resolved: c.finish === 1,
|
|
59
|
+
create_time: c.createTime,
|
|
60
|
+
}));
|
|
61
|
+
(0, output_1.emit)({ data: rows }, listSchema);
|
|
62
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.handleCommentResolve = handleCommentResolve;
|
|
37
|
+
const api = __importStar(require("../../../api/index"));
|
|
38
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
39
|
+
const output_1 = require("../../../utils/output");
|
|
40
|
+
async function handleCommentResolve(commentId, opts) {
|
|
41
|
+
const appId = (0, shared_1.resolveAppId)({ appId: opts.appId });
|
|
42
|
+
await api.comment.resolveComment(appId, commentId);
|
|
43
|
+
(0, output_1.emitOk)({ comment_id: commentId, resolved: true });
|
|
44
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleRegistryAdd = handleRegistryAdd;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const index_1 = require("../../../services/registry/index");
|
|
9
|
+
const shared_1 = require("./shared");
|
|
10
|
+
const error_1 = require("../../../utils/error");
|
|
11
|
+
const output_1 = require("../../../utils/output");
|
|
12
|
+
const logger_1 = require("../../../utils/logger");
|
|
13
|
+
/**
|
|
14
|
+
* miaoda registry add <name...> [--overwrite] [--dry-run] [--dir <path>] [--version <ver>]
|
|
15
|
+
*
|
|
16
|
+
* 解析 USAGE 块 Depends 传递闭包,把每个条目对应的 SDK 文件从 registry 包根的 <relPath>
|
|
17
|
+
* **保留相对路径**拷到项目根(--dir 指定目录的根)。
|
|
18
|
+
* skip-by-disk:目标已存在默认跳过,--overwrite 才覆盖。不写任何安装记账文件。
|
|
19
|
+
*/
|
|
20
|
+
async function handleRegistryAdd(opts) {
|
|
21
|
+
await Promise.resolve();
|
|
22
|
+
if (opts.names.length === 0) {
|
|
23
|
+
throw new error_1.AppError('ARGS_INVALID', 'registry add 至少需要一个条目名');
|
|
24
|
+
}
|
|
25
|
+
const targetDir = node_path_1.default.resolve(opts.dir ?? process.cwd());
|
|
26
|
+
const stack = (0, shared_1.resolveRegistryStack)(targetDir);
|
|
27
|
+
const reg = (0, index_1.loadRegistry)({ stack, version: opts.version });
|
|
28
|
+
try {
|
|
29
|
+
const plan = (0, index_1.planAdd)({
|
|
30
|
+
entries: reg.entries,
|
|
31
|
+
targetDir,
|
|
32
|
+
names: opts.names,
|
|
33
|
+
});
|
|
34
|
+
const result = (0, index_1.applyAdd)(plan.files, {
|
|
35
|
+
overwrite: opts.overwrite === true,
|
|
36
|
+
dryRun: opts.dryRun === true,
|
|
37
|
+
});
|
|
38
|
+
const verb = opts.dryRun === true ? 'Would add' : 'Added';
|
|
39
|
+
(0, logger_1.log)('registry', `${verb} ${String(result.added.length)} file(s), skipped ${String(result.skipped.length)} (registry@${reg.version})`);
|
|
40
|
+
(0, output_1.emit)({
|
|
41
|
+
data: {
|
|
42
|
+
registryVersion: reg.version,
|
|
43
|
+
requested: opts.names,
|
|
44
|
+
resolved: plan.entries.map((e) => e.relPath),
|
|
45
|
+
added: result.added,
|
|
46
|
+
skipped: result.skipped,
|
|
47
|
+
dryRun: opts.dryRun === true,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
reg.cleanup();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleRegistryAdd = exports.handleRegistryList = void 0;
|
|
4
|
+
var list_1 = require("./list");
|
|
5
|
+
Object.defineProperty(exports, "handleRegistryList", { enumerable: true, get: function () { return list_1.handleRegistryList; } });
|
|
6
|
+
var add_1 = require("./add");
|
|
7
|
+
Object.defineProperty(exports, "handleRegistryAdd", { enumerable: true, get: function () { return add_1.handleRegistryAdd; } });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleRegistryList = handleRegistryList;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const index_1 = require("../../../services/registry/index");
|
|
9
|
+
const shared_1 = require("./shared");
|
|
10
|
+
const output_1 = require("../../../utils/output");
|
|
11
|
+
/**
|
|
12
|
+
* miaoda registry list [--dir <path>] [--version <ver>]
|
|
13
|
+
*
|
|
14
|
+
* 从 .spark/meta.json 读 stack → runtime → 包名,拉对应 registry 包,从包根递归扫含 USAGE 块的 SDK 文件。
|
|
15
|
+
*
|
|
16
|
+
* - 默认(pretty):输出各条目 USAGE 块原文,带文件名分隔,给 Agent 直接读注释。
|
|
17
|
+
* - --json:输出 [{name, file, usage(原文字符串), dependsOn[]}],usage 保持原文不解析成字段。
|
|
18
|
+
* file 是相对包根的路径(如 scripts/deck-stage.js),即 add 后的落地相对路径。
|
|
19
|
+
*/
|
|
20
|
+
async function handleRegistryList(opts) {
|
|
21
|
+
await Promise.resolve();
|
|
22
|
+
const targetDir = node_path_1.default.resolve(opts.dir ?? process.cwd());
|
|
23
|
+
const stack = (0, shared_1.resolveRegistryStack)(targetDir);
|
|
24
|
+
const reg = (0, index_1.loadRegistry)({ stack, version: opts.version });
|
|
25
|
+
try {
|
|
26
|
+
if ((0, output_1.isJsonMode)()) {
|
|
27
|
+
(0, output_1.emit)({
|
|
28
|
+
data: reg.entries.map((e) => ({
|
|
29
|
+
name: e.name,
|
|
30
|
+
file: e.relPath,
|
|
31
|
+
usage: e.usage,
|
|
32
|
+
dependsOn: e.dependsOn,
|
|
33
|
+
})),
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// pretty:各条目 USAGE 块原文拼接,带文件路径分隔(让 Agent 直接读注释)
|
|
38
|
+
if (reg.entries.length === 0) {
|
|
39
|
+
(0, output_1.emit)('(no registry entries)');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const blocks = reg.entries.map((e) => `# ${e.relPath}\n${e.usage}`);
|
|
43
|
+
(0, output_1.emit)(blocks.join('\n\n'));
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
reg.cleanup();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRegistryStack = resolveRegistryStack;
|
|
4
|
+
const spark_meta_1 = require("../../../utils/spark-meta");
|
|
5
|
+
const index_1 = require("../../../services/registry/index");
|
|
6
|
+
const error_1 = require("../../../utils/error");
|
|
7
|
+
/**
|
|
8
|
+
* 从 <targetDir>/.spark/meta.json 读 stack,校验该 stack 有组件 registry。
|
|
9
|
+
* 缺 stack → 提示先 init;stack 无 registry(无对应 runtime / runtime 无 registry 包)→ 提示支持哪些 stack。
|
|
10
|
+
*
|
|
11
|
+
* 这里只做「stack 是否在支持列表」的早校验给用户友好提示;包名的两跳解析
|
|
12
|
+
* (stack → runtime → 包)由 loadRegistry/resolveRegistryPackage 负责。
|
|
13
|
+
*/
|
|
14
|
+
function resolveRegistryStack(targetDir) {
|
|
15
|
+
const meta = (0, spark_meta_1.readSparkMeta)(targetDir);
|
|
16
|
+
if (meta.stack === undefined || meta.stack === '') {
|
|
17
|
+
throw new error_1.AppError('REGISTRY_META_INCOMPLETE', '.spark/meta.json missing stack — run `miaoda app init` first');
|
|
18
|
+
}
|
|
19
|
+
if (!index_1.REGISTRY_SUPPORTED_STACKS.includes(meta.stack)) {
|
|
20
|
+
throw new error_1.AppError('REGISTRY_STACK_UNSUPPORTED', `stack "${meta.stack}" 没有组件 registry`, {
|
|
21
|
+
next_actions: [`支持 registry 的 stack:${index_1.REGISTRY_SUPPORTED_STACKS.join(', ') || '(none)'}`],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return meta.stack;
|
|
25
|
+
}
|
|
@@ -36,7 +36,8 @@ function isHtml(rel) {
|
|
|
36
36
|
/**
|
|
37
37
|
* 把 changeset 组成 TosFileAction[]:
|
|
38
38
|
* - create/update 读本地文件、自动编码;delete 仅 FilePath。
|
|
39
|
-
* -
|
|
39
|
+
* - .html 被 create / delete(路由集合变化)时,追加重算 routes.json 的 UPDATE action;
|
|
40
|
+
* 纯 update 现有 .html 只改内容、不改路由集合,不重算 routes.json。
|
|
40
41
|
*/
|
|
41
42
|
function buildTosActions(projectDir, cs) {
|
|
42
43
|
const actions = [];
|
|
@@ -47,8 +48,8 @@ function buildTosActions(projectDir, cs) {
|
|
|
47
48
|
for (const rel of cs.deletes) {
|
|
48
49
|
actions.push({ actionType: index_1.TosActionType.DELETE, filePath: normalizeRel(rel) });
|
|
49
50
|
}
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
51
|
+
const routeSetChanged = [...cs.creates, ...cs.deletes].some(isHtml);
|
|
52
|
+
if (routeSetChanged) {
|
|
52
53
|
actions.push({
|
|
53
54
|
actionType: index_1.TosActionType.UPDATE,
|
|
54
55
|
filePath: 'routes.json',
|
|
@@ -11,8 +11,8 @@ const actions_1 = require("./actions");
|
|
|
11
11
|
var actions_2 = require("./actions");
|
|
12
12
|
Object.defineProperty(exports, "buildTosActions", { enumerable: true, get: function () { return actions_2.buildTosActions; } });
|
|
13
13
|
/**
|
|
14
|
-
* design-html 增量发布:读本地文件组 TosFileAction
|
|
15
|
-
*
|
|
14
|
+
* design-html 增量发布:读本地文件组 TosFileAction(create/delete .html 时带重算的
|
|
15
|
+
* routes.json),调后端 applyTosDiff 应用到 latest。scope 限 design_local_deploy。
|
|
16
16
|
*/
|
|
17
17
|
async function patchDesignDeploy(opts) {
|
|
18
18
|
if (opts.creates.length + opts.updates.length + opts.deletes.length === 0) {
|
|
@@ -2,27 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRoutes = generateRoutes;
|
|
4
4
|
const source_scan_1 = require("./source-scan");
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* .html → route path 推导(相对路径,不带 base 前缀)。rel 为 posix 相对路径。
|
|
7
|
+
* base 前缀交由消费侧(运行时/网关)自行拼接,design-html 链路不在 routes.json 内带前缀。
|
|
8
|
+
*/
|
|
9
|
+
function toRoute(rel) {
|
|
7
10
|
let r = '/' + rel;
|
|
8
11
|
r = r.replace(/\.html$/i, '');
|
|
9
12
|
r = r.replace(/(^|\/)index$/, '$1');
|
|
10
13
|
if (r.length > 1)
|
|
11
14
|
r = r.replace(/\/$/, '');
|
|
12
|
-
|
|
13
|
-
return full === '' ? '/' : full;
|
|
15
|
+
return r === '' ? '/' : r;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
|
-
* 扫描 projectDir 下所有 .html(套 source-scan 的 EXCLUDES
|
|
17
|
-
*
|
|
18
|
+
* 扫描 projectDir 下所有 .html(套 source-scan 的 EXCLUDES),生成 routes.json 文本(含尾换行)。
|
|
19
|
+
* 每项为 { path, file }:path 为相对路径(不带 CLIENT_BASE_PATH 前缀,由消费侧拼接),
|
|
20
|
+
* file 为该路由对应的原始 .html 源文件。按 path 排序、同 path 取字典序靠前的 file 去重。
|
|
21
|
+
* 零 html 时输出空数组——不伪造解析不到文件的根路由。
|
|
18
22
|
*/
|
|
19
23
|
function generateRoutes(projectDir) {
|
|
20
|
-
const base = (process.env.CLIENT_BASE_PATH ?? '').replace(/\/+$/, '');
|
|
21
24
|
const htmls = (0, source_scan_1.listSourceFiles)(projectDir).filter((f) => f.toLowerCase().endsWith('.html'));
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const byPath = new Map();
|
|
26
|
+
for (const entry of htmls.map((file) => ({ path: toRoute(file), file })).sort(byPathThenFile)) {
|
|
27
|
+
if (!byPath.has(entry.path))
|
|
28
|
+
byPath.set(entry.path, entry);
|
|
29
|
+
}
|
|
30
|
+
const routes = [...byPath.values()];
|
|
27
31
|
return JSON.stringify(routes, null, 2) + '\n';
|
|
28
32
|
}
|
|
33
|
+
function byPathThenFile(a, b) {
|
|
34
|
+
return a.path === b.path
|
|
35
|
+
? (a.file ?? '').localeCompare(b.file ?? '')
|
|
36
|
+
: a.path.localeCompare(b.path);
|
|
37
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.REGISTRY_SUPPORTED_STACKS = exports.REGISTRY_BY_RUNTIME = exports.STACK_RUNTIME = void 0;
|
|
7
|
+
exports.resolveRegistryPackage = resolveRegistryPackage;
|
|
8
|
+
exports.loadRegistry = loadRegistry;
|
|
9
|
+
exports.extractUsageBlock = extractUsageBlock;
|
|
10
|
+
exports.parseDependsOn = parseDependsOn;
|
|
11
|
+
exports.tokenMatches = tokenMatches;
|
|
12
|
+
exports.resolveDependencyClosure = resolveDependencyClosure;
|
|
13
|
+
exports.planAdd = planAdd;
|
|
14
|
+
exports.applyAdd = applyAdd;
|
|
15
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
const npm_pack_1 = require("../../utils/npm-pack");
|
|
18
|
+
const error_1 = require("../../utils/error");
|
|
19
|
+
const logger_1 = require("../../utils/logger");
|
|
20
|
+
/**
|
|
21
|
+
* 解析链:stack → runtime → registry 包名。
|
|
22
|
+
*
|
|
23
|
+
* registry 包按 **运行时(runtime)** 命名分发(而非 stack):多个 stack 可共享同一 runtime
|
|
24
|
+
* 的同一份 registry。runtime 不引入新的 meta 字段,从已有的 `.spark/meta.json.stack` 推得。
|
|
25
|
+
* STACK_RUNTIME: stack → runtime(design-html 跑在 buildless 运行时)
|
|
26
|
+
* REGISTRY_BY_RUNTIME: runtime → registry 包名
|
|
27
|
+
* 任一步查不到都明确报错(stack 无对应 runtime / runtime 无对应 registry)。
|
|
28
|
+
*/
|
|
29
|
+
exports.STACK_RUNTIME = {
|
|
30
|
+
'design-html': 'buildless',
|
|
31
|
+
};
|
|
32
|
+
exports.REGISTRY_BY_RUNTIME = {
|
|
33
|
+
buildless: '@lark-apaas/coding-registry-buildless',
|
|
34
|
+
};
|
|
35
|
+
/** 有对应 registry 的 stack 列表(stack 有 runtime 且该 runtime 有 registry 包)。 */
|
|
36
|
+
exports.REGISTRY_SUPPORTED_STACKS = Object.keys(exports.STACK_RUNTIME).filter((stack) => Boolean(exports.REGISTRY_BY_RUNTIME[exports.STACK_RUNTIME[stack]]));
|
|
37
|
+
/**
|
|
38
|
+
* stack → registry 包名。走 STACK_RUNTIME → REGISTRY_BY_RUNTIME 两跳。
|
|
39
|
+
* stack 无对应 runtime,或 runtime 无对应 registry,均抛 AppError。
|
|
40
|
+
*/
|
|
41
|
+
function resolveRegistryPackage(stack) {
|
|
42
|
+
const runtime = exports.STACK_RUNTIME[stack];
|
|
43
|
+
if (!runtime) {
|
|
44
|
+
throw new error_1.AppError('REGISTRY_STACK_UNSUPPORTED', `stack "${stack}" 没有对应的 runtime`, {
|
|
45
|
+
next_actions: [`支持 registry 的 stack:${exports.REGISTRY_SUPPORTED_STACKS.join(', ') || '(none)'}`],
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const packageName = exports.REGISTRY_BY_RUNTIME[runtime];
|
|
49
|
+
if (!packageName) {
|
|
50
|
+
throw new error_1.AppError('REGISTRY_RUNTIME_UNSUPPORTED', `runtime "${runtime}"(来自 stack "${stack}")没有对应的 registry 包`);
|
|
51
|
+
}
|
|
52
|
+
return packageName;
|
|
53
|
+
}
|
|
54
|
+
const USAGE_BEGIN = '/* BEGIN USAGE */';
|
|
55
|
+
const USAGE_END = '/* END USAGE */';
|
|
56
|
+
/**
|
|
57
|
+
* 拉取并解析某 stack 的 registry 包。
|
|
58
|
+
*
|
|
59
|
+
* 复用 fetchNpmPackage(npm pack + tar -xzf + 临时目录),与 template / steering 同一套
|
|
60
|
+
* tarball 基建。包内布局约定(SDK 文件**平铺在包根**,无外层 registry/ 目录):
|
|
61
|
+
* package/<subdir>/<sdk-file> ← 按目录组织的 SDK 文件,每个以 USAGE 块开头
|
|
62
|
+
* (scripts/ · components/ · stylesheets/ 等;CLI 不约束子目录名)
|
|
63
|
+
*
|
|
64
|
+
* 从包根递归扫整棵树,判定含 USAGE 块的为 SDK 条目(package.json / README / LICENSE 等无
|
|
65
|
+
* USAGE 块的文件自然跳过),解析其 USAGE 原文 + Depends。
|
|
66
|
+
* 调用方用完 **必须** 调 result.cleanup() 清理临时目录。
|
|
67
|
+
*/
|
|
68
|
+
function loadRegistry(opts) {
|
|
69
|
+
const packageName = resolveRegistryPackage(opts.stack);
|
|
70
|
+
const effectiveVersion = opts.version ?? 'latest';
|
|
71
|
+
(0, logger_1.log)('registry', `Fetching ${packageName}@${effectiveVersion}...`);
|
|
72
|
+
const fetched = (0, npm_pack_1.fetchNpmPackage)({ packageName, version: effectiveVersion });
|
|
73
|
+
try {
|
|
74
|
+
// 扫描根 = 包根(fetchNpmPackage 的 extractDir 即 tarball 内 package/ 目录)
|
|
75
|
+
const registryRoot = fetched.extractDir;
|
|
76
|
+
const entries = scanEntries(registryRoot);
|
|
77
|
+
return {
|
|
78
|
+
entries,
|
|
79
|
+
registryRoot,
|
|
80
|
+
version: fetched.version,
|
|
81
|
+
cleanup: () => {
|
|
82
|
+
fetched.cleanup();
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
fetched.cleanup();
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 可作为 SDK 条目的代码文件扩展名白名单。
|
|
93
|
+
* 只扫代码文件 —— README.md / LICENSE / package.json 等不在此列,避免文档里出现的
|
|
94
|
+
* USAGE 字面量(如 README 解释 `/* BEGIN USAGE */` 格式)被误判为 SDK 条目。
|
|
95
|
+
*/
|
|
96
|
+
const SDK_FILE_EXTENSIONS = new Set(['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.css']);
|
|
97
|
+
/**
|
|
98
|
+
* 条目所在的顶层目录白名单。只有包根下这几个目录(任意深度)里的代码文件才算条目,
|
|
99
|
+
* 包根直放的文件(eslint.config.js 等)、其它顶层目录(lib/ 等)一律排除——
|
|
100
|
+
* 避免 USAGE 可选后把工程配置 / 非 SDK 代码误判为条目。
|
|
101
|
+
*/
|
|
102
|
+
const SDK_TOP_DIRS = new Set(['components', 'scripts', 'stylesheets']);
|
|
103
|
+
/**
|
|
104
|
+
* 从包根递归扫整棵树,提取 SDK 条目。条目判据:
|
|
105
|
+
* 1. 在白名单顶层目录下(SDK_TOP_DIRS,任意深度);
|
|
106
|
+
* 2. 是代码文件(SDK_FILE_EXTENSIONS)。
|
|
107
|
+
* USAGE 块**可选**:有则解析描述 + Depends,无则 usage 为空、dependsOn 为空——仍是条目。
|
|
108
|
+
* name(去扩展名 basename)**不要求唯一**:同名的不同文件全部收录为独立条目,由 relPath
|
|
109
|
+
* (树内唯一)区分;寻址 / 拉取由 tokenMatches + resolveDependencyClosure 处理(同名 → 全拉)。
|
|
110
|
+
*/
|
|
111
|
+
function scanEntries(registryRoot) {
|
|
112
|
+
const entries = [];
|
|
113
|
+
const walk = (dir) => {
|
|
114
|
+
for (const dirent of node_fs_1.default.readdirSync(dir, { withFileTypes: true })) {
|
|
115
|
+
const absPath = node_path_1.default.join(dir, dirent.name);
|
|
116
|
+
if (dirent.isDirectory()) {
|
|
117
|
+
walk(absPath);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (!dirent.isFile())
|
|
121
|
+
continue;
|
|
122
|
+
// 只扫代码文件,排除 README/LICENSE/package.json 等非 SDK 文件
|
|
123
|
+
if (!SDK_FILE_EXTENSIONS.has(node_path_1.default.extname(dirent.name).toLowerCase()))
|
|
124
|
+
continue;
|
|
125
|
+
// 相对包根的路径,统一用 '/' 分隔(落地时再按平台 join)
|
|
126
|
+
const relPath = node_path_1.default.relative(registryRoot, absPath).split(node_path_1.default.sep).join('/');
|
|
127
|
+
// 只认白名单顶层目录下的文件(顶层段 ∈ SDK_TOP_DIRS)
|
|
128
|
+
if (!SDK_TOP_DIRS.has(relPath.split('/')[0]))
|
|
129
|
+
continue;
|
|
130
|
+
const usage = extractUsageBlock(node_fs_1.default.readFileSync(absPath, 'utf-8')) ?? '';
|
|
131
|
+
entries.push({
|
|
132
|
+
name: stripExt(dirent.name),
|
|
133
|
+
relPath,
|
|
134
|
+
usage,
|
|
135
|
+
dependsOn: parseDependsOn(usage),
|
|
136
|
+
absPath,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
walk(registryRoot);
|
|
141
|
+
// 按 relPath(唯一)稳定排序,便于 list 输出可预期
|
|
142
|
+
entries.sort((a, b) => a.relPath.localeCompare(b.relPath));
|
|
143
|
+
return entries;
|
|
144
|
+
}
|
|
145
|
+
/** 提取 BEGIN/END USAGE 标记之间的原文(含标记行)。无 USAGE 块返回 null。 */
|
|
146
|
+
function extractUsageBlock(content) {
|
|
147
|
+
const begin = content.indexOf(USAGE_BEGIN);
|
|
148
|
+
if (begin === -1)
|
|
149
|
+
return null;
|
|
150
|
+
const end = content.indexOf(USAGE_END, begin);
|
|
151
|
+
if (end === -1)
|
|
152
|
+
return null;
|
|
153
|
+
return content.slice(begin, end + USAGE_END.length);
|
|
154
|
+
}
|
|
155
|
+
/** 从 USAGE 块文本里解析 `// Depends: <name>` 行(可多行),返回去重后的依赖名列表。 */
|
|
156
|
+
function parseDependsOn(usage) {
|
|
157
|
+
const deps = [];
|
|
158
|
+
const seen = new Set();
|
|
159
|
+
for (const line of usage.split(/\r?\n/)) {
|
|
160
|
+
const m = /^\s*\/\/\s*Depends:\s*(.+?)\s*$/.exec(line);
|
|
161
|
+
if (m === null)
|
|
162
|
+
continue;
|
|
163
|
+
// 一行内允许逗号 / 空白分隔多个依赖
|
|
164
|
+
for (const raw of m[1].split(/[\s,]+/)) {
|
|
165
|
+
const name = raw.trim();
|
|
166
|
+
if (name !== '' && !seen.has(name)) {
|
|
167
|
+
seen.add(name);
|
|
168
|
+
deps.push(name);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return deps;
|
|
173
|
+
}
|
|
174
|
+
function stripExt(file) {
|
|
175
|
+
const ext = node_path_1.default.extname(file);
|
|
176
|
+
return ext === '' ? file : file.slice(0, -ext.length);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 一个 token 是否命中某条目。token 可写三种寻址形式(按特异度,任一相等即命中):
|
|
180
|
+
* - relPath:相对包根路径,如 components/foo.jsx(含 '/')
|
|
181
|
+
* - 完整文件名:含扩展名的 basename,如 foo.jsx
|
|
182
|
+
* - name:去扩展名的 basename,如 foo
|
|
183
|
+
* 三种形式无歧义重叠(relPath 含 '/',basename 不含;完整文件名含原扩展名,name 不含),
|
|
184
|
+
* 故用一个等值谓词即可。多个条目可同时命中同一 token(同名 → 全拉),由调用方处理。
|
|
185
|
+
*/
|
|
186
|
+
function tokenMatches(entry, token) {
|
|
187
|
+
if (token === entry.relPath)
|
|
188
|
+
return true;
|
|
189
|
+
const fileName = entry.relPath.split('/').pop() ?? '';
|
|
190
|
+
if (token === fileName)
|
|
191
|
+
return true;
|
|
192
|
+
return token === entry.name;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 解析 Depends 的传递闭包:从 requested token 出发,递归把所有依赖一并纳入。
|
|
196
|
+
*
|
|
197
|
+
* token 经 tokenMatches 解析成**一组**条目(同名 → 全拉),逐个展开。返回拓扑序
|
|
198
|
+
* (依赖在前、被依赖在后),便于按序拷贝。token 零命中抛 REGISTRY_ENTRY_NOT_FOUND;
|
|
199
|
+
* 检测循环依赖并抛 REGISTRY_CYCLE。visited / onStack / 环检测均以 relPath(唯一)为键,
|
|
200
|
+
* 故同名(去扩展名)的不同文件互不干扰、不会误判成环。
|
|
201
|
+
*/
|
|
202
|
+
function resolveDependencyClosure(entries, requested) {
|
|
203
|
+
const ordered = [];
|
|
204
|
+
const visited = new Set(); // by relPath
|
|
205
|
+
const onStack = new Set(); // by relPath
|
|
206
|
+
// token → 命中条目集合;零命中 fail-fast(避免拷半套)
|
|
207
|
+
const resolveToken = (token, trail) => {
|
|
208
|
+
const matches = entries.filter((e) => tokenMatches(e, token));
|
|
209
|
+
if (matches.length === 0) {
|
|
210
|
+
const via = trail.length > 0 ? `(被 "${trail[trail.length - 1]}" 依赖)` : '';
|
|
211
|
+
throw new error_1.AppError('REGISTRY_ENTRY_NOT_FOUND', `registry 没有条目 "${token}"${via}`, {
|
|
212
|
+
next_actions: ['用 `miaoda registry list` 查看可用条目'],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return matches;
|
|
216
|
+
};
|
|
217
|
+
const visit = (entry, trail) => {
|
|
218
|
+
if (visited.has(entry.relPath))
|
|
219
|
+
return;
|
|
220
|
+
if (onStack.has(entry.relPath)) {
|
|
221
|
+
throw new error_1.AppError('REGISTRY_CYCLE', `registry 条目依赖成环:${[...trail, entry.relPath].join(' -> ')}`);
|
|
222
|
+
}
|
|
223
|
+
onStack.add(entry.relPath);
|
|
224
|
+
for (const depToken of entry.dependsOn) {
|
|
225
|
+
for (const depEntry of resolveToken(depToken, [...trail, entry.relPath])) {
|
|
226
|
+
visit(depEntry, [...trail, entry.relPath]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
onStack.delete(entry.relPath);
|
|
230
|
+
visited.add(entry.relPath);
|
|
231
|
+
ordered.push(entry);
|
|
232
|
+
};
|
|
233
|
+
for (const token of requested) {
|
|
234
|
+
for (const entry of resolveToken(token, []))
|
|
235
|
+
visit(entry, []);
|
|
236
|
+
}
|
|
237
|
+
return ordered;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* 规划 add:解析依赖闭包 → 每个条目**拍平为 basename** 落到项目根 → 标记是否已存在。
|
|
241
|
+
* 纯计算,不落盘(dry-run 与真实 add 共用)。exists 在此快照(落盘前),故闭包内同名
|
|
242
|
+
* basename 撞车时双方 exists 都为 false、applyAdd 里后者覆盖前者。
|
|
243
|
+
*/
|
|
244
|
+
function planAdd(opts) {
|
|
245
|
+
const entries = resolveDependencyClosure(opts.entries, opts.names);
|
|
246
|
+
const files = entries.map((entry) => {
|
|
247
|
+
const dest = entry.relPath.split('/').pop() ?? entry.relPath; // 拍平为 basename
|
|
248
|
+
const destAbs = node_path_1.default.join(opts.targetDir, dest);
|
|
249
|
+
return {
|
|
250
|
+
entry: entry.name,
|
|
251
|
+
srcRelPath: entry.relPath,
|
|
252
|
+
dest,
|
|
253
|
+
destAbs,
|
|
254
|
+
srcAbs: entry.absPath,
|
|
255
|
+
exists: node_fs_1.default.existsSync(destAbs),
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
return { entries, files };
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 执行 add 计划:把 SDK 文件**拍平**拷到项目根。
|
|
262
|
+
* - 目标已存在且未 overwrite → skip(skip-by-disk 保护用户改动)
|
|
263
|
+
* - 目标已存在且 overwrite → 覆盖写
|
|
264
|
+
* - 目标不存在 → 写
|
|
265
|
+
* 闭包内同名 basename 撞车(双方 exists 均为 plan 前快照 false)→ 顺序拷贝、后者覆盖前者,
|
|
266
|
+
* added 去重只报一次。dryRun=true 时只分类不落盘。不写任何安装记账文件(项目文件树即状态)。
|
|
267
|
+
*/
|
|
268
|
+
function applyAdd(files, opts) {
|
|
269
|
+
const added = [];
|
|
270
|
+
const skipped = [];
|
|
271
|
+
const seen = new Set();
|
|
272
|
+
const pushUnique = (list, dest) => {
|
|
273
|
+
if (seen.has(dest))
|
|
274
|
+
return;
|
|
275
|
+
seen.add(dest);
|
|
276
|
+
list.push(dest);
|
|
277
|
+
};
|
|
278
|
+
for (const f of files) {
|
|
279
|
+
if (f.exists && !opts.overwrite) {
|
|
280
|
+
pushUnique(skipped, f.dest);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (!opts.dryRun) {
|
|
284
|
+
if (!node_fs_1.default.existsSync(f.srcAbs)) {
|
|
285
|
+
throw new error_1.AppError('REGISTRY_FILE_MISSING', `registry 包内缺少文件 ${f.srcRelPath}(条目 "${f.entry}")`);
|
|
286
|
+
}
|
|
287
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(f.destAbs), { recursive: true });
|
|
288
|
+
node_fs_1.default.copyFileSync(f.srcAbs, f.destAbs);
|
|
289
|
+
}
|
|
290
|
+
pushUnique(added, f.dest);
|
|
291
|
+
}
|
|
292
|
+
return { added, skipped };
|
|
293
|
+
}
|