@pactor-app/cli 0.1.0 → 1.0.0
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/dist/cli.js +60 -6
- package/package.json +4 -4
- package/templates/app/README.md +1 -1
- package/templates/app/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -52,6 +52,7 @@ import { join as join2 } from "path";
|
|
|
52
52
|
// src/dsl-io.ts
|
|
53
53
|
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
54
54
|
import { join } from "path";
|
|
55
|
+
import { isDslSourceRef } from "@pactor-app/core";
|
|
55
56
|
import { validatePageDsl } from "@pactor-app/schema";
|
|
56
57
|
import { parseDocument } from "yaml";
|
|
57
58
|
var DSL_FILE_RE = /\.(page|fragment)\.(yaml|yml)$/;
|
|
@@ -201,10 +202,23 @@ function walkDslTree(root, visit, basePath = "/body") {
|
|
|
201
202
|
visit(root, basePath);
|
|
202
203
|
if (Array.isArray(root.children)) {
|
|
203
204
|
root.children.forEach((child, index) => {
|
|
205
|
+
if (isDslSourceRef(child)) return;
|
|
204
206
|
walkDslTree(child, visit, `${basePath}/children/${index}`);
|
|
205
207
|
});
|
|
206
208
|
}
|
|
207
209
|
}
|
|
210
|
+
function walkPageTrees(data, visit) {
|
|
211
|
+
if (data.body !== void 0) {
|
|
212
|
+
walkDslTree(data.body, visit, "/body");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (Array.isArray(data.children)) {
|
|
216
|
+
data.children.forEach((child, index) => {
|
|
217
|
+
if (isDslSourceRef(child)) return;
|
|
218
|
+
walkDslTree(child, visit, `/children/${index}`);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
208
222
|
|
|
209
223
|
// src/commands/build.ts
|
|
210
224
|
function runBuild(args, io) {
|
|
@@ -334,6 +348,7 @@ function runCreate(args, io, templatesDir = defaultTemplatesDir()) {
|
|
|
334
348
|
|
|
335
349
|
// src/commands/inspect.ts
|
|
336
350
|
import { existsSync as existsSync4, statSync as statSync4 } from "fs";
|
|
351
|
+
import { isDslSourceRef as isDslSourceRef2 } from "@pactor-app/core";
|
|
337
352
|
function permissionCodes(permission) {
|
|
338
353
|
if (permission === void 0) return [];
|
|
339
354
|
if (typeof permission === "string") return [permission];
|
|
@@ -384,8 +399,21 @@ function runInspect(args, io) {
|
|
|
384
399
|
const componentCounts = /* @__PURE__ */ new Map();
|
|
385
400
|
const actions = [];
|
|
386
401
|
const permissions = [];
|
|
387
|
-
|
|
388
|
-
|
|
402
|
+
walkPageTrees(data, (node, path) => {
|
|
403
|
+
const nodeKey = node.type ?? `\u2192${node.component ?? "?"}`;
|
|
404
|
+
componentCounts.set(nodeKey, (componentCounts.get(nodeKey) ?? 0) + 1);
|
|
405
|
+
if (isDslSourceRef2(node.children)) {
|
|
406
|
+
const key = `source(${node.children.source.type})`;
|
|
407
|
+
componentCounts.set(key, (componentCounts.get(key) ?? 0) + 1);
|
|
408
|
+
}
|
|
409
|
+
if (Array.isArray(node.children)) {
|
|
410
|
+
for (const child of node.children) {
|
|
411
|
+
if (isDslSourceRef2(child)) {
|
|
412
|
+
const key = `source(${child.source.type})`;
|
|
413
|
+
componentCounts.set(key, (componentCounts.get(key) ?? 0) + 1);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
389
417
|
for (const [event, config] of Object.entries(node.events ?? {})) {
|
|
390
418
|
for (const action of actionList(config)) {
|
|
391
419
|
actions.push(` - ${path} events.${event} \u2192 ${action.action}`);
|
|
@@ -395,6 +423,18 @@ function runInspect(args, io) {
|
|
|
395
423
|
permissions.push(` - ${path} \u2192 ${code}`);
|
|
396
424
|
}
|
|
397
425
|
});
|
|
426
|
+
if (!data.body && isDslSourceRef2(data.children)) {
|
|
427
|
+
const key = `source(${data.children.source.type})`;
|
|
428
|
+
componentCounts.set(key, (componentCounts.get(key) ?? 0) + 1);
|
|
429
|
+
}
|
|
430
|
+
if (!data.body && Array.isArray(data.children)) {
|
|
431
|
+
for (const child of data.children) {
|
|
432
|
+
if (isDslSourceRef2(child)) {
|
|
433
|
+
const key = `source(${child.source.type})`;
|
|
434
|
+
componentCounts.set(key, (componentCounts.get(key) ?? 0) + 1);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
398
438
|
lines.push(`\u7EC4\u4EF6: ${[...componentCounts.values()].reduce((a, b) => a + b, 0)} \u4E2A`);
|
|
399
439
|
for (const [type, count] of [...componentCounts.entries()].sort()) {
|
|
400
440
|
lines.push(` - ${type} x${count}`);
|
|
@@ -481,8 +521,11 @@ function lintExpressions(data, findings) {
|
|
|
481
521
|
}
|
|
482
522
|
}
|
|
483
523
|
}
|
|
484
|
-
function lintComponentNaming(
|
|
485
|
-
|
|
524
|
+
function lintComponentNaming(data, findings) {
|
|
525
|
+
walkPageTrees(data, (node, path) => {
|
|
526
|
+
if (node.component !== void 0) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
486
529
|
if (typeof node.type !== "string" || !PASCAL_CASE_RE.test(node.type)) {
|
|
487
530
|
findings.push({
|
|
488
531
|
level: "warning",
|
|
@@ -507,7 +550,7 @@ function lintPermissionFormat(data, findings) {
|
|
|
507
550
|
}
|
|
508
551
|
};
|
|
509
552
|
check(permissionCodes2(data.page?.permission), "/page/permission");
|
|
510
|
-
|
|
553
|
+
walkPageTrees(data, (node, path) => {
|
|
511
554
|
check(permissionCodes2(node.permission), `${path}/permission`);
|
|
512
555
|
for (const [event, config] of Object.entries(node.events ?? {})) {
|
|
513
556
|
for (const action of actionList2(config)) {
|
|
@@ -533,10 +576,21 @@ function lintDslData(data, isFragment) {
|
|
|
533
576
|
}
|
|
534
577
|
lintExpressions(data, findings);
|
|
535
578
|
const typed = data;
|
|
536
|
-
lintComponentNaming(typed
|
|
579
|
+
lintComponentNaming(typed, findings);
|
|
537
580
|
lintPermissionFormat(typed, findings);
|
|
581
|
+
lintBodyChildrenConflict(typed, findings);
|
|
538
582
|
return findings;
|
|
539
583
|
}
|
|
584
|
+
function lintBodyChildrenConflict(data, findings) {
|
|
585
|
+
if (data.body !== void 0 && data.children !== void 0) {
|
|
586
|
+
findings.push({
|
|
587
|
+
level: "warning",
|
|
588
|
+
rule: "body-children-conflict",
|
|
589
|
+
path: "/children",
|
|
590
|
+
message: "body \u4E0E\u6839\u7EA7 children \u540C\u65F6\u58F0\u660E\uFF0Cchildren \u5C06\u88AB\u5FFD\u7565\uFF08body \u4F18\u5148\uFF09"
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
540
594
|
function runLint(args, io) {
|
|
541
595
|
if (args.positionals.length === 0) {
|
|
542
596
|
io.err("\u7528\u6CD5: pactor lint <paths...>");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pactor-app/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Pactor CLI: local DSL toolchain (validate / inspect / lint / schema / build / create)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pactor",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"yaml": "^2.9.0",
|
|
38
|
-
"@pactor-app/core": "
|
|
39
|
-
"@pactor-app/
|
|
40
|
-
"@pactor-app/
|
|
38
|
+
"@pactor-app/core": "1.0.0",
|
|
39
|
+
"@pactor-app/expression": "1.0.0",
|
|
40
|
+
"@pactor-app/schema": "1.0.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsup",
|
package/templates/app/README.md
CHANGED
|
@@ -13,6 +13,6 @@ pnpm dev
|
|
|
13
13
|
|
|
14
14
|
## 说明
|
|
15
15
|
|
|
16
|
-
- 依赖版本为语义化占位(`^
|
|
16
|
+
- 依赖版本为语义化占位(`^1.0.0` 等),请在 Pactor 发布后按实际版本对齐。
|
|
17
17
|
- 如需 `*.page.yaml` 的 TypeScript 类型声明,按 @pactor-app/vite-plugin 文档添加 `src/dsl-modules.d.ts`。
|
|
18
18
|
- 常用命令:`pactor validate src/pages/*.page.yaml`、`pactor lint src`、`pactor build src/pages -o dist/runtime`。
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"preview": "vite preview"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@pactor-app/app": "^
|
|
13
|
-
"@pactor-app/core": "^
|
|
14
|
-
"@pactor-app/resource": "^
|
|
15
|
-
"@pactor-app/ui": "^
|
|
12
|
+
"@pactor-app/app": "^1.0.0",
|
|
13
|
+
"@pactor-app/core": "^1.0.0",
|
|
14
|
+
"@pactor-app/resource": "^1.0.0",
|
|
15
|
+
"@pactor-app/ui": "^1.0.0",
|
|
16
16
|
"react": "^18.3.1",
|
|
17
17
|
"react-dom": "^18.3.1"
|
|
18
18
|
},
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@types/react": "^18.3.12",
|
|
21
21
|
"@types/react-dom": "^18.3.1",
|
|
22
22
|
"@vitejs/plugin-react": "^4.3.4",
|
|
23
|
-
"@pactor-app/vite-plugin": "^
|
|
23
|
+
"@pactor-app/vite-plugin": "^1.0.0",
|
|
24
24
|
"typescript": "^5.6.3",
|
|
25
25
|
"vite": "^5.4.11"
|
|
26
26
|
}
|