@kosdev-code/kos-ddk-cli 0.0.0-stage → 0.1.0-dev.50
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 +129 -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 +888 -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 +19288 -0
- package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48632 -0
- package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +71 -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__ +30 -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__ +32 -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__ +32 -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__ +32 -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__ +30 -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 +80 -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__ +32 -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__ +32 -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/setting/__nameDashCase__.stories.tsx__template__ +30 -0
- package/agent-plugin/kos-ddk-tools/templates/setting/__nameDashCase__.tsx__template__ +27 -0
- package/agent-plugin/kos-ddk-tools/templates/setting/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +30 -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__ +29 -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__ +30 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +47 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
- package/catalog/contributions.json +888 -0
- package/guides/ddk-dev.md +46 -0
- package/guides/storybook.md +69 -0
- package/package.json +33 -3
- package/reference/reference.json +19288 -0
- package/src/build-paths.mjs +20 -0
- package/src/codegen/contribution.mjs +255 -0
- package/src/codegen/overrides.mjs +179 -0
- package/src/codegen/project.mjs +144 -0
- package/src/extension.mjs +22 -0
- package/src/generators/agent-install.mjs +79 -0
- package/src/generators/catalog.mjs +70 -0
- package/src/generators/contributions.mjs +116 -0
- package/src/generators/dashboard.mjs +238 -0
- package/src/generators/dev.mjs +221 -0
- package/src/generators/override-prompts.mjs +27 -0
- package/src/generators/plugin-project.mjs +34 -0
- package/src/generators/theme-project.mjs +34 -0
- package/src/handlers.mjs +325 -0
- package/src/mcp/pkg-info.mjs +7 -0
- package/src/mcp/plugin-inspect.mjs +257 -0
- package/src/mcp/reference.mjs +248 -0
- package/src/mcp/server.mjs +12 -0
- package/src/mcp/tools.mjs +478 -0
- package/templates/cui/__nameDashCase__.stories.tsx__template__ +30 -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__ +32 -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__ +32 -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__ +32 -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__ +30 -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 +80 -0
- package/templates/plugin-project/.storybook/registration.ts.template +6 -0
- package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +32 -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__ +32 -0
- package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
- package/templates/pump-summary/index.ts__template__ +1 -0
- package/templates/setting/__nameDashCase__.stories.tsx__template__ +30 -0
- package/templates/setting/__nameDashCase__.tsx__template__ +27 -0
- package/templates/setting/index.ts__template__ +1 -0
- package/templates/setup/__nameDashCase__.stories.tsx__template__ +30 -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__ +29 -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__ +30 -0
- package/templates/utility/__nameDashCase__.tsx__template__ +47 -0
- package/templates/utility/index.ts__template__ +1 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// ddk:theme-project: a DDK theme project. kos-nx-plugin's generic theme project with the
|
|
2
|
+
// DDK KAB type and the theme-overlay.css the DDK apps load over their base tokens.
|
|
3
|
+
import { createDdkProject } from "../codegen/project.mjs";
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
key: "ddk:theme-project",
|
|
7
|
+
name: "DDK Theme Project",
|
|
8
|
+
invalidateCache: true,
|
|
9
|
+
namedArguments: { name: "name", interactive: "interactive" },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export async function register(plop, { host }) {
|
|
13
|
+
plop.setActionType("ddk:createThemeProject", (answers) => {
|
|
14
|
+
createDdkProject("theme", {
|
|
15
|
+
workspaceRoot: process.cwd(),
|
|
16
|
+
name: answers.name,
|
|
17
|
+
stdio: "inherit",
|
|
18
|
+
});
|
|
19
|
+
return `DDK theme project ${answers.name} created.`;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
plop.setGenerator("ddk:theme-project", {
|
|
23
|
+
description: "Create a new DDK theme project",
|
|
24
|
+
prompts: [
|
|
25
|
+
{
|
|
26
|
+
type: "input",
|
|
27
|
+
name: "name",
|
|
28
|
+
message: "What is the name of the theme project?",
|
|
29
|
+
validate: host.required,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
actions: host.actionFactory("ddk:createThemeProject", metadata),
|
|
33
|
+
});
|
|
34
|
+
}
|
package/src/handlers.mjs
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// DDK extension-point handlers for codegen-core's generateComponent. Register them
|
|
2
|
+
// in the same module graph that calls generateComponent: the registry is per copy.
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import {
|
|
6
|
+
BasePluginHandler,
|
|
7
|
+
PluginHandlerFactory,
|
|
8
|
+
} from "@kosdev-code/kos-codegen-core";
|
|
9
|
+
|
|
10
|
+
export const TEMPLATES_DIR = path.resolve(
|
|
11
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
12
|
+
"../templates"
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
class DdkHandler extends BasePluginHandler {
|
|
16
|
+
requiresI18n = true;
|
|
17
|
+
/** Whether the extension point keeps a contribution's rank. */
|
|
18
|
+
rankable = false;
|
|
19
|
+
|
|
20
|
+
getTargetDirectory() {
|
|
21
|
+
return this.contributionKey;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
contribute(options, { suffix, experienceSuffix, key, fields }) {
|
|
25
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
26
|
+
const experienceId = `${configPrefix}.${experienceSuffix}.experience`;
|
|
27
|
+
return {
|
|
28
|
+
contributions: {
|
|
29
|
+
[key]: [
|
|
30
|
+
{
|
|
31
|
+
id: suffix ? `${configPrefix}.${suffix}` : configPrefix,
|
|
32
|
+
title: `${configPrefix}.${fields.titleSuffix}.title`,
|
|
33
|
+
namespace: options.appProject,
|
|
34
|
+
...fields.extra,
|
|
35
|
+
...(this.rankable && Number.isInteger(options.rank)
|
|
36
|
+
? { rank: options.rank }
|
|
37
|
+
: {}),
|
|
38
|
+
experienceId,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
experiences: {
|
|
43
|
+
[experienceId]: this.createExperience(options, experienceId),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class DdkCuiHandler extends DdkHandler {
|
|
50
|
+
pluginType = "ddk.cui";
|
|
51
|
+
contributionKey = "cui";
|
|
52
|
+
|
|
53
|
+
createConfiguration(options) {
|
|
54
|
+
return this.contribute(options, {
|
|
55
|
+
suffix: "",
|
|
56
|
+
experienceSuffix: "cui",
|
|
57
|
+
key: "cui",
|
|
58
|
+
fields: { titleSuffix: "cui" },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class DdkSetupHandler extends DdkHandler {
|
|
64
|
+
pluginType = "ddk.setup";
|
|
65
|
+
contributionKey = "setup";
|
|
66
|
+
rankable = true;
|
|
67
|
+
|
|
68
|
+
createConfiguration(options) {
|
|
69
|
+
return this.contribute(options, {
|
|
70
|
+
suffix: "setup",
|
|
71
|
+
experienceSuffix: "setup",
|
|
72
|
+
key: "setupStep",
|
|
73
|
+
fields: {
|
|
74
|
+
titleSuffix: "setup",
|
|
75
|
+
extra: {
|
|
76
|
+
setupDescriptor: options.descriptor || options.nameCamelCase,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class DdkUtilityHandler extends DdkHandler {
|
|
84
|
+
pluginType = "ddk.utility";
|
|
85
|
+
contributionKey = "utility";
|
|
86
|
+
rankable = true;
|
|
87
|
+
|
|
88
|
+
createConfiguration(options) {
|
|
89
|
+
return this.contribute(options, {
|
|
90
|
+
suffix: "util",
|
|
91
|
+
experienceSuffix: "util",
|
|
92
|
+
key: "utilities",
|
|
93
|
+
fields: {
|
|
94
|
+
titleSuffix: "utility",
|
|
95
|
+
extra: {
|
|
96
|
+
utilDescriptor: options.descriptor || options.nameCamelCase,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class DdkSettingHandler extends DdkHandler {
|
|
104
|
+
pluginType = "ddk.setting";
|
|
105
|
+
contributionKey = "setting";
|
|
106
|
+
|
|
107
|
+
createConfiguration(options) {
|
|
108
|
+
return this.contribute(options, {
|
|
109
|
+
suffix: "setting",
|
|
110
|
+
experienceSuffix: "settings",
|
|
111
|
+
key: "settings",
|
|
112
|
+
fields: {
|
|
113
|
+
titleSuffix: "setting",
|
|
114
|
+
extra: { settingsGroup: options.group || "general" },
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class DdkNavHandler extends DdkHandler {
|
|
121
|
+
pluginType = "ddk.nav";
|
|
122
|
+
contributionKey = "nav";
|
|
123
|
+
rankable = true;
|
|
124
|
+
|
|
125
|
+
createConfiguration(options) {
|
|
126
|
+
return this.contribute(options, {
|
|
127
|
+
suffix: "nav",
|
|
128
|
+
experienceSuffix: "nav",
|
|
129
|
+
key: "navViews",
|
|
130
|
+
fields: {
|
|
131
|
+
titleSuffix: "nav",
|
|
132
|
+
extra: {
|
|
133
|
+
navDescriptor: options.descriptor || options.nameLowerCase,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Contributions that carry their extension point's `type` literal. Ids, title key
|
|
141
|
+
// and i18n entry all hang off `${project}.${name}.${contributionKey}`.
|
|
142
|
+
class TypedDdkHandler extends DdkHandler {
|
|
143
|
+
rankable = true;
|
|
144
|
+
|
|
145
|
+
/** Exposed component name, which must be unique within the plugin. */
|
|
146
|
+
componentName(options) {
|
|
147
|
+
return options.namePascalCase;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
contributionFields() {
|
|
151
|
+
return {};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
createConfiguration(options) {
|
|
155
|
+
const config = this.contribute(options, {
|
|
156
|
+
suffix: this.contributionKey,
|
|
157
|
+
experienceSuffix: this.contributionKey,
|
|
158
|
+
key: this.kosJsonKey,
|
|
159
|
+
fields: {
|
|
160
|
+
titleSuffix: this.contributionKey,
|
|
161
|
+
extra: {
|
|
162
|
+
type: this.extensionType,
|
|
163
|
+
...this.contributionFields(options),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
for (const experience of Object.values(config.experiences)) {
|
|
168
|
+
experience.component = this.componentName(options);
|
|
169
|
+
}
|
|
170
|
+
return config;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
class DashboardCardHandler extends TypedDdkHandler {
|
|
175
|
+
getTargetDirectory() {
|
|
176
|
+
return "dashboard";
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
getComponentPath(options) {
|
|
180
|
+
return `${options.appDirectory}/dashboard/${options.nameDashCase}/${this.part}/${options.nameDashCase}.tsx`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
componentName(options) {
|
|
184
|
+
return `${options.namePascalCase}${
|
|
185
|
+
this.part === "summary" ? "Summary" : "Detail"
|
|
186
|
+
}`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
contributionFields(options) {
|
|
190
|
+
return { dashboardKey: options.dashboardKey };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export class DdkDashboardSummaryHandler extends DashboardCardHandler {
|
|
195
|
+
pluginType = "ddk.dashboardSummary";
|
|
196
|
+
contributionKey = "dashboardSummary";
|
|
197
|
+
kosJsonKey = "dashboardSummary";
|
|
198
|
+
extensionType = "dashboard.summary";
|
|
199
|
+
part = "summary";
|
|
200
|
+
|
|
201
|
+
getTemplatePath() {
|
|
202
|
+
return "dashboard-summary";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export class DdkDashboardDetailHandler extends DashboardCardHandler {
|
|
207
|
+
pluginType = "ddk.dashboardDetail";
|
|
208
|
+
contributionKey = "dashboardDetail";
|
|
209
|
+
kosJsonKey = "dashboardDetail";
|
|
210
|
+
extensionType = "dashboard.detail";
|
|
211
|
+
part = "detail";
|
|
212
|
+
|
|
213
|
+
getTemplatePath() {
|
|
214
|
+
return "dashboard-detail";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export class DdkPumpDetailHandler extends TypedDdkHandler {
|
|
219
|
+
pluginType = "ddk.pumpDetail";
|
|
220
|
+
contributionKey = "dashboardPumpDetail";
|
|
221
|
+
kosJsonKey = "dashboardPumpDetail";
|
|
222
|
+
extensionType = "dashboard.detail.pump";
|
|
223
|
+
|
|
224
|
+
getTargetDirectory() {
|
|
225
|
+
return "dashboard/pumpDetail";
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
getTemplatePath() {
|
|
229
|
+
return "pump-detail";
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
contributionFields(options) {
|
|
233
|
+
return { dashboardKey: options.dashboardKey };
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export class DdkPumpSummaryHandler extends TypedDdkHandler {
|
|
238
|
+
pluginType = "ddk.pumpSummary";
|
|
239
|
+
contributionKey = "dashboardPumpSummary";
|
|
240
|
+
kosJsonKey = "dashboardPumpSummary";
|
|
241
|
+
extensionType = "dashboard.summary.pump";
|
|
242
|
+
|
|
243
|
+
getTargetDirectory() {
|
|
244
|
+
return "dashboard/pumpSummary";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
getTemplatePath() {
|
|
248
|
+
return "pump-summary";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Distinct from the pump detail of the same name, which is exposed as its PascalCase name.
|
|
252
|
+
componentName(options) {
|
|
253
|
+
return `${options.namePascalCase}Summary`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
contributionFields(options) {
|
|
257
|
+
return { dashboardKey: options.dashboardKey };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class DdkMacroSummaryHandler extends TypedDdkHandler {
|
|
262
|
+
pluginType = "ddk.macroSummary";
|
|
263
|
+
contributionKey = "dashboardMacroSummary";
|
|
264
|
+
kosJsonKey = "dashboardMacroSummary";
|
|
265
|
+
extensionType = "dashboard.macro.summary";
|
|
266
|
+
|
|
267
|
+
getTargetDirectory() {
|
|
268
|
+
return "dashboard/macroSummary";
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
getTemplatePath() {
|
|
272
|
+
return "macro-summary";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
contributionFields(options) {
|
|
276
|
+
return { dashboardKey: options.dashboardKey };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export class DdkTroubleActionHandler extends TypedDdkHandler {
|
|
281
|
+
pluginType = "ddk.troubleAction";
|
|
282
|
+
contributionKey = "troubleAction";
|
|
283
|
+
kosJsonKey = "troubleActions";
|
|
284
|
+
extensionType = "trouble.action";
|
|
285
|
+
|
|
286
|
+
getTargetDirectory() {
|
|
287
|
+
return "trouble-action";
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
getTemplatePath() {
|
|
291
|
+
return "trouble-action";
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
contributionFields(options) {
|
|
295
|
+
return {
|
|
296
|
+
troubleType: options.troubleType,
|
|
297
|
+
stateKey: options.stateKey || options.troubleType,
|
|
298
|
+
stateValue: options.stateValue || options.troubleType,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export const DDK_HANDLERS = [
|
|
304
|
+
DdkCuiHandler,
|
|
305
|
+
DdkSetupHandler,
|
|
306
|
+
DdkUtilityHandler,
|
|
307
|
+
DdkSettingHandler,
|
|
308
|
+
DdkNavHandler,
|
|
309
|
+
DdkDashboardSummaryHandler,
|
|
310
|
+
DdkDashboardDetailHandler,
|
|
311
|
+
DdkPumpDetailHandler,
|
|
312
|
+
DdkPumpSummaryHandler,
|
|
313
|
+
DdkMacroSummaryHandler,
|
|
314
|
+
DdkTroubleActionHandler,
|
|
315
|
+
];
|
|
316
|
+
|
|
317
|
+
/** Register every DDK handler once with this copy of codegen-core. */
|
|
318
|
+
export function registerDdkHandlers() {
|
|
319
|
+
for (const Handler of DDK_HANDLERS) {
|
|
320
|
+
const type = new Handler().pluginType;
|
|
321
|
+
if (!PluginHandlerFactory.isValidPluginType(type)) {
|
|
322
|
+
PluginHandlerFactory.register(type, Handler);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The name and version the kos-ddk server reports; the agent-plugin bundle swaps this
|
|
2
|
+
// module for one reading its plugin.json.
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
export const pkg = JSON.parse(
|
|
6
|
+
readFileSync(new URL("../../package.json", import.meta.url), "utf-8")
|
|
7
|
+
);
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// A DDK plugin project's contributions, read from its .kos.json, and their checks
|
|
2
|
+
// against the extension points' schemas, the standard contributions they override
|
|
3
|
+
// and the rule that plugins compose DDK components without setting tokens.
|
|
4
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
MAX_RANK,
|
|
8
|
+
OVERRIDABLE_POINTS,
|
|
9
|
+
listOverridableContributions,
|
|
10
|
+
loadCatalog,
|
|
11
|
+
uniqueContributions,
|
|
12
|
+
} from "../codegen/overrides.mjs";
|
|
13
|
+
import { findDdkPlugins } from "../generators/dev.mjs";
|
|
14
|
+
import { loadReference } from "./reference.mjs";
|
|
15
|
+
|
|
16
|
+
const readJson = (file) => JSON.parse(readFileSync(file, "utf-8"));
|
|
17
|
+
|
|
18
|
+
const SLOT_KEYS = Object.fromEntries(
|
|
19
|
+
Object.values(OVERRIDABLE_POINTS).flatMap(({ contributionKeys, keys }) =>
|
|
20
|
+
contributionKeys.map((key) => [key, keys])
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/** The plugin project, its directory and its kos.ui.plugin block. */
|
|
25
|
+
function loadPlugin(root, project) {
|
|
26
|
+
const plugins = findDdkPlugins(root);
|
|
27
|
+
const plugin = plugins.find(
|
|
28
|
+
(p) => p.project === project || p.alias === project
|
|
29
|
+
);
|
|
30
|
+
if (!plugin) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`No DDK plugin project "${project}". DDK plugin projects: ${
|
|
33
|
+
plugins.map((p) => p.project).join(", ") || "none"
|
|
34
|
+
}.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const dir = path.join(root, plugin.dir);
|
|
38
|
+
const kos = readJson(path.join(dir, ".kos.json"));
|
|
39
|
+
return { ...plugin, absDir: dir, block: kos.kos?.ui?.plugin ?? {} };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const slotOf = (key, entry) =>
|
|
43
|
+
Object.fromEntries(
|
|
44
|
+
(SLOT_KEYS[key] ?? [])
|
|
45
|
+
.filter((field) => entry[field] !== undefined)
|
|
46
|
+
.map((field) => [field, entry[field]])
|
|
47
|
+
);
|
|
48
|
+
const sameSlot = (a, b) => {
|
|
49
|
+
const keys = Object.keys(a);
|
|
50
|
+
return (
|
|
51
|
+
keys.length > 0 &&
|
|
52
|
+
keys.length === Object.keys(b).length &&
|
|
53
|
+
keys.every((k) => a[k] === b[k])
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
// Lower rank wins; an unranked contribution loses to any ranked one.
|
|
57
|
+
const beats = (rank, other) =>
|
|
58
|
+
typeof rank === "number" && (typeof other !== "number" || rank < other);
|
|
59
|
+
|
|
60
|
+
/** Each contribution with its point, slot, experience and the standard ones it shares a slot with. */
|
|
61
|
+
export function describePlugin(root, project) {
|
|
62
|
+
const plugin = loadPlugin(root, project);
|
|
63
|
+
const { extensionPoints } = loadReference();
|
|
64
|
+
const standard = uniqueContributions(listOverridableContributions());
|
|
65
|
+
const contributes = plugin.block.contributes ?? {};
|
|
66
|
+
const experiences = contributes.experiences ?? {};
|
|
67
|
+
const contributions = [];
|
|
68
|
+
for (const [key, entries] of Object.entries(contributes)) {
|
|
69
|
+
if (!Array.isArray(entries)) continue;
|
|
70
|
+
const point = extensionPoints.find((p) => p.contributionKey === key);
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
const slot = slotOf(key, entry);
|
|
73
|
+
const shared = standard.filter(
|
|
74
|
+
(s) =>
|
|
75
|
+
s.plugin !== plugin.project &&
|
|
76
|
+
s.contributionKey === key &&
|
|
77
|
+
sameSlot(slot, s.keys)
|
|
78
|
+
);
|
|
79
|
+
const experience = experiences[entry.experienceId];
|
|
80
|
+
contributions.push({
|
|
81
|
+
contributionKey: key,
|
|
82
|
+
...(point ? { extensionPoint: point.id } : {}),
|
|
83
|
+
id: entry.id,
|
|
84
|
+
...(Object.keys(slot).length ? { slot } : {}),
|
|
85
|
+
...(typeof entry.rank === "number" ? { rank: entry.rank } : {}),
|
|
86
|
+
...(experience
|
|
87
|
+
? { component: experience.component, location: experience.location }
|
|
88
|
+
: {}),
|
|
89
|
+
...(shared.length
|
|
90
|
+
? {
|
|
91
|
+
sharesSlotWith: shared.map((s) => ({
|
|
92
|
+
id: s.id,
|
|
93
|
+
...(typeof s.rank === "number" ? { rank: s.rank } : {}),
|
|
94
|
+
wins: beats(entry.rank, s.rank),
|
|
95
|
+
})),
|
|
96
|
+
}
|
|
97
|
+
: {}),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
project: plugin.project,
|
|
103
|
+
dir: plugin.dir,
|
|
104
|
+
pluginId: plugin.block.id,
|
|
105
|
+
contributions,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function sourceFiles(dir) {
|
|
110
|
+
if (!existsSync(dir)) return [];
|
|
111
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
112
|
+
const full = path.join(dir, entry.name);
|
|
113
|
+
if (entry.isDirectory())
|
|
114
|
+
return entry.name === "node_modules" ? [] : sourceFiles(full);
|
|
115
|
+
return /\.(tsx?|css)$/.test(entry.name) ? [full] : [];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// The experience loads the module's default export, or the export named by component.
|
|
120
|
+
const exportsComponent = (text, name) =>
|
|
121
|
+
/export\s+default\b/.test(text) ||
|
|
122
|
+
new RegExp(`export\\s+(const|let|function|class)\\s+${name}\\b`).test(text) ||
|
|
123
|
+
new RegExp(`export\\s*\\{[^}]*\\b${name}\\b[^}]*\\}`).test(text);
|
|
124
|
+
|
|
125
|
+
function checkField(field, value) {
|
|
126
|
+
if (value === undefined || value === "") {
|
|
127
|
+
return field.required ? `missing required ${field.name}` : null;
|
|
128
|
+
}
|
|
129
|
+
if (field.type.startsWith('"')) {
|
|
130
|
+
const allowed = field.type.split(" | ").map((t) => JSON.parse(t));
|
|
131
|
+
return allowed.includes(value)
|
|
132
|
+
? null
|
|
133
|
+
: `${field.name} must be ${field.type}`;
|
|
134
|
+
}
|
|
135
|
+
if (
|
|
136
|
+
["string", "number", "boolean"].includes(field.type) &&
|
|
137
|
+
typeof value !== field.type
|
|
138
|
+
) {
|
|
139
|
+
return `${field.name} must be a ${field.type}`;
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Errors and warnings for a plugin project; ok when there are no errors. */
|
|
145
|
+
export function validatePlugin(root, project) {
|
|
146
|
+
const plugin = loadPlugin(root, project);
|
|
147
|
+
const { extensionPoints } = loadReference();
|
|
148
|
+
const described = describePlugin(root, project);
|
|
149
|
+
const contributes = plugin.block.contributes ?? {};
|
|
150
|
+
const experiences = contributes.experiences ?? {};
|
|
151
|
+
const errors = [];
|
|
152
|
+
const warnings = [];
|
|
153
|
+
const ids = new Map();
|
|
154
|
+
|
|
155
|
+
for (const [key, entries] of Object.entries(contributes)) {
|
|
156
|
+
if (!Array.isArray(entries)) continue;
|
|
157
|
+
const point = extensionPoints.find((p) => p.contributionKey === key);
|
|
158
|
+
for (const entry of entries) {
|
|
159
|
+
const where = `contributes.${key} ${entry.id ?? "(no id)"}`;
|
|
160
|
+
if (!entry.id) errors.push(`${where}: missing id`);
|
|
161
|
+
else if (ids.has(entry.id))
|
|
162
|
+
errors.push(
|
|
163
|
+
`${where}: id also used in contributes.${ids.get(entry.id)}`
|
|
164
|
+
);
|
|
165
|
+
else ids.set(entry.id, key);
|
|
166
|
+
|
|
167
|
+
for (const field of point?.fields ?? []) {
|
|
168
|
+
if (field.name === "rank") continue;
|
|
169
|
+
const problem = checkField(field, entry[field.name]);
|
|
170
|
+
if (problem) errors.push(`${where}: ${problem} (${point.id})`);
|
|
171
|
+
}
|
|
172
|
+
if (entry.rank !== undefined) {
|
|
173
|
+
if (
|
|
174
|
+
!Number.isInteger(entry.rank) ||
|
|
175
|
+
entry.rank < 0 ||
|
|
176
|
+
entry.rank > MAX_RANK
|
|
177
|
+
) {
|
|
178
|
+
errors.push(
|
|
179
|
+
`${where}: rank must be an integer from 0 to ${MAX_RANK}`
|
|
180
|
+
);
|
|
181
|
+
} else if (point && !point.isRankable) {
|
|
182
|
+
warnings.push(
|
|
183
|
+
`${where}: ${point.id} is not ranked, so rank has no effect`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (entry.experienceId !== undefined || point?.hasView) {
|
|
189
|
+
const experience = experiences[entry.experienceId];
|
|
190
|
+
if (!experience) {
|
|
191
|
+
errors.push(
|
|
192
|
+
`${where}: experience ${
|
|
193
|
+
entry.experienceId ?? "(none)"
|
|
194
|
+
} is not in contributes.experiences`
|
|
195
|
+
);
|
|
196
|
+
} else {
|
|
197
|
+
const file = path.join(plugin.absDir, experience.location ?? "");
|
|
198
|
+
if (!experience.location || !existsSync(file)) {
|
|
199
|
+
errors.push(
|
|
200
|
+
`${where}: component file ${experience.location} does not exist`
|
|
201
|
+
);
|
|
202
|
+
} else if (
|
|
203
|
+
experience.component &&
|
|
204
|
+
!exportsComponent(readFileSync(file, "utf-8"), experience.component)
|
|
205
|
+
) {
|
|
206
|
+
errors.push(
|
|
207
|
+
`${where}: ${experience.location} has no default export and does not export ${experience.component}`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const bySlot = new Map();
|
|
216
|
+
for (const c of described.contributions.filter((c) => c.slot)) {
|
|
217
|
+
const slotKey = `${c.contributionKey} ${JSON.stringify(c.slot)}`;
|
|
218
|
+
const other = bySlot.get(slotKey);
|
|
219
|
+
if (other && other.rank === c.rank) {
|
|
220
|
+
warnings.push(
|
|
221
|
+
`contributes.${c.contributionKey} ${c.id}: same slot and rank as ${other.id}; which renders is not defined`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
bySlot.set(slotKey, c);
|
|
225
|
+
// The standard plugins are alternatives, so sharing slots with each other is expected.
|
|
226
|
+
if (loadCatalog().sources.includes(plugin.project)) continue;
|
|
227
|
+
for (const s of c.sharesSlotWith ?? []) {
|
|
228
|
+
if (!s.wins) {
|
|
229
|
+
warnings.push(
|
|
230
|
+
`contributes.${c.contributionKey} ${c.id}: shares a slot with ${
|
|
231
|
+
s.id
|
|
232
|
+
} (${
|
|
233
|
+
typeof s.rank === "number" ? `rank ${s.rank}` : "unranked"
|
|
234
|
+
}) without a winning rank, so it does not replace it`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const srcDir = path.join(plugin.absDir, "src");
|
|
241
|
+
for (const file of sourceFiles(srcDir)) {
|
|
242
|
+
const text = readFileSync(file, "utf-8");
|
|
243
|
+
const rel = path.relative(plugin.absDir, file).split(path.sep).join("/");
|
|
244
|
+
const set = [
|
|
245
|
+
...new Set([...text.matchAll(/(--ddk-[\w-]+)\s*:/g)].map((m) => m[1])),
|
|
246
|
+
];
|
|
247
|
+
if (set.length) {
|
|
248
|
+
errors.push(
|
|
249
|
+
`${rel}: sets DDK tokens (${set.join(
|
|
250
|
+
", "
|
|
251
|
+
)}); plugins compose DDK components and do not set tokens`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return { project: plugin.project, ok: errors.length === 0, errors, warnings };
|
|
257
|
+
}
|