@kosdev-code/kos-ddk-cli 0.0.0-stage → 0.1.0-dev.55
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 +165 -2
- package/agent-plugin/.claude-plugin/marketplace.json +13 -0
- package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +8 -0
- package/agent-plugin/kos-ddk-tools/.mcp.json +11 -0
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-planner.md +40 -0
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +33 -0
- package/agent-plugin/kos-ddk-tools/catalog/contributions.json +877 -0
- package/agent-plugin/kos-ddk-tools/mcp.json +12 -0
- package/agent-plugin/kos-ddk-tools/plugin.json +7 -0
- package/agent-plugin/kos-ddk-tools/reference/reference.json +19339 -0
- package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48633 -0
- package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +74 -0
- package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +49 -0
- package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +39 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +113 -0
- package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +37 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
- package/catalog/contributions.json +877 -0
- package/guides/ddk-dev.md +47 -0
- package/guides/getting-started.md +117 -0
- package/guides/storybook.md +104 -0
- package/package.json +33 -3
- package/reference/reference.json +19339 -0
- package/src/build-paths.mjs +20 -0
- package/src/codegen/contribution.mjs +425 -0
- package/src/codegen/descriptor.mjs +210 -0
- package/src/codegen/ncui-descriptor.mjs +134 -0
- package/src/codegen/overrides.mjs +263 -0
- package/src/codegen/project.mjs +242 -0
- package/src/extension.mjs +32 -0
- package/src/generators/agent-install.mjs +80 -0
- package/src/generators/catalog.mjs +81 -0
- package/src/generators/contributions.mjs +151 -0
- package/src/generators/dashboard.mjs +241 -0
- package/src/generators/descriptor-entries.mjs +53 -0
- package/src/generators/descriptor-project.mjs +79 -0
- package/src/generators/dev.mjs +231 -0
- package/src/generators/override-prompts.mjs +27 -0
- package/src/generators/plugin-project.mjs +66 -0
- package/src/generators/theme-project.mjs +45 -0
- package/src/handlers.mjs +315 -0
- package/src/mcp/pkg-info.mjs +7 -0
- package/src/mcp/plugin-inspect.mjs +292 -0
- package/src/mcp/reference.mjs +264 -0
- package/src/mcp/server.mjs +12 -0
- package/src/mcp/tools.mjs +575 -0
- package/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
- package/templates/cui/index.ts__template__ +1 -0
- package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
- package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
- package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
- package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
- package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
- package/templates/macro-summary/index.ts__template__ +1 -0
- package/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
- package/templates/nav/index.ts__template__ +1 -0
- package/templates/plugin-project/.storybook/preview.tsx.template +113 -0
- package/templates/plugin-project/.storybook/registration.ts.template +6 -0
- package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
- package/templates/pump-detail/index.ts__template__ +1 -0
- package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
- package/templates/pump-summary/index.ts__template__ +1 -0
- package/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
- package/templates/setup/index.ts__template__ +1 -0
- package/templates/theme-project/theme/assets/component.css.template +2 -0
- package/templates/theme-project/theme/assets/generic.css.template +2 -0
- package/templates/theme-project/theme/assets/semantic.css.template +2 -0
- package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
- package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
- package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
- package/templates/trouble-action/index.ts__template__ +1 -0
- package/templates/utility/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/utility/__nameDashCase__.tsx__template__ +37 -0
- package/templates/utility/index.ts__template__ +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Where the build writes the contribution catalog and the reference; the agent-plugin
|
|
2
|
+
// bundle swaps this module for its own copies' locations.
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const packageRoot = path.resolve(
|
|
7
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
8
|
+
".."
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const CATALOG_PATH = path.join(
|
|
12
|
+
packageRoot,
|
|
13
|
+
"catalog",
|
|
14
|
+
"contributions.json"
|
|
15
|
+
);
|
|
16
|
+
export const REFERENCE_PATH = path.join(
|
|
17
|
+
packageRoot,
|
|
18
|
+
"reference",
|
|
19
|
+
"reference.json"
|
|
20
|
+
);
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// DDK contributions (component, story, index, .kos.json entry, i18n title) in a
|
|
2
|
+
// plugin project. Shared by the ddk:* commands and the DDK MCP tools.
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
findProjectByName,
|
|
6
|
+
generateComponent,
|
|
7
|
+
normalizeAllValues,
|
|
8
|
+
updateJson,
|
|
9
|
+
} from "@kosdev-code/kos-codegen-core";
|
|
10
|
+
import { TEMPLATES_DIR, registerDdkHandlers } from "../handlers.mjs";
|
|
11
|
+
import {
|
|
12
|
+
addDescriptorEntry,
|
|
13
|
+
descriptorListsSlot,
|
|
14
|
+
findDescriptorProjects,
|
|
15
|
+
} from "./descriptor.mjs";
|
|
16
|
+
import { alsoReplacedNotes, resolveOverride } from "./overrides.mjs";
|
|
17
|
+
|
|
18
|
+
/** Extension point → plugin type and what a contribution of it needs. */
|
|
19
|
+
export const CONTRIBUTION_TYPES = {
|
|
20
|
+
cui: {
|
|
21
|
+
pluginType: "ddk.cui",
|
|
22
|
+
label: "DDK CUI Configuration",
|
|
23
|
+
required: "cuiDescriptor",
|
|
24
|
+
description:
|
|
25
|
+
"Create a CUI configuration; --descriptor is the CUI's appId from /api/app/kosdev.ddk/cui",
|
|
26
|
+
},
|
|
27
|
+
setup: {
|
|
28
|
+
pluginType: "ddk.setup",
|
|
29
|
+
label: "DDK Setup Step",
|
|
30
|
+
overridable: "setupDescriptor",
|
|
31
|
+
listedIn: "kondra.ncui.setup.steps",
|
|
32
|
+
descriptorType: "setup",
|
|
33
|
+
description:
|
|
34
|
+
"Create a setup step; --descriptor is its kondra.ncui.setup.steps entry (default: from the name)",
|
|
35
|
+
},
|
|
36
|
+
utility: {
|
|
37
|
+
pluginType: "ddk.utility",
|
|
38
|
+
label: "DDK Utility",
|
|
39
|
+
overridable: "utilDescriptor",
|
|
40
|
+
listedIn: "kondra.ncui.utilities",
|
|
41
|
+
descriptorType: "utility",
|
|
42
|
+
description:
|
|
43
|
+
"Create a utility; --descriptor is its kondra.ncui.utilities entry (default: from the name)",
|
|
44
|
+
},
|
|
45
|
+
nav: {
|
|
46
|
+
pluginType: "ddk.nav",
|
|
47
|
+
label: "DDK Navigation View",
|
|
48
|
+
overridable: "navDescriptor",
|
|
49
|
+
listedIn: "kondra.ncui.navigations",
|
|
50
|
+
descriptorType: "nav",
|
|
51
|
+
// A navigation view fills a kondra.ncui.navigations path; no name is one.
|
|
52
|
+
slotRequired: true,
|
|
53
|
+
description:
|
|
54
|
+
"Create a navigation view; --descriptor is its kondra.ncui.navigations entry, e.g. settings.water for a Settings tab",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** The keys each component template translates beyond its title, with their English text. */
|
|
59
|
+
export const TEMPLATE_KEYS = {
|
|
60
|
+
"ddk.cui": { proceed: "Proceed" },
|
|
61
|
+
"ddk.setup": { proceed: "Proceed" },
|
|
62
|
+
"ddk.utility": { proceed: "Proceed" },
|
|
63
|
+
"ddk.dashboardDetail": { close: "Close" },
|
|
64
|
+
"ddk.troubleAction": { resolve: "Resolve" },
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Adds the template's keys to the plugin's en locale file, keeping existing values. */
|
|
68
|
+
function addTemplateKeys(codegenFs, pluginType, project) {
|
|
69
|
+
const keys = TEMPLATE_KEYS[pluginType];
|
|
70
|
+
const sourceRoot = findProjectByName(codegenFs.root, project)?.sourceRoot;
|
|
71
|
+
if (!keys || !sourceRoot) return;
|
|
72
|
+
const localePath = path.join(
|
|
73
|
+
sourceRoot,
|
|
74
|
+
"assets",
|
|
75
|
+
"locales",
|
|
76
|
+
"en",
|
|
77
|
+
`${project}.json`
|
|
78
|
+
);
|
|
79
|
+
if (!codegenFs.exists(localePath)) return;
|
|
80
|
+
updateJson(codegenFs, localePath, (json) => ({ ...keys, ...json }));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Refuses a name whose component the plugin already exposes: module federation
|
|
85
|
+
* exposes each component by name, so a second one would replace the first.
|
|
86
|
+
*/
|
|
87
|
+
function assertNameFree(codegenFs, project, name) {
|
|
88
|
+
const root = findProjectByName(codegenFs.root, project)?.root;
|
|
89
|
+
const kosJson = root && codegenFs.read(path.join(root, ".kos.json"));
|
|
90
|
+
if (!kosJson) return;
|
|
91
|
+
const experiences =
|
|
92
|
+
JSON.parse(kosJson).kos?.ui?.plugin?.contributes?.experiences ?? {};
|
|
93
|
+
const pascal = normalizeAllValues({ name }).namePascalCase;
|
|
94
|
+
const taken = Object.values(experiences).find((experience) =>
|
|
95
|
+
[pascal, `${pascal}Summary`, `${pascal}Detail`].includes(
|
|
96
|
+
experience.component
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
if (taken) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`${project} already has a component ${taken.component} (${taken.location}); components are exposed by name, so choose another --name (kosui ddk:descriptor-entries lists an existing contribution's slot in a descriptor project)`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function generate(codegenFs, pluginType, { name, project, ...extra }) {
|
|
107
|
+
registerDdkHandlers();
|
|
108
|
+
generateComponent(codegenFs, TEMPLATES_DIR, {
|
|
109
|
+
name,
|
|
110
|
+
appProject: project,
|
|
111
|
+
type: "components",
|
|
112
|
+
pluginType,
|
|
113
|
+
useEmotionCss: false,
|
|
114
|
+
appDirectory: "",
|
|
115
|
+
modelDirectory: "",
|
|
116
|
+
...extra,
|
|
117
|
+
});
|
|
118
|
+
addTemplateKeys(codegenFs, pluginType, project);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function requireOption(value, flag) {
|
|
122
|
+
if (!value) throw new Error(`${flag} is required`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const rankField = (rank) => (rank === undefined ? {} : { rank });
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {{type: keyof CONTRIBUTION_TYPES, name: string, project: string,
|
|
129
|
+
* descriptor?: string, override?: string, rank?: number|string}} options
|
|
130
|
+
* `override` and `rank` apply to the rankable types (setup, utility, nav); `descriptor`
|
|
131
|
+
* to those and to cui, which requires it.
|
|
132
|
+
*/
|
|
133
|
+
export function generateDdkContribution(
|
|
134
|
+
codegenFs,
|
|
135
|
+
{
|
|
136
|
+
type,
|
|
137
|
+
name,
|
|
138
|
+
project,
|
|
139
|
+
descriptor,
|
|
140
|
+
override,
|
|
141
|
+
rank,
|
|
142
|
+
descriptorProject,
|
|
143
|
+
roles,
|
|
144
|
+
column,
|
|
145
|
+
}
|
|
146
|
+
) {
|
|
147
|
+
const spec = CONTRIBUTION_TYPES[type];
|
|
148
|
+
if (!spec) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Unknown contribution type "${type}". Choose from ${Object.keys(
|
|
151
|
+
CONTRIBUTION_TYPES
|
|
152
|
+
).join(", ")}.`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const ranked = override || (rank !== undefined && rank !== "");
|
|
156
|
+
if (!spec.overridable && ranked) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`${type} contributions are not ranked; --override and --rank do not apply`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
if (spec.required) requireOption(descriptor, `descriptor (${spec.required})`);
|
|
162
|
+
const resolved = spec.overridable
|
|
163
|
+
? resolveOverride(type, {
|
|
164
|
+
override,
|
|
165
|
+
rank,
|
|
166
|
+
explicit: { [spec.overridable]: descriptor },
|
|
167
|
+
})
|
|
168
|
+
: { fields: {}, notes: [] };
|
|
169
|
+
const slot = resolved.fields[spec.overridable] ?? descriptor;
|
|
170
|
+
if (spec.slotRequired && !slot) {
|
|
171
|
+
requireOption(
|
|
172
|
+
slot,
|
|
173
|
+
`descriptor (${spec.overridable}, a kondra.ncui.navigations path such as settings.water)`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
assertNameFree(codegenFs, project, name);
|
|
177
|
+
if (descriptorProject && override) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
"--override fills a slot the descriptor already lists; --descriptorProject does not apply"
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
const derived =
|
|
183
|
+
spec.listedIn && !slot
|
|
184
|
+
? [
|
|
185
|
+
`${spec.overridable} "${
|
|
186
|
+
normalizeAllValues({ name }).nameCamelCase
|
|
187
|
+
}" comes from the name (--descriptor sets it).`,
|
|
188
|
+
]
|
|
189
|
+
: [];
|
|
190
|
+
generate(codegenFs, spec.pluginType, {
|
|
191
|
+
name,
|
|
192
|
+
project,
|
|
193
|
+
...(slot ? { descriptor: slot } : {}),
|
|
194
|
+
...rankField(resolved.rank),
|
|
195
|
+
});
|
|
196
|
+
const listed = spec.descriptorType
|
|
197
|
+
? descriptorNotes(codegenFs, spec, {
|
|
198
|
+
slot: slot || normalizeAllValues({ name }).nameCamelCase,
|
|
199
|
+
override,
|
|
200
|
+
descriptorProject,
|
|
201
|
+
roles,
|
|
202
|
+
column,
|
|
203
|
+
})
|
|
204
|
+
: [];
|
|
205
|
+
return {
|
|
206
|
+
label: spec.label,
|
|
207
|
+
notes: [...resolved.notes, ...derived, ...listed],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Lists a new utility, setup step or navigation slot in the named descriptor project,
|
|
213
|
+
* or says where it needs listing: the NCUI shows only the slots its descriptor lists.
|
|
214
|
+
*/
|
|
215
|
+
function descriptorNotes(
|
|
216
|
+
codegenFs,
|
|
217
|
+
spec,
|
|
218
|
+
{ slot, override, descriptorProject, roles, column }
|
|
219
|
+
) {
|
|
220
|
+
if (override) return [];
|
|
221
|
+
if (descriptorProject) {
|
|
222
|
+
return [
|
|
223
|
+
addDescriptorEntry(codegenFs, spec.descriptorType, {
|
|
224
|
+
project: descriptorProject,
|
|
225
|
+
slot,
|
|
226
|
+
roles,
|
|
227
|
+
column,
|
|
228
|
+
}),
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
const listed = descriptorListsSlot(codegenFs, spec.descriptorType, slot);
|
|
232
|
+
if (listed) return [];
|
|
233
|
+
const projects = findDescriptorProjects(codegenFs).map((p) => p.name);
|
|
234
|
+
return [
|
|
235
|
+
projects.length
|
|
236
|
+
? `No descriptor project lists ${spec.overridable} "${slot}"; add it with --descriptorProject ${projects[0]}.`
|
|
237
|
+
: `The NCUI shows "${slot}" only if its descriptor (${spec.listedIn}) lists it: create a descriptor project with kosui ddk:descriptor-project and pass --descriptorProject, or the system app's descriptor must list it.`,
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* A dashboard summary card and, unless `detail` is false, the detail its card
|
|
243
|
+
* opens; both share `dashboardKey` and `rank`. `override` names a standard
|
|
244
|
+
* summary or detail whose dashboardKey to take over.
|
|
245
|
+
*/
|
|
246
|
+
export function generateDashboardCard(
|
|
247
|
+
codegenFs,
|
|
248
|
+
{ name, project, dashboardKey, detail = true, override, rank }
|
|
249
|
+
) {
|
|
250
|
+
assertNameFree(codegenFs, project, name);
|
|
251
|
+
const resolved = resolveOverride("dashboard-card", {
|
|
252
|
+
override,
|
|
253
|
+
rank,
|
|
254
|
+
explicit: { dashboardKey },
|
|
255
|
+
});
|
|
256
|
+
const key = resolved.fields.dashboardKey ?? dashboardKey;
|
|
257
|
+
requireOption(key, "dashboardKey");
|
|
258
|
+
const options = {
|
|
259
|
+
name,
|
|
260
|
+
project,
|
|
261
|
+
dashboardKey: key,
|
|
262
|
+
...rankField(resolved.rank),
|
|
263
|
+
};
|
|
264
|
+
generate(codegenFs, "ddk.dashboardSummary", options);
|
|
265
|
+
if (detail) {
|
|
266
|
+
generate(codegenFs, "ddk.dashboardDetail", options);
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
label: detail ? "DDK Dashboard Card" : "DDK Dashboard Summary",
|
|
270
|
+
notes: [
|
|
271
|
+
`The dashboard draws one card per active model at assembly.${key} (or the FreestyleAssembly companion's ${key}); no such model, no card.`,
|
|
272
|
+
...(detail
|
|
273
|
+
? ["The detail opens when a technician selects the card."]
|
|
274
|
+
: []),
|
|
275
|
+
...resolved.notes,
|
|
276
|
+
...alsoReplacedNotes("dashboard-card", {
|
|
277
|
+
override,
|
|
278
|
+
rank: resolved.rank,
|
|
279
|
+
slot: { dashboardKey: key },
|
|
280
|
+
written: detail
|
|
281
|
+
? ["dashboardSummary", "dashboardDetail"]
|
|
282
|
+
: ["dashboardSummary"],
|
|
283
|
+
}),
|
|
284
|
+
],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Pump detail for holders whose dashboard key is `dashboardKey`. */
|
|
289
|
+
export function generatePumpDetail(
|
|
290
|
+
codegenFs,
|
|
291
|
+
{ name, project, dashboardKey, override, rank }
|
|
292
|
+
) {
|
|
293
|
+
assertNameFree(codegenFs, project, name);
|
|
294
|
+
const resolved = resolveOverride("pump-detail", {
|
|
295
|
+
override,
|
|
296
|
+
rank,
|
|
297
|
+
explicit: { dashboardKey },
|
|
298
|
+
});
|
|
299
|
+
const key = resolved.fields.dashboardKey ?? dashboardKey;
|
|
300
|
+
requireOption(key, "dashboardKey");
|
|
301
|
+
generate(codegenFs, "ddk.pumpDetail", {
|
|
302
|
+
name,
|
|
303
|
+
project,
|
|
304
|
+
dashboardKey: key,
|
|
305
|
+
...rankField(resolved.rank),
|
|
306
|
+
});
|
|
307
|
+
return {
|
|
308
|
+
label: "DDK Pump Detail",
|
|
309
|
+
notes: [
|
|
310
|
+
`Shown in the holder modal when the dashboard key factory returns "${key}" for the holder (default: its first pump's type), unless the holder has its own content.`,
|
|
311
|
+
...resolved.notes,
|
|
312
|
+
],
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* A pump card for holders whose dashboard key is `dashboardKey`: the summary body on
|
|
318
|
+
* the holder's dashboard card and, unless `detail` is false, the pump detail in its
|
|
319
|
+
* modal; both share `dashboardKey` and `rank`. `override` names a standard pump
|
|
320
|
+
* summary or detail whose dashboardKey to take over.
|
|
321
|
+
*/
|
|
322
|
+
export function generatePumpCard(
|
|
323
|
+
codegenFs,
|
|
324
|
+
{ name, project, dashboardKey, detail = true, override, rank }
|
|
325
|
+
) {
|
|
326
|
+
assertNameFree(codegenFs, project, name);
|
|
327
|
+
const resolved = resolveOverride("pump-card", {
|
|
328
|
+
override,
|
|
329
|
+
rank,
|
|
330
|
+
explicit: { dashboardKey },
|
|
331
|
+
});
|
|
332
|
+
const key = resolved.fields.dashboardKey ?? dashboardKey;
|
|
333
|
+
requireOption(key, "dashboardKey");
|
|
334
|
+
const options = {
|
|
335
|
+
name,
|
|
336
|
+
project,
|
|
337
|
+
dashboardKey: key,
|
|
338
|
+
...rankField(resolved.rank),
|
|
339
|
+
};
|
|
340
|
+
generate(codegenFs, "ddk.pumpSummary", options);
|
|
341
|
+
if (detail) {
|
|
342
|
+
generate(codegenFs, "ddk.pumpDetail", options);
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
label: detail ? "DDK Pump Card" : "DDK Pump Summary",
|
|
346
|
+
notes: [
|
|
347
|
+
`Used for holders whose dashboard key factory returns "${key}" (default: the holder's first pump type, which the backend assembly assigns); other holders keep the default card body.`,
|
|
348
|
+
...(detail
|
|
349
|
+
? [
|
|
350
|
+
"The detail shows in the holder modal a technician opens from the card.",
|
|
351
|
+
]
|
|
352
|
+
: []),
|
|
353
|
+
...resolved.notes,
|
|
354
|
+
...alsoReplacedNotes("pump-card", {
|
|
355
|
+
override,
|
|
356
|
+
rank: resolved.rank,
|
|
357
|
+
slot: { dashboardKey: key },
|
|
358
|
+
written: detail
|
|
359
|
+
? ["dashboardPumpSummary", "dashboardPumpDetail"]
|
|
360
|
+
: ["dashboardPumpSummary"],
|
|
361
|
+
}),
|
|
362
|
+
],
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** The macro holder card body for `dashboardKey`. */
|
|
367
|
+
export function generateMacroSummary(
|
|
368
|
+
codegenFs,
|
|
369
|
+
{ name, project, dashboardKey, override, rank }
|
|
370
|
+
) {
|
|
371
|
+
assertNameFree(codegenFs, project, name);
|
|
372
|
+
const resolved = resolveOverride("macro-summary", {
|
|
373
|
+
override,
|
|
374
|
+
rank,
|
|
375
|
+
explicit: { dashboardKey },
|
|
376
|
+
});
|
|
377
|
+
const key = resolved.fields.dashboardKey ?? dashboardKey;
|
|
378
|
+
requireOption(key, "dashboardKey");
|
|
379
|
+
generate(codegenFs, "ddk.macroSummary", {
|
|
380
|
+
name,
|
|
381
|
+
project,
|
|
382
|
+
dashboardKey: key,
|
|
383
|
+
...rankField(resolved.rank),
|
|
384
|
+
});
|
|
385
|
+
return {
|
|
386
|
+
label: "DDK Macro Summary",
|
|
387
|
+
notes: [
|
|
388
|
+
`Matched to a macro holder by holder.name "${key}" first, then by the dashboard key factory.`,
|
|
389
|
+
...resolved.notes,
|
|
390
|
+
],
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The experience shown while the device has an active `troubleType` trouble.
|
|
396
|
+
* Contributions sharing a stateKey share one experience.
|
|
397
|
+
*/
|
|
398
|
+
export function generateTroubleAction(
|
|
399
|
+
codegenFs,
|
|
400
|
+
{ name, project, troubleType, stateKey, stateValue, override, rank }
|
|
401
|
+
) {
|
|
402
|
+
assertNameFree(codegenFs, project, name);
|
|
403
|
+
const resolved = resolveOverride("trouble-action", {
|
|
404
|
+
override,
|
|
405
|
+
rank,
|
|
406
|
+
explicit: { troubleType, stateKey, stateValue },
|
|
407
|
+
});
|
|
408
|
+
const type = resolved.fields.troubleType ?? troubleType;
|
|
409
|
+
requireOption(type, "troubleType");
|
|
410
|
+
generate(codegenFs, "ddk.troubleAction", {
|
|
411
|
+
name,
|
|
412
|
+
project,
|
|
413
|
+
troubleType: type,
|
|
414
|
+
stateKey: resolved.fields.stateKey ?? (stateKey || type),
|
|
415
|
+
stateValue: resolved.fields.stateValue ?? (stateValue || type),
|
|
416
|
+
...rankField(resolved.rank),
|
|
417
|
+
});
|
|
418
|
+
return {
|
|
419
|
+
label: "DDK Trouble Action",
|
|
420
|
+
notes: [
|
|
421
|
+
`troubleType "${type}" must be the exact type the device raises; the experience shows while one is active and goes away once it is resolved.`,
|
|
422
|
+
...resolved.notes,
|
|
423
|
+
],
|
|
424
|
+
};
|
|
425
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// NCUI descriptor projects: a ddk.ncui.descriptor KAB whose descriptor.json (its
|
|
2
|
+
// .kos.json) carries `kondra.ncui`. The DDK app uses an installed one in place of the
|
|
3
|
+
// system app's descriptor, so a plugin's new utility, setup step or navigation slot
|
|
4
|
+
// is listed there.
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
discoverProjects,
|
|
8
|
+
findProjectByName,
|
|
9
|
+
} from "@kosdev-code/kos-codegen-core";
|
|
10
|
+
import {
|
|
11
|
+
NCUI_LAYOUTS,
|
|
12
|
+
NCUI_OPTIONS,
|
|
13
|
+
buildNcuiDescriptor,
|
|
14
|
+
} from "./ncui-descriptor.mjs";
|
|
15
|
+
|
|
16
|
+
export const DESCRIPTOR_KAB_TYPE = "ddk.ncui.descriptor";
|
|
17
|
+
|
|
18
|
+
/** The workspace's descriptor projects: {name, kosJsonPath} relative to the root. */
|
|
19
|
+
export function findDescriptorProjects(codegenFs) {
|
|
20
|
+
return [...discoverProjects(codegenFs.root).values()]
|
|
21
|
+
.map((project) => ({
|
|
22
|
+
name: project.name,
|
|
23
|
+
kosJsonPath: path.join(project.root, ".kos.json"),
|
|
24
|
+
}))
|
|
25
|
+
.filter(({ kosJsonPath }) => {
|
|
26
|
+
const raw = codegenFs.read(kosJsonPath);
|
|
27
|
+
return raw && JSON.parse(raw).type === DESCRIPTOR_KAB_TYPE;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function descriptorProject(codegenFs, name) {
|
|
32
|
+
const projects = findDescriptorProjects(codegenFs);
|
|
33
|
+
const project = projects.find((p) => p.name === name);
|
|
34
|
+
if (!project) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`No descriptor project "${name}". ${
|
|
37
|
+
projects.length
|
|
38
|
+
? `Descriptor projects: ${projects.map((p) => p.name).join(", ")}.`
|
|
39
|
+
: "Create one with kosui ddk:descriptor-project."
|
|
40
|
+
}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return project;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const parseRoles = (roles) =>
|
|
47
|
+
(Array.isArray(roles) ? roles : String(roles ?? "").split(","))
|
|
48
|
+
.map((role) => role.trim())
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Lists a slot in a descriptor project's `kondra.ncui`, unless it already is.
|
|
53
|
+
* Returns the note for the command's report.
|
|
54
|
+
*
|
|
55
|
+
* @param {"utility" | "setup" | "nav"} type
|
|
56
|
+
* @param {{project: string, slot: string, roles?: string | string[], column?: number | string}} options
|
|
57
|
+
* `column` (1-based, default the last) is for utilities; `roles` default to everyone
|
|
58
|
+
* for a utility and to the parent's roles for a navigation view.
|
|
59
|
+
*/
|
|
60
|
+
export function addDescriptorEntry(
|
|
61
|
+
codegenFs,
|
|
62
|
+
type,
|
|
63
|
+
{ project, slot, roles, column }
|
|
64
|
+
) {
|
|
65
|
+
const { name, kosJsonPath } = descriptorProject(codegenFs, project);
|
|
66
|
+
const kosJson = JSON.parse(codegenFs.read(kosJsonPath));
|
|
67
|
+
const ncui = ((kosJson.kondra ??= {}).ncui ??= {});
|
|
68
|
+
const roleList = parseRoles(roles);
|
|
69
|
+
const withRoles = roleList.length ? { roles: roleList } : {};
|
|
70
|
+
let note;
|
|
71
|
+
|
|
72
|
+
if (type === "utility") {
|
|
73
|
+
const columns = (ncui.utilities ??= [[]]);
|
|
74
|
+
if (columns.flat().some((entry) => entry.name === slot)) {
|
|
75
|
+
return `${name} already lists utility "${slot}".`;
|
|
76
|
+
}
|
|
77
|
+
const index =
|
|
78
|
+
column === undefined || column === ""
|
|
79
|
+
? columns.length - 1
|
|
80
|
+
: Number(column) - 1;
|
|
81
|
+
if (!Number.isInteger(index) || index < 0 || index > columns.length) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`column must be 1 to ${columns.length + 1}; got "${column}"`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
(columns[index] ??= []).push({ name: slot, options: {}, ...withRoles });
|
|
87
|
+
note = `Listed utility "${slot}" in ${name} (column ${index + 1}).`;
|
|
88
|
+
} else if (type === "setup") {
|
|
89
|
+
const steps = ((ncui.setup ??= {}).steps ??= []);
|
|
90
|
+
if (steps.some((step) => step.name === slot)) {
|
|
91
|
+
return `${name} already lists setup step "${slot}".`;
|
|
92
|
+
}
|
|
93
|
+
steps.push({ name: slot });
|
|
94
|
+
note = `Listed setup step "${slot}" last in ${name}; the setup flow runs steps in that order.`;
|
|
95
|
+
} else {
|
|
96
|
+
const parts = slot.split(".");
|
|
97
|
+
let level = (ncui.navigations ??= []);
|
|
98
|
+
let parent;
|
|
99
|
+
for (const part of parts.slice(0, -1)) {
|
|
100
|
+
parent = level.find((item) => item.name === part);
|
|
101
|
+
if (!parent) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`${name} has no navigation "${parts
|
|
104
|
+
.slice(0, parts.indexOf(part) + 1)
|
|
105
|
+
.join(".")}" to add "${slot}" under`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
level = parent.children ??= [];
|
|
109
|
+
}
|
|
110
|
+
const leaf = parts[parts.length - 1];
|
|
111
|
+
if (level.some((item) => item.name === leaf)) {
|
|
112
|
+
return `${name} already lists navigation "${slot}".`;
|
|
113
|
+
}
|
|
114
|
+
const navRoles = roleList.length ? roleList : parent?.roles;
|
|
115
|
+
level.push({ name: leaf, ...(navRoles ? { roles: navRoles } : {}) });
|
|
116
|
+
note = `Listed navigation "${slot}" in ${name}.`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
codegenFs.write(kosJsonPath, JSON.stringify(kosJson, null, 2) + "\n");
|
|
120
|
+
return note;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function ncuiLists(ncui, type, slot) {
|
|
124
|
+
if (type === "utility") {
|
|
125
|
+
return (ncui.utilities ?? []).flat().some((entry) => entry.name === slot);
|
|
126
|
+
}
|
|
127
|
+
if (type === "setup") {
|
|
128
|
+
return (ncui.setup?.steps ?? []).some((step) => step.name === slot);
|
|
129
|
+
}
|
|
130
|
+
let level = ncui.navigations ?? [];
|
|
131
|
+
for (const part of slot.split(".")) {
|
|
132
|
+
const found = level.find((item) => item.name === part);
|
|
133
|
+
if (!found) return false;
|
|
134
|
+
level = found.children ?? [];
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Whether the workspace's descriptor projects list the slot, or with none, whether
|
|
141
|
+
* a generated NCUI descriptor could (the system app's descriptor is one of them).
|
|
142
|
+
*/
|
|
143
|
+
export function descriptorListsSlot(codegenFs, type, slot) {
|
|
144
|
+
const projects = findDescriptorProjects(codegenFs);
|
|
145
|
+
if (!projects.length) {
|
|
146
|
+
return NCUI_LAYOUTS.some((layout) =>
|
|
147
|
+
[false, true].some((on) =>
|
|
148
|
+
ncuiLists(
|
|
149
|
+
buildNcuiDescriptor({
|
|
150
|
+
layout,
|
|
151
|
+
...Object.fromEntries(
|
|
152
|
+
Object.keys(NCUI_OPTIONS).map((option) => [option, on])
|
|
153
|
+
),
|
|
154
|
+
}).ncui,
|
|
155
|
+
type,
|
|
156
|
+
slot
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
return projects.some(({ kosJsonPath }) =>
|
|
162
|
+
ncuiLists(
|
|
163
|
+
JSON.parse(codegenFs.read(kosJsonPath)).kondra?.ncui ?? {},
|
|
164
|
+
type,
|
|
165
|
+
slot
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const SLOT_FIELDS = [
|
|
171
|
+
["utilities", "utility", "utilDescriptor"],
|
|
172
|
+
["setupStep", "setup", "setupDescriptor"],
|
|
173
|
+
["navViews", "nav", "navDescriptor"],
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Lists every utility, setup step and navigation slot a plugin already contributes in
|
|
178
|
+
* a descriptor project, keeping the entries it has; for a plugin that predates it.
|
|
179
|
+
*/
|
|
180
|
+
export function addPluginDescriptorEntries(
|
|
181
|
+
codegenFs,
|
|
182
|
+
{ project, descriptorProject }
|
|
183
|
+
) {
|
|
184
|
+
const root = findProjectByName(codegenFs.root, project)?.root;
|
|
185
|
+
const raw = root && codegenFs.read(path.join(root, ".kos.json"));
|
|
186
|
+
if (!raw) throw new Error(`No plugin project "${project}" with a .kos.json`);
|
|
187
|
+
const contributes = JSON.parse(raw).kos?.ui?.plugin?.contributes ?? {};
|
|
188
|
+
const notes = [];
|
|
189
|
+
for (const [key, type, field] of SLOT_FIELDS) {
|
|
190
|
+
for (const entry of contributes[key] ?? []) {
|
|
191
|
+
if (!entry[field]) continue;
|
|
192
|
+
try {
|
|
193
|
+
notes.push(
|
|
194
|
+
addDescriptorEntry(codegenFs, type, {
|
|
195
|
+
project: descriptorProject,
|
|
196
|
+
slot: entry[field],
|
|
197
|
+
})
|
|
198
|
+
);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
notes.push(`${entry.id}: ${error.message}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
label: "DDK descriptor entries",
|
|
206
|
+
notes: notes.length
|
|
207
|
+
? notes
|
|
208
|
+
: [`${project} contributes no utility, setup step or navigation slot.`],
|
|
209
|
+
};
|
|
210
|
+
}
|