soma-kit 0.1.11 → 0.1.13
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 +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// 显隐规则:面板 / 步骤条变体都是「外层只放 core 写的 hidden、内层放布局类」两层;各步表单一直挂着,只靠外层显隐切换。
|
|
4
4
|
|
|
5
5
|
import { mergeClass } from '../../object-renderer/merge-class';
|
|
6
|
+
import { kitShellRecipe } from '../../recipes/container';
|
|
6
7
|
import { cls, esc, host } from '../link/shared';
|
|
7
|
-
import { kitText } from '../../i18n/kit-text';
|
|
8
8
|
import { kitIconHtml } from '../../base/icons';
|
|
9
9
|
|
|
10
10
|
/** 壳的内部区域名(`areaClass` 的合法键) */
|
|
@@ -13,7 +13,7 @@ export type StepFormArea = (typeof STEP_FORM_AREAS)[number];
|
|
|
13
13
|
|
|
14
14
|
export const STEP_FORM_CLASS = {
|
|
15
15
|
root: '@container flex justify-center',
|
|
16
|
-
card: 'flex w-full max-w-2xl flex-col gap-6
|
|
16
|
+
card: mergeClass('flex w-full max-w-2xl flex-col gap-6 p-6', kitShellRecipe()),
|
|
17
17
|
title: 'text-lg font-semibold text-fg',
|
|
18
18
|
steps: 'flex flex-wrap items-center gap-2',
|
|
19
19
|
stepItem: 'flex items-center gap-2',
|
|
@@ -26,7 +26,6 @@ export const STEP_FORM_CLASS = {
|
|
|
26
26
|
labelFut: 'text-sm text-fg-muted',
|
|
27
27
|
joint: 'w-6 border-t border-border-subtle',
|
|
28
28
|
panel: 'flex flex-col gap-3',
|
|
29
|
-
progress: 'text-sm text-fg-muted',
|
|
30
29
|
panelTitle: 'text-base font-semibold text-fg',
|
|
31
30
|
done: 'flex flex-col items-start gap-3',
|
|
32
31
|
doneTitle: 'text-lg font-semibold text-fg',
|
|
@@ -67,7 +66,7 @@ export function stepFormHtml(
|
|
|
67
66
|
parts: { title: string; steps: StepBlock[]; doneTitle: string; /** abandon: delete 才有:每个面板放一个「取消」钮 */ withAbort?: boolean },
|
|
68
67
|
areaClass: Record<string, string>,
|
|
69
68
|
extra: string | undefined,
|
|
70
|
-
|
|
69
|
+
_locale?: string,
|
|
71
70
|
): string {
|
|
72
71
|
const total = parts.steps.length;
|
|
73
72
|
const C = STEP_FORM_CLASS;
|
|
@@ -84,7 +83,8 @@ export function stepFormHtml(
|
|
|
84
83
|
});
|
|
85
84
|
const bar = `<nav aria-label="steps"${cls(mergeClass(C.steps, areaClass.steps))}>${items.join('')}</nav>`;
|
|
86
85
|
const panels = parts.steps.map((s, i) => {
|
|
87
|
-
|
|
86
|
+
// 步骤条已表达进度,面板头只放步骤标题(不再有「第 n 步 / 共 m 步」)
|
|
87
|
+
const head = `<h3${cls(C.panelTitle)}>${esc(s.title)}</h3>`;
|
|
88
88
|
return `<div data-soma-id="${esc(ids.panel(i))}"><div${cls(mergeClass(C.panel, areaClass.panel))}>${head}${s.form}${parts.withAbort === true ? host('Button', ids.abort(i)) : ''}</div></div>`;
|
|
89
89
|
});
|
|
90
90
|
const done = `<div data-soma-id="${esc(ids.done)}"><div${cls(mergeClass(C.done, areaClass.done))}>`
|
package/src/biz/types.ts
CHANGED
|
@@ -37,10 +37,9 @@ export interface KitOverlayDecl {
|
|
|
37
37
|
schema?: KitObject['schema'];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/**
|
|
40
|
+
/** 浮层事件绑具名动作:`{ action: 具名动作 }`(单管道;动作之后的提示 / 重取 / 关窗写在具名动作处理函数里) */
|
|
41
41
|
export interface KitOverlayEventAction {
|
|
42
42
|
action: string;
|
|
43
|
-
then?: 'saved' | 'close' | 'reload';
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
export interface KitBizInput {
|
|
@@ -66,7 +65,7 @@ export interface KitBizContext {
|
|
|
66
65
|
/** 已登记的基础组件名(内置 13 个 + App*) */
|
|
67
66
|
registeredComponents: ReadonlySet<string>;
|
|
68
67
|
/** 已登记的写死形状数据组件 */
|
|
69
|
-
staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[] }>;
|
|
68
|
+
staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[]; propTypes?: Readonly<Record<string, string>> }>;
|
|
70
69
|
/** 页面语言(`page.locale`,缺省应用 defaultLocale;未声明为空串):业务组件写进产物的内置文案按它取(`kitText(key, params, ctx.locale)`) */
|
|
71
70
|
locale?: string;
|
|
72
71
|
}
|
|
@@ -77,6 +76,8 @@ export interface KitBizRole {
|
|
|
77
76
|
views: Array<'list' | 'summary' | 'filter' | 'form'>;
|
|
78
77
|
/** 对象表(如 `subs.*`):值是「名字 -> 对象」 */
|
|
79
78
|
many?: boolean;
|
|
79
|
+
/** 该角色下对象声明允许的额外顶层键(如看板面板的 title / span / class、详情主记录的 subsLayout) */
|
|
80
|
+
extraKeys?: readonly string[];
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
export interface KitBizDefinition {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// AP-1(应用代码不直接 import soma-core*)在 kit 线的检查:`soma kit check` 递归扫描应用根下的 js/ts 源码,
|
|
2
|
+
// 命中即报 KIT-APP-013(诊断带文件、行号与改用 soma-kit/app 的建议)。规则册闸门 G84。
|
|
3
|
+
// 跳过:node_modules、.soma、tests/、test/(测试允许 import core 内部名校验产物)与其他点目录、构建产物目录。
|
|
4
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
5
|
+
|
|
6
|
+
const SKIP_DIRS = new Set(['node_modules', 'tests', 'test', 'dist', 'build', 'coverage']);
|
|
7
|
+
/** import / import type / export … from / 动态 import() / require() 里的 soma-core 或 soma-core/* 说明符 */
|
|
8
|
+
const IMPORT_CORE = /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)['"](soma-core(?:\/[^'"]*)?)['"]/g;
|
|
9
|
+
|
|
10
|
+
/** 扫描应用根目录;返回 KIT-APP-013 诊断(按文件名、行号有序);目录读不到当作空 */
|
|
11
|
+
export async function scanKitCoreImports(appDir: string): Promise<KitDiagnostic[]> {
|
|
12
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
13
|
+
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
14
|
+
const root = path.resolve(appDir);
|
|
15
|
+
const out: KitDiagnostic[] = [];
|
|
16
|
+
const walk = (dir: string): void => {
|
|
17
|
+
let entries: import('node:fs').Dirent[];
|
|
18
|
+
try {
|
|
19
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
24
|
+
const full = path.join(dir, e.name);
|
|
25
|
+
if (e.isDirectory()) {
|
|
26
|
+
if (!SKIP_DIRS.has(e.name) && !e.name.startsWith('.')) walk(full);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!/\.[cm]?[jt]sx?$/.test(e.name) || /\.d\.[cm]?ts$/.test(e.name)) continue;
|
|
30
|
+
let text: string;
|
|
31
|
+
try {
|
|
32
|
+
text = fs.readFileSync(full, 'utf8');
|
|
33
|
+
} catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const file = path.relative(root, full).split(path.sep).join('/');
|
|
37
|
+
text.split('\n').forEach((lineText, i) => {
|
|
38
|
+
for (const m of lineText.matchAll(IMPORT_CORE)) {
|
|
39
|
+
out.push({
|
|
40
|
+
code: 'KIT-APP-013',
|
|
41
|
+
path: `${file}:${i + 1}`,
|
|
42
|
+
file,
|
|
43
|
+
line: i + 1,
|
|
44
|
+
column: (m.index ?? 0) + 1,
|
|
45
|
+
message: `应用代码直接 import '${m[1]}'(AP-1:应用不直接依赖 soma-core*)`,
|
|
46
|
+
hint: `改为从 'soma-kit/app' 取用(装配名字在 soma-kit/app,服务端名字在 soma-kit/app/server)`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
walk(root);
|
|
53
|
+
return out;
|
|
54
|
+
}
|
package/src/cli/kit-cli.ts
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
// `soma kit explain <诊断码>` 与 `soma kit check <应用目录>` 的实现(bin/soma-kit.mjs 只拿参数、接标准输出、设退出码)。
|
|
2
2
|
// 说明正文读真源 kit-grammar.json#diagnostics,常见原因与正反示例读 #diagnosticExamples;建议由 compile/hints.ts 生成。
|
|
3
3
|
import grammarJson from '../../spec/kit-grammar.json';
|
|
4
|
-
import { closestOf, formatKitDiagnostic } from '../compile/hints';
|
|
4
|
+
import { closestOf, formatKitDiagnostic, kitDiagnosticFooter } from '../compile/hints';
|
|
5
5
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
6
|
+
import { formatKitThemeDegradation, type NineDimDegradation } from '../theme/theme-tokens';
|
|
7
|
+
import { scanKitCoreImports } from './core-imports';
|
|
8
|
+
import { scanKitViewWrites } from './view-writes';
|
|
9
|
+
import { packageNameOf, scaffoldKitApp } from './kit-init';
|
|
10
|
+
import { formatServiceEndpointReport, runServiceEndpointCheck, type ServiceEndpointWarning } from './service-endpoint-check';
|
|
11
|
+
import type { KitLayoutReport } from '../compile/layout-lint';
|
|
12
|
+
import type { KitAdvisory } from '../object-renderer/types';
|
|
13
|
+
import {
|
|
14
|
+
collectAdvisories,
|
|
15
|
+
formatAdvisories,
|
|
16
|
+
formatAdvisory,
|
|
17
|
+
formatLayoutPlan,
|
|
18
|
+
formatScoreSummary,
|
|
19
|
+
parseKitCheckArgs,
|
|
20
|
+
strictFails,
|
|
21
|
+
summarizeScores,
|
|
22
|
+
type KitScoreSummary,
|
|
23
|
+
} from './layout-cli';
|
|
6
24
|
|
|
7
25
|
type Examples = Record<string, { causes?: string[]; bad: string; good: string }>;
|
|
8
26
|
|
|
@@ -16,8 +34,21 @@ export interface KitCliIo {
|
|
|
16
34
|
|
|
17
35
|
export const KIT_CLI_USAGE = [
|
|
18
36
|
'Usage:',
|
|
37
|
+
' soma-kit init <目录> 生成最小可跑的 soma-kit 应用(已有同名文件则整体拒绝,不覆盖)',
|
|
19
38
|
' soma kit explain <诊断码> 打印诊断的完整说明、常见原因与正反示例',
|
|
20
|
-
' soma kit check <应用目录>
|
|
39
|
+
' soma kit check <应用目录> [--json] 编译应用全部页面并扫描源码是否直接 import soma-core*(KIT-APP-013)、展示对象方法是否对数组原地变异(KIT-VIEW-008),打印带修改建议的诊断;--json 在标准输出打印机器可读 JSON',
|
|
40
|
+
' 另核对页面里 /api/... 地址是否有对应服务文件与方法,不符只打印告警,不影响退出码',
|
|
41
|
+
' 退出码:0 全部通过;1 有诊断;2 用法错误(缺参数 / 未知选项)',
|
|
42
|
+
' soma kit check <应用目录> [--strict] [--profile ai|human] [--score]',
|
|
43
|
+
' 布局体检(KIT-LAYOUT-001…039):建议走 advisories 新通道(error / warn / advice),不影响 ok 与既有退出码语义;',
|
|
44
|
+
' --strict:有 warn / error 级建议时退出码为 1;--profile ai:取 AI 生成页同一严格档(缺省 human);',
|
|
45
|
+
' --score:打印每页质量分(0–100,只度量已知违例)与中位数;--json 里新增 advisories / score 字段',
|
|
46
|
+
' 弃用提示(仍生效但应迁移的旧拼写,如 KIT-LOCALE-002 的 @row.字段)单独成段(--json 为 deprecations),不影响 ok,--strict 时算失败',
|
|
47
|
+
' soma kit explain-layout <页面文件> [--profile ai|human]',
|
|
48
|
+
' 打印该页的布局规划(表格列 min/ideal/max 与来源、操作列、表单栏数、筛选常驻数、面板装箱)与该页的布局建议;',
|
|
49
|
+
' 页面文件相对当前目录或应用目录,应用目录取向上最近的含 soma.app.ts 的目录',
|
|
50
|
+
' soma kit migrate [应用目录] [--write] [--json] [--emit-views]',
|
|
51
|
+
' 把 0.1.6 时代的应用升级到 0.1.13:机械改写(缺省只演练)+ 只报告项与展示对象骨架;演练下有待改写项退出码为 1',
|
|
21
52
|
'',
|
|
22
53
|
].join('\n');
|
|
23
54
|
|
|
@@ -39,24 +70,129 @@ export function explainKitCode(raw: string): string | undefined {
|
|
|
39
70
|
return `${lines.join('\n')}\n`;
|
|
40
71
|
}
|
|
41
72
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
73
|
+
/** 异常 -> 诊断:自带结构化诊断的原样取用(KitDiagnosticError / KitAppAssemblyError / KitPackError),其余包成 KIT-APP-011 保留原消息 */
|
|
74
|
+
function diagnosticsOf(error: unknown, path: string): KitDiagnostic[] {
|
|
75
|
+
const list = (error as { diagnostics?: KitDiagnostic[] }).diagnostics;
|
|
76
|
+
if (Array.isArray(list) && list.length > 0) return list;
|
|
77
|
+
return [{ code: 'KIT-APP-011', path, message: (error as Error)?.message ?? String(error), hint: '按消息排查 soma.app.ts 及其依赖的加载错误;`soma kit explain KIT-APP-011` 看说明' }];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 装配一个 soma-kit 应用并编译全部页面;返回诊断(空 = 全部通过)、页面数与主题降级提示清单;任何失败都归成诊断,不向外抛 */
|
|
81
|
+
async function checkApp(
|
|
82
|
+
appDir: string,
|
|
83
|
+
load: (file: string) => unknown,
|
|
84
|
+
): Promise<{ pages: number; diagnostics: KitDiagnostic[]; degradations: readonly NineDimDegradation[]; layoutReports?: ReadonlyMap<string, KitLayoutReport>; deprecations?: readonly KitAdvisory[]; root: string }> {
|
|
44
85
|
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
45
86
|
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
46
87
|
const root = path.resolve(appDir);
|
|
47
88
|
const file = path.join(root, 'soma.app.ts');
|
|
48
|
-
if (!fs.existsSync(file))
|
|
89
|
+
if (!fs.existsSync(file)) {
|
|
90
|
+
return {
|
|
91
|
+
pages: 0,
|
|
92
|
+
diagnostics: [{ code: 'KIT-APP-010', path: root, message: `${root} 下没有 soma.app.ts(应用装配入口)`, hint: '把应用目录指到含 soma.app.ts 的目录,或先创建 soma.app.ts' }],
|
|
93
|
+
degradations: [],
|
|
94
|
+
root,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
49
97
|
process.env.SOMA_HOST_DIR = root;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
if (typeof assembly.server !== 'function') throw new Error('soma.app.ts 的默认导出不是 defineKitApp(...) 的装配(没有 server())');
|
|
98
|
+
const prevCheckFlag = process.env.SOMA_KIT_CHECK;
|
|
99
|
+
process.env.SOMA_KIT_CHECK = '1';
|
|
53
100
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
101
|
+
let assembly: {
|
|
102
|
+
server?: () => Promise<{
|
|
103
|
+
artifacts?: ReadonlyMap<string, unknown>;
|
|
104
|
+
diagnostics?: readonly KitDiagnostic[];
|
|
105
|
+
themeDegradations?: readonly NineDimDegradation[];
|
|
106
|
+
layoutReports?: ReadonlyMap<string, KitLayoutReport>;
|
|
107
|
+
deprecations?: readonly KitAdvisory[];
|
|
108
|
+
}>;
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
const loaded = load(file) as { default?: unknown };
|
|
112
|
+
assembly = (loaded.default ?? loaded) as typeof assembly;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
return { pages: 0, diagnostics: diagnosticsOf(error, file), degradations: [], root };
|
|
115
|
+
}
|
|
116
|
+
if (typeof assembly.server !== 'function') {
|
|
117
|
+
return {
|
|
118
|
+
pages: 0,
|
|
119
|
+
diagnostics: [{ code: 'KIT-APP-010', path: file, message: 'soma.app.ts 的默认导出不是 defineKitApp(...) 的装配(没有 server())', hint: '写成 export default defineKitApp({ ... })' }],
|
|
120
|
+
degradations: [],
|
|
121
|
+
root,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const face = await assembly.server();
|
|
126
|
+
return {
|
|
127
|
+
pages: face.artifacts?.size ?? 0,
|
|
128
|
+
diagnostics: [...(face.diagnostics ?? [])],
|
|
129
|
+
degradations: face.themeDegradations ?? [],
|
|
130
|
+
...(face.layoutReports !== undefined ? { layoutReports: face.layoutReports } : {}),
|
|
131
|
+
...(face.deprecations !== undefined && face.deprecations.length > 0 ? { deprecations: face.deprecations } : {}),
|
|
132
|
+
root,
|
|
133
|
+
};
|
|
134
|
+
} catch (error) {
|
|
135
|
+
return { pages: 0, diagnostics: diagnosticsOf(error, file), degradations: [], root };
|
|
136
|
+
}
|
|
137
|
+
} finally {
|
|
138
|
+
if (prevCheckFlag === undefined) delete process.env.SOMA_KIT_CHECK;
|
|
139
|
+
else process.env.SOMA_KIT_CHECK = prevCheckFlag;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** `soma kit check --json` 的输出形状(稳定契约):ok 为 true 当且仅当 diagnostics 为空 */
|
|
144
|
+
export interface KitCheckReport {
|
|
145
|
+
ok: boolean;
|
|
146
|
+
pages: number;
|
|
147
|
+
diagnostics: KitDiagnostic[];
|
|
148
|
+
degradations?: readonly NineDimDegradation[];
|
|
149
|
+
/** 接口落点告警(可选;不计入 diagnostics,不影响 ok 与退出码) */
|
|
150
|
+
endpointWarnings?: readonly ServiceEndpointWarning[];
|
|
151
|
+
/** 接口落点核对整体跳过的原因(可选) */
|
|
152
|
+
endpointCheckSkipped?: string;
|
|
153
|
+
/** 布局体检建议(RV-1117,与 diagnostics 并行的新通道;只在有建议时出现,不影响 ok) */
|
|
154
|
+
advisories?: readonly KitAdvisory[];
|
|
155
|
+
/** 弃用提示(仍生效但应迁移的旧拼写,如 KIT-LOCALE-002;只在有时出现,不影响 ok,--strict 时算失败) */
|
|
156
|
+
deprecations?: readonly KitAdvisory[];
|
|
157
|
+
/** 体检所用档案(有 advisories 时给) */
|
|
158
|
+
profile?: 'human' | 'ai';
|
|
159
|
+
/** --score:每页质量分与中位数 */
|
|
160
|
+
score?: KitScoreSummary;
|
|
161
|
+
/** --strict:布局建议是否使退出码失败 */
|
|
162
|
+
strict?: { failed: boolean };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 读各页面源(相对应用根的展示路径)用于按路径定位行列;读不到的跳过。 */
|
|
166
|
+
async function readPageSources(root: string | undefined, files: readonly string[]): Promise<ReadonlyMap<string, string>> {
|
|
167
|
+
const out = new Map<string, string>();
|
|
168
|
+
if (root === undefined) return out;
|
|
169
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
170
|
+
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
171
|
+
for (const f of files) {
|
|
172
|
+
for (const candidate of [path.resolve(root, f), path.resolve(root, 'pages', f)]) {
|
|
173
|
+
try {
|
|
174
|
+
out.set(f, fs.readFileSync(candidate, 'utf8'));
|
|
175
|
+
break;
|
|
176
|
+
} catch {
|
|
177
|
+
// 展示路径与磁盘路径对不上时放弃定位,建议仍照常打印(只是没有行列)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** 由页面文件向上找应用目录(最近的含 soma.app.ts 的祖先);返回应用目录与页面相对应用根的路径。 */
|
|
185
|
+
async function locateAppOfPage(pageFile: string): Promise<{ appDir: string; relFile: string; base: string } | undefined> {
|
|
186
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
187
|
+
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
188
|
+
const abs = path.resolve(pageFile);
|
|
189
|
+
if (!fs.existsSync(abs) || !fs.statSync(abs).isFile()) return undefined;
|
|
190
|
+
let dir = path.dirname(abs);
|
|
191
|
+
for (;;) {
|
|
192
|
+
if (fs.existsSync(path.join(dir, 'soma.app.ts'))) return { appDir: dir, relFile: path.relative(dir, abs).split(path.sep).join('/'), base: path.basename(abs) };
|
|
193
|
+
const up = path.dirname(dir);
|
|
194
|
+
if (up === dir) return undefined;
|
|
195
|
+
dir = up;
|
|
60
196
|
}
|
|
61
197
|
}
|
|
62
198
|
|
|
@@ -78,24 +214,117 @@ export async function runKitCli(args: readonly string[], io: KitCliIo, load: (fi
|
|
|
78
214
|
io.out(text);
|
|
79
215
|
return 0;
|
|
80
216
|
}
|
|
81
|
-
if (sub === '
|
|
217
|
+
if (sub === 'migrate') {
|
|
218
|
+
const { runKitMigrate } = await import('./migrate');
|
|
219
|
+
return runKitMigrate(rest, io);
|
|
220
|
+
}
|
|
221
|
+
if (sub === 'init') {
|
|
82
222
|
const dir = rest[0];
|
|
83
223
|
if (dir === undefined) {
|
|
84
|
-
io.err(`[soma
|
|
224
|
+
io.err(`[soma-kit init] 缺目录\n${KIT_CLI_USAGE}`);
|
|
85
225
|
return 1;
|
|
86
226
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return 0;
|
|
92
|
-
}
|
|
93
|
-
io.out(`FAIL ${diagnostics.length} 条诊断\n${diagnostics.map((d) => ` ${formatKitDiagnostic(d)}`).join('\n')}\n`);
|
|
227
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
228
|
+
const result = await scaffoldKitApp(dir, { name: packageNameOf(path.basename(path.resolve(dir))) });
|
|
229
|
+
if (result.conflicts.length > 0) {
|
|
230
|
+
io.err(`[soma-kit init] ${result.root} 下已有同名文件,未写入任何内容:\n${result.conflicts.map((f) => ` ${f}`).join('\n')}\n`);
|
|
94
231
|
return 1;
|
|
95
|
-
}
|
|
96
|
-
|
|
232
|
+
}
|
|
233
|
+
const where = path.relative(process.cwd(), result.root) || '.';
|
|
234
|
+
io.out(`已生成 ${result.created.length} 个文件到 ${result.root}\n${result.created.map((f) => ` ${f}`).join('\n')}\n\n下一步:\n${where === '.' ? '' : ` cd ${where}\n`} npm install\n npm run dev # 打开 http://localhost:3000/orders\n`);
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
if (sub === 'check') {
|
|
238
|
+
const parsed = parseKitCheckArgs(rest);
|
|
239
|
+
if (parsed.unknownFlags.length > 0) {
|
|
240
|
+
io.err(`[soma kit check] 未知选项 ${parsed.unknownFlags.join(' ')}\n${KIT_CLI_USAGE}`);
|
|
241
|
+
return 2;
|
|
242
|
+
}
|
|
243
|
+
if (parsed.errors.length > 0) {
|
|
244
|
+
io.err(`[soma kit check] ${parsed.errors.join(';')}\n${KIT_CLI_USAGE}`);
|
|
245
|
+
return 2;
|
|
246
|
+
}
|
|
247
|
+
const dir = parsed.dir;
|
|
248
|
+
if (dir === undefined) {
|
|
249
|
+
io.err(`[soma kit check] 缺应用目录\n${KIT_CLI_USAGE}`);
|
|
250
|
+
return 2;
|
|
251
|
+
}
|
|
252
|
+
const checked = await checkApp(dir, load);
|
|
253
|
+
const pages = checked.pages;
|
|
254
|
+
// 布局体检(RV-1117):advisories 是与 diagnostics 并行的新通道,不进 diagnostics、不改 ok;--strict 才影响退出码
|
|
255
|
+
const reports = checked.layoutReports ?? new Map<string, KitLayoutReport>();
|
|
256
|
+
const advisories: KitAdvisory[] = collectAdvisories(reports, parsed.profile, await readPageSources(checked.root, [...reports.keys()]));
|
|
257
|
+
const scoreSummary: KitScoreSummary | undefined = parsed.score ? summarizeScores(reports, parsed.profile) : undefined;
|
|
258
|
+
// 弃用提示(KIT-LOCALE-002 等):建议性输出,不进 diagnostics / ok;--strict 与布局建议同口径(warn 以上算失败)
|
|
259
|
+
const deprecations: readonly KitAdvisory[] = checked.deprecations ?? [];
|
|
260
|
+
const strictFailed = parsed.strict && strictFails([...advisories, ...deprecations]);
|
|
261
|
+
const deprecationText = deprecations.length === 0 ? '' : `弃用提示 ${deprecations.length} 条(仍生效但应迁移;不影响 ok,--strict 时算失败)\n${deprecations.map(formatAdvisory).join('\n')}\n`;
|
|
262
|
+
// AP-1:应用源码不直接 import soma-core*(KIT-APP-013),展示对象方法写入与对象/动作引用核对,与装配结果合并输出
|
|
263
|
+
const diagnostics = [...(await scanKitCoreImports(dir)), ...(await scanKitViewWrites(dir, load)), ...checked.diagnostics];
|
|
264
|
+
const degradations = checked.degradations;
|
|
265
|
+
// 接口落点核对:只出告警,不进诊断、不改退出码;编译通过或失败都跑
|
|
266
|
+
const endpoints = await runServiceEndpointCheck(dir);
|
|
267
|
+
const endpointText = formatServiceEndpointReport(endpoints);
|
|
268
|
+
if (parsed.json) {
|
|
269
|
+
const report: KitCheckReport = {
|
|
270
|
+
ok: diagnostics.length === 0,
|
|
271
|
+
pages,
|
|
272
|
+
diagnostics,
|
|
273
|
+
...(degradations.length > 0 ? { degradations } : {}),
|
|
274
|
+
...(endpoints.warnings.length > 0 || endpoints.skipped !== undefined
|
|
275
|
+
? { endpointWarnings: endpoints.warnings, ...(endpoints.skipped !== undefined ? { endpointCheckSkipped: endpoints.skipped } : {}) }
|
|
276
|
+
: {}),
|
|
277
|
+
// 只新增字段:既有字段与 ok 语义不变;没有建议 / 没要分数时这两个键都不出现
|
|
278
|
+
...(advisories.length > 0 ? { advisories, profile: parsed.profile } : {}),
|
|
279
|
+
...(deprecations.length > 0 ? { deprecations } : {}),
|
|
280
|
+
...(scoreSummary !== undefined ? { score: scoreSummary } : {}),
|
|
281
|
+
...(parsed.strict ? { strict: { failed: strictFailed } } : {}),
|
|
282
|
+
};
|
|
283
|
+
io.out(`${JSON.stringify(report, null, 2)}\n`);
|
|
284
|
+
return report.ok && !strictFailed ? 0 : 1;
|
|
285
|
+
}
|
|
286
|
+
const degradationLines =
|
|
287
|
+
degradations.length > 0
|
|
288
|
+
? `${degradations.flatMap((d) => formatKitThemeDegradation(d)).map((line) => ` ${line}`).join('\n')}\n`
|
|
289
|
+
: '';
|
|
290
|
+
const layoutText = `${formatAdvisories(advisories, parsed.profile)}${deprecationText}${scoreSummary !== undefined ? formatScoreSummary(scoreSummary) : ''}`;
|
|
291
|
+
if (diagnostics.length === 0) {
|
|
292
|
+
io.out(`OK 页面 ${pages} 个,零诊断\n${degradationLines}${layoutText}${endpointText}${strictFailed ? 'FAIL --strict:存在 warn / error 级布局建议或弃用提示\n' : ''}`);
|
|
293
|
+
return strictFailed ? 1 : 0;
|
|
294
|
+
}
|
|
295
|
+
const footer = kitDiagnosticFooter(diagnostics.map((d) => d.code));
|
|
296
|
+
io.out(`FAIL ${diagnostics.length} 条诊断\n${diagnostics.map((d) => ` ${formatKitDiagnostic(d)}`).join('\n')}\n${degradationLines}${footer === '' ? '' : `${footer}\n`}${layoutText}${endpointText}`);
|
|
297
|
+
return 1;
|
|
298
|
+
}
|
|
299
|
+
if (sub === 'explain-layout') {
|
|
300
|
+
const flagged = rest.filter((x) => x.startsWith('--') && x !== '--profile' && !x.startsWith('--profile='));
|
|
301
|
+
const parsed = parseKitCheckArgs(rest);
|
|
302
|
+
if (flagged.length > 0 || parsed.errors.length > 0) {
|
|
303
|
+
io.err(`[soma kit explain-layout] ${flagged.length > 0 ? `未知选项 ${flagged.join(' ')}` : parsed.errors.join(';')}\n${KIT_CLI_USAGE}`);
|
|
304
|
+
return 2;
|
|
305
|
+
}
|
|
306
|
+
if (parsed.dir === undefined) {
|
|
307
|
+
io.err(`[soma kit explain-layout] 缺页面文件\n${KIT_CLI_USAGE}`);
|
|
308
|
+
return 2;
|
|
309
|
+
}
|
|
310
|
+
const found = await locateAppOfPage(parsed.dir);
|
|
311
|
+
if (found === undefined) {
|
|
312
|
+
io.err(`[soma kit explain-layout] 找不到页面文件 ${parsed.dir},或它所在目录往上没有 soma.app.ts\n`);
|
|
313
|
+
return 2;
|
|
314
|
+
}
|
|
315
|
+
const checked = await checkApp(found.appDir, load);
|
|
316
|
+
const reports = checked.layoutReports ?? new Map<string, KitLayoutReport>();
|
|
317
|
+
const key = [...reports.keys()].find((k) => k === found.relFile || found.relFile.endsWith(`/${k}`) || k.endsWith(`/${found.base}`) || k === found.base);
|
|
318
|
+
if (key === undefined) {
|
|
319
|
+
const hint = checked.diagnostics.length > 0 ? `;应用编译有 ${checked.diagnostics.length} 条诊断,先 soma kit check 修掉` : '';
|
|
320
|
+
io.err(`[soma kit explain-layout] 没有 ${found.relFile} 的布局规划(页面没编译出来${hint})\n`);
|
|
97
321
|
return 1;
|
|
98
322
|
}
|
|
323
|
+
const report = reports.get(key) as KitLayoutReport;
|
|
324
|
+
const sources = await readPageSources(checked.root, [key]);
|
|
325
|
+
const located = collectAdvisories(new Map([[key, report]]), parsed.profile, sources);
|
|
326
|
+
io.out(`${formatLayoutPlan(key, report.plan)}${located.length > 0 ? `\n${formatAdvisories(located, parsed.profile)}` : ''}${formatScoreSummary(summarizeScores(new Map([[key, report]]), parsed.profile))}`);
|
|
327
|
+
return 0;
|
|
99
328
|
}
|
|
100
329
|
io.err(KIT_CLI_USAGE);
|
|
101
330
|
return sub === undefined || sub === 'help' || sub === '--help' ? 0 : 1;
|