@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.
Files changed (116) hide show
  1. package/README.md +129 -2
  2. package/agent-plugin/.claude-plugin/marketplace.json +13 -0
  3. package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +8 -0
  4. package/agent-plugin/kos-ddk-tools/.mcp.json +11 -0
  5. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-planner.md +40 -0
  6. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +33 -0
  7. package/agent-plugin/kos-ddk-tools/catalog/contributions.json +888 -0
  8. package/agent-plugin/kos-ddk-tools/mcp.json +12 -0
  9. package/agent-plugin/kos-ddk-tools/plugin.json +7 -0
  10. package/agent-plugin/kos-ddk-tools/reference/reference.json +19288 -0
  11. package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48632 -0
  12. package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +71 -0
  13. package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +49 -0
  14. package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +39 -0
  15. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +30 -0
  16. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  17. package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
  18. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +32 -0
  19. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  20. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  21. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +32 -0
  22. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  23. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  24. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  25. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  26. package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
  27. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +30 -0
  28. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  29. package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
  30. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +80 -0
  31. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
  32. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +32 -0
  33. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  34. package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
  35. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  36. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  37. package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
  38. package/agent-plugin/kos-ddk-tools/templates/setting/__nameDashCase__.stories.tsx__template__ +30 -0
  39. package/agent-plugin/kos-ddk-tools/templates/setting/__nameDashCase__.tsx__template__ +27 -0
  40. package/agent-plugin/kos-ddk-tools/templates/setting/index.ts__template__ +1 -0
  41. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +30 -0
  42. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  43. package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
  44. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
  45. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
  46. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
  47. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  48. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +29 -0
  49. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  50. package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
  51. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +30 -0
  52. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +47 -0
  53. package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
  54. package/catalog/contributions.json +888 -0
  55. package/guides/ddk-dev.md +46 -0
  56. package/guides/storybook.md +69 -0
  57. package/package.json +33 -3
  58. package/reference/reference.json +19288 -0
  59. package/src/build-paths.mjs +20 -0
  60. package/src/codegen/contribution.mjs +255 -0
  61. package/src/codegen/overrides.mjs +179 -0
  62. package/src/codegen/project.mjs +144 -0
  63. package/src/extension.mjs +22 -0
  64. package/src/generators/agent-install.mjs +79 -0
  65. package/src/generators/catalog.mjs +70 -0
  66. package/src/generators/contributions.mjs +116 -0
  67. package/src/generators/dashboard.mjs +238 -0
  68. package/src/generators/dev.mjs +221 -0
  69. package/src/generators/override-prompts.mjs +27 -0
  70. package/src/generators/plugin-project.mjs +34 -0
  71. package/src/generators/theme-project.mjs +34 -0
  72. package/src/handlers.mjs +325 -0
  73. package/src/mcp/pkg-info.mjs +7 -0
  74. package/src/mcp/plugin-inspect.mjs +257 -0
  75. package/src/mcp/reference.mjs +248 -0
  76. package/src/mcp/server.mjs +12 -0
  77. package/src/mcp/tools.mjs +478 -0
  78. package/templates/cui/__nameDashCase__.stories.tsx__template__ +30 -0
  79. package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  80. package/templates/cui/index.ts__template__ +1 -0
  81. package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +32 -0
  82. package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  83. package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  84. package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +32 -0
  85. package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  86. package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  87. package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  88. package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  89. package/templates/macro-summary/index.ts__template__ +1 -0
  90. package/templates/nav/__nameDashCase__.stories.tsx__template__ +30 -0
  91. package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  92. package/templates/nav/index.ts__template__ +1 -0
  93. package/templates/plugin-project/.storybook/preview.tsx.template +80 -0
  94. package/templates/plugin-project/.storybook/registration.ts.template +6 -0
  95. package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +32 -0
  96. package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  97. package/templates/pump-detail/index.ts__template__ +1 -0
  98. package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +32 -0
  99. package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  100. package/templates/pump-summary/index.ts__template__ +1 -0
  101. package/templates/setting/__nameDashCase__.stories.tsx__template__ +30 -0
  102. package/templates/setting/__nameDashCase__.tsx__template__ +27 -0
  103. package/templates/setting/index.ts__template__ +1 -0
  104. package/templates/setup/__nameDashCase__.stories.tsx__template__ +30 -0
  105. package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  106. package/templates/setup/index.ts__template__ +1 -0
  107. package/templates/theme-project/theme/assets/component.css.template +2 -0
  108. package/templates/theme-project/theme/assets/generic.css.template +2 -0
  109. package/templates/theme-project/theme/assets/semantic.css.template +2 -0
  110. package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  111. package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +29 -0
  112. package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  113. package/templates/trouble-action/index.ts__template__ +1 -0
  114. package/templates/utility/__nameDashCase__.stories.tsx__template__ +30 -0
  115. package/templates/utility/__nameDashCase__.tsx__template__ +47 -0
  116. package/templates/utility/index.ts__template__ +1 -0
@@ -0,0 +1,70 @@
1
+ // ddk:contributions: the standard contributions a ddk:<point> --override can replace.
2
+ import {
3
+ OVERRIDABLE_POINTS,
4
+ listOverridableContributions,
5
+ } from "../codegen/overrides.mjs";
6
+
7
+ export const metadata = [
8
+ {
9
+ key: "ddk:contributions",
10
+ name: "DDK Overridable Contributions",
11
+ invalidateCache: false,
12
+ namedArguments: { point: "point", interactive: "interactive" },
13
+ },
14
+ ];
15
+
16
+ const describeRank = (rank) =>
17
+ typeof rank === "number" ? `rank ${rank}` : "unranked";
18
+
19
+ /** One line per contribution, grouped by command, with how to override it. */
20
+ export function formatOverridableContributions(point) {
21
+ const entries = listOverridableContributions(point || undefined);
22
+ if (entries.length === 0) return "No overridable contributions.";
23
+ const lines = [];
24
+ for (const name of Object.keys(OVERRIDABLE_POINTS)) {
25
+ const group = entries.filter((entry) => entry.point === name);
26
+ if (group.length === 0) continue;
27
+ lines.push(`ddk:${name}`);
28
+ for (const entry of group) {
29
+ const slot = Object.entries(entry.keys)
30
+ .map(([key, value]) => `${key}=${value}`)
31
+ .join(" ");
32
+ lines.push(
33
+ ` ${entry.id} ${slot} ${describeRank(entry.rank)} (${entry.plugin})`
34
+ );
35
+ }
36
+ }
37
+ lines.push(
38
+ "",
39
+ "Override one with: kosui ddk:<point> --name <name> --project <plugin> --override <id> [--rank <n>]",
40
+ "Lower rank wins; an unranked contribution loses to any ranked one."
41
+ );
42
+ return lines.join("\n");
43
+ }
44
+
45
+ export async function register(plop, { host }) {
46
+ plop.setActionType("ddk:listContributions", (answers) =>
47
+ formatOverridableContributions(answers.point)
48
+ );
49
+ plop.setGenerator("ddk:contributions", {
50
+ description:
51
+ "List the standard DDK contributions a ddk:<point> --override can replace",
52
+ prompts: [
53
+ ...host.DEFAULT_PROMPTS,
54
+ {
55
+ type: "list",
56
+ name: "point",
57
+ message: "Which command's contributions?",
58
+ choices: [
59
+ { name: "All", value: "" },
60
+ ...Object.keys(OVERRIDABLE_POINTS).map((name) => ({
61
+ name: `ddk:${name}`,
62
+ value: name,
63
+ })),
64
+ ],
65
+ default: "",
66
+ },
67
+ ],
68
+ actions: host.actionFactory("ddk:listContributions", metadata[0]),
69
+ });
70
+ }
@@ -0,0 +1,116 @@
1
+ // ddk:<extension point> commands: one DDK contribution in a plugin project.
2
+ import {
3
+ CONTRIBUTION_TYPES,
4
+ generateDdkContribution,
5
+ } from "../codegen/contribution.mjs";
6
+ import { overridePrompts } from "./override-prompts.mjs";
7
+
8
+ const baseArguments = {
9
+ name: "componentName",
10
+ componentName: "componentName",
11
+ project: "componentProject",
12
+ componentProject: "componentProject",
13
+ dryRun: "dryRun",
14
+ interactive: "interactive",
15
+ };
16
+
17
+ const rankArguments = {
18
+ override: "override",
19
+ rank: "rank",
20
+ descriptor: "descriptor",
21
+ };
22
+
23
+ export const metadata = Object.entries(CONTRIBUTION_TYPES).map(
24
+ ([type, spec]) => ({
25
+ key: `ddk:${type}`,
26
+ name: spec.label,
27
+ projectType: "plugin",
28
+ invalidateCache: false,
29
+ namedArguments: {
30
+ ...baseArguments,
31
+ ...(spec.group ? { group: "group" } : {}),
32
+ ...(spec.overridable ? rankArguments : {}),
33
+ },
34
+ })
35
+ );
36
+
37
+ export async function register(plop, { host }) {
38
+ const pluginProjects = await host.getPluginProjectsWithFallback();
39
+
40
+ plop.setActionType("ddk:createContribution", async (answers, config) => {
41
+ const cwd = process.cwd();
42
+ const dryRun = !!answers.dryRun;
43
+ const codegenFs = host.codegenFsFor(cwd, dryRun);
44
+ const { label, notes } = generateDdkContribution(codegenFs, {
45
+ type: config.data.type,
46
+ name: answers.componentName,
47
+ project: answers.componentProject,
48
+ group: answers.group,
49
+ descriptor: answers.descriptor,
50
+ override: answers.override,
51
+ rank: answers.rank,
52
+ });
53
+ return host.reportCodegen(
54
+ codegenFs,
55
+ cwd,
56
+ dryRun,
57
+ [
58
+ `${label} ${answers.componentName} created in ${answers.componentProject}`,
59
+ ...notes,
60
+ ].join("\n")
61
+ );
62
+ });
63
+
64
+ for (const meta of metadata) {
65
+ const type = meta.key.slice("ddk:".length);
66
+ const spec = CONTRIBUTION_TYPES[type];
67
+ plop.setGenerator(meta.key, {
68
+ description: `Create a ${spec.label}`,
69
+ prompts: [
70
+ ...host.DEFAULT_PROMPTS,
71
+ {
72
+ type: "input",
73
+ name: "componentName",
74
+ message: "Enter the name of the component",
75
+ validate: host.required,
76
+ },
77
+ {
78
+ type: "list",
79
+ name: "componentProject",
80
+ message: "Which plugin project should the component be created in?",
81
+ choices: pluginProjects,
82
+ },
83
+ ...(spec.group
84
+ ? [
85
+ {
86
+ type: "input",
87
+ name: "group",
88
+ message: "Which settings group should the setting be located?",
89
+ validate: host.required,
90
+ },
91
+ ]
92
+ : []),
93
+ ...(spec.overridable
94
+ ? [
95
+ ...overridePrompts(type),
96
+ {
97
+ type: "input",
98
+ name: "descriptor",
99
+ message: `${spec.overridable} (blank: derived from the component name)?`,
100
+ default: "",
101
+ when: (answers) => !answers.override,
102
+ },
103
+ ]
104
+ : []),
105
+ ],
106
+ actions: () =>
107
+ host
108
+ .actionFactory("ddk:createContribution", meta)()
109
+ .map((action) =>
110
+ action.type === "ddk:createContribution"
111
+ ? { ...action, data: { type } }
112
+ : action
113
+ ),
114
+ });
115
+ }
116
+ }
@@ -0,0 +1,238 @@
1
+ // ddk:dashboard-card, ddk:pump-detail, ddk:pump-card, ddk:macro-summary and
2
+ // ddk:trouble-action.
3
+ import {
4
+ generateDashboardCard,
5
+ generateMacroSummary,
6
+ generatePumpCard,
7
+ generatePumpDetail,
8
+ generateTroubleAction,
9
+ } from "../codegen/contribution.mjs";
10
+ import { overridePrompts } from "./override-prompts.mjs";
11
+
12
+ const common = {
13
+ name: "componentName",
14
+ componentName: "componentName",
15
+ project: "componentProject",
16
+ componentProject: "componentProject",
17
+ dryRun: "dryRun",
18
+ interactive: "interactive",
19
+ override: "override",
20
+ rank: "rank",
21
+ };
22
+
23
+ const notOverriding = (answers) => !answers.override;
24
+
25
+ const dashboardKeyPrompt = (message) => ({
26
+ type: "input",
27
+ name: "dashboardKey",
28
+ message,
29
+ when: notOverriding,
30
+ });
31
+
32
+ const COMMANDS = [
33
+ {
34
+ key: "ddk:dashboard-card",
35
+ point: "dashboard-card",
36
+ name: "DDK Dashboard Card",
37
+ description:
38
+ "Create a dashboard summary card and the detail it opens, sharing one dashboardKey",
39
+ namedArguments: {
40
+ ...common,
41
+ dashboardKey: "dashboardKey",
42
+ detail: "detail",
43
+ },
44
+ prompts: [
45
+ dashboardKeyPrompt(
46
+ "Dashboard key (the assembly property whose models get a card)?"
47
+ ),
48
+ {
49
+ type: "confirm",
50
+ name: "detail",
51
+ message: "Also create the detail the card opens?",
52
+ default: true,
53
+ },
54
+ ],
55
+ generate: (codegenFs, a) =>
56
+ generateDashboardCard(codegenFs, {
57
+ name: a.componentName,
58
+ project: a.componentProject,
59
+ dashboardKey: a.dashboardKey,
60
+ detail: a.detail !== false,
61
+ override: a.override,
62
+ rank: a.rank,
63
+ }),
64
+ },
65
+ {
66
+ key: "ddk:pump-detail",
67
+ point: "pump-detail",
68
+ name: "DDK Pump Detail",
69
+ description: "Create a pump detail for holders with a given dashboard key",
70
+ namedArguments: { ...common, dashboardKey: "dashboardKey" },
71
+ prompts: [
72
+ dashboardKeyPrompt("Dashboard key (default factory: the pump type)?"),
73
+ ],
74
+ generate: (codegenFs, a) =>
75
+ generatePumpDetail(codegenFs, {
76
+ name: a.componentName,
77
+ project: a.componentProject,
78
+ dashboardKey: a.dashboardKey,
79
+ override: a.override,
80
+ rank: a.rank,
81
+ }),
82
+ },
83
+ {
84
+ key: "ddk:pump-card",
85
+ point: "pump-card",
86
+ name: "DDK Pump Card",
87
+ description:
88
+ "Create a pump card for a pump type: the holder card body and the pump detail, sharing one dashboardKey",
89
+ namedArguments: {
90
+ ...common,
91
+ dashboardKey: "dashboardKey",
92
+ detail: "detail",
93
+ },
94
+ prompts: [
95
+ dashboardKeyPrompt("Dashboard key (default factory: the pump type)?"),
96
+ {
97
+ type: "confirm",
98
+ name: "detail",
99
+ message: "Also create the pump detail the holder modal shows?",
100
+ default: true,
101
+ },
102
+ ],
103
+ generate: (codegenFs, a) =>
104
+ generatePumpCard(codegenFs, {
105
+ name: a.componentName,
106
+ project: a.componentProject,
107
+ dashboardKey: a.dashboardKey,
108
+ detail: a.detail !== false,
109
+ override: a.override,
110
+ rank: a.rank,
111
+ }),
112
+ },
113
+ {
114
+ key: "ddk:macro-summary",
115
+ point: "macro-summary",
116
+ name: "DDK Macro Summary",
117
+ description: "Create the macro holder card body for a holder name or key",
118
+ namedArguments: { ...common, dashboardKey: "dashboardKey" },
119
+ prompts: [dashboardKeyPrompt("Holder name or dashboard key?")],
120
+ generate: (codegenFs, a) =>
121
+ generateMacroSummary(codegenFs, {
122
+ name: a.componentName,
123
+ project: a.componentProject,
124
+ dashboardKey: a.dashboardKey,
125
+ override: a.override,
126
+ rank: a.rank,
127
+ }),
128
+ },
129
+ {
130
+ key: "ddk:trouble-action",
131
+ point: "trouble-action",
132
+ name: "DDK Trouble Action",
133
+ description:
134
+ "Create the experience shown while the device has an active trouble of a type",
135
+ namedArguments: {
136
+ ...common,
137
+ troubleType: "troubleType",
138
+ stateKey: "stateKey",
139
+ stateValue: "stateValue",
140
+ },
141
+ prompts: [
142
+ {
143
+ type: "input",
144
+ name: "troubleType",
145
+ message: "Trouble type (exactly as the device raises it)?",
146
+ when: notOverriding,
147
+ },
148
+ {
149
+ type: "input",
150
+ name: "stateKey",
151
+ message:
152
+ "State key shared with related troubles (blank: the trouble type)?",
153
+ default: "",
154
+ when: notOverriding,
155
+ },
156
+ {
157
+ type: "input",
158
+ name: "stateValue",
159
+ message: "State value (blank: the trouble type)?",
160
+ default: "",
161
+ when: notOverriding,
162
+ },
163
+ ],
164
+ generate: (codegenFs, a) =>
165
+ generateTroubleAction(codegenFs, {
166
+ name: a.componentName,
167
+ project: a.componentProject,
168
+ troubleType: a.troubleType,
169
+ stateKey: a.stateKey,
170
+ stateValue: a.stateValue,
171
+ override: a.override,
172
+ rank: a.rank,
173
+ }),
174
+ },
175
+ ];
176
+
177
+ export const metadata = COMMANDS.map(({ key, name, namedArguments }) => ({
178
+ key,
179
+ name,
180
+ projectType: "plugin",
181
+ invalidateCache: false,
182
+ namedArguments,
183
+ }));
184
+
185
+ export async function register(plop, { host }) {
186
+ const pluginProjects = await host.getPluginProjectsWithFallback();
187
+
188
+ plop.setActionType(
189
+ "ddk:createDashboardContribution",
190
+ async (answers, config) => {
191
+ const command = COMMANDS.find((c) => c.key === config.data.key);
192
+ const cwd = process.cwd();
193
+ const dryRun = !!answers.dryRun;
194
+ const codegenFs = host.codegenFsFor(cwd, dryRun);
195
+ const { label, notes } = command.generate(codegenFs, answers);
196
+ return host.reportCodegen(
197
+ codegenFs,
198
+ cwd,
199
+ dryRun,
200
+ [
201
+ `${label} ${answers.componentName} created in ${answers.componentProject}`,
202
+ ...notes,
203
+ ].join("\n")
204
+ );
205
+ }
206
+ );
207
+
208
+ for (const [i, command] of COMMANDS.entries()) {
209
+ plop.setGenerator(command.key, {
210
+ description: command.description,
211
+ prompts: [
212
+ ...host.DEFAULT_PROMPTS,
213
+ {
214
+ type: "input",
215
+ name: "componentName",
216
+ message: "Enter the name of the component",
217
+ validate: host.required,
218
+ },
219
+ {
220
+ type: "list",
221
+ name: "componentProject",
222
+ message: "Which plugin project should the component be created in?",
223
+ choices: pluginProjects,
224
+ },
225
+ ...overridePrompts(command.point),
226
+ ...command.prompts,
227
+ ],
228
+ actions: () =>
229
+ host
230
+ .actionFactory("ddk:createDashboardContribution", metadata[i])()
231
+ .map((action) =>
232
+ action.type === "ddk:createDashboardContribution"
233
+ ? { ...action, data: { key: command.key } }
234
+ : action
235
+ ),
236
+ });
237
+ }
238
+ }
@@ -0,0 +1,221 @@
1
+ // ddk:dev: serves the workspace's DDK plugin projects for a device to load with
2
+ // ?pluginDevServers=, using kosui's plugin dev server runner.
3
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+
7
+ const DDK_PLUGIN_TYPE = "ddk.ncui.plugin";
8
+ const SKIP_DIRS = new Set(["node_modules", "dist", "tmp", ".git", ".nx"]);
9
+ const LOG_DIR = process.env.DEV_LOG_DIR || "/tmp/kos-dev-logs";
10
+
11
+ export const metadata = {
12
+ key: "ddk:dev",
13
+ name: "DDK Plugin Dev Servers",
14
+ invalidateCache: false,
15
+ namedArguments: {
16
+ plugins: "plugins",
17
+ scenario: "scenario",
18
+ device: "device",
19
+ interactive: "interactive",
20
+ },
21
+ };
22
+
23
+ const readJson = (file) => JSON.parse(readFileSync(file, "utf-8"));
24
+
25
+ export function findWorkspaceRoot(start = process.cwd()) {
26
+ let dir = start;
27
+ while (dir !== path.dirname(dir)) {
28
+ if (existsSync(path.join(dir, "nx.json"))) return dir;
29
+ dir = path.dirname(dir);
30
+ }
31
+ throw new Error("ddk:dev must run inside an Nx workspace");
32
+ }
33
+
34
+ function findKosJsonFiles(dir, found) {
35
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
36
+ if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {
37
+ findKosJsonFiles(path.join(dir, entry.name), found);
38
+ } else if (entry.name === ".kos.json" && dir !== found.root) {
39
+ found.files.push(path.join(dir, entry.name));
40
+ }
41
+ }
42
+ return found.files;
43
+ }
44
+
45
+ /**
46
+ * DDK plugin projects (`.kos.json` type ddk.ncui.plugin) with the port of their `serve`
47
+ * target and the alias the root `.kos.json` gives them, if any.
48
+ */
49
+ export function findDdkPlugins(root) {
50
+ const rootKos = existsSync(path.join(root, ".kos.json"))
51
+ ? readJson(path.join(root, ".kos.json"))
52
+ : {};
53
+ const aliases = new Map(
54
+ (rootKos.development?.hosts ?? [])
55
+ .flatMap((host) => host.plugins ?? [])
56
+ .map((plugin) => [plugin.project, plugin.alias])
57
+ );
58
+ return findKosJsonFiles(root, { root, files: [] })
59
+ .filter((file) => readJson(file).type === DDK_PLUGIN_TYPE)
60
+ .map((file) => {
61
+ const projectJson = path.join(path.dirname(file), "project.json");
62
+ const project = existsSync(projectJson) ? readJson(projectJson) : {};
63
+ const name = project.name ?? path.basename(path.dirname(file));
64
+ return {
65
+ project: name,
66
+ dir: path.relative(root, path.dirname(file)).split(path.sep).join("/"),
67
+ alias: aliases.get(name),
68
+ port: project.targets?.serve?.options?.port,
69
+ };
70
+ })
71
+ .sort((a, b) => a.project.localeCompare(b.project));
72
+ }
73
+
74
+ /**
75
+ * The plugins to start: `scenario` names a list under `.kos.json`
76
+ * development.ddkScenarios, `plugins` is a comma-separated list; entries match a
77
+ * project name or alias. Neither selects every DDK plugin.
78
+ */
79
+ export function selectPlugins(all, { plugins, scenario, scenarios = {} }) {
80
+ let names;
81
+ if (scenario) {
82
+ names = scenarios[scenario];
83
+ if (!names) {
84
+ const known = Object.keys(scenarios);
85
+ throw new Error(
86
+ `Unknown scenario "${scenario}". ${
87
+ known.length
88
+ ? `Scenarios: ${known.join(", ")}.`
89
+ : "Define scenarios under development.ddkScenarios in .kos.json."
90
+ }`
91
+ );
92
+ }
93
+ } else if (plugins) {
94
+ names = plugins
95
+ .split(",")
96
+ .map((name) => name.trim())
97
+ .filter(Boolean);
98
+ } else {
99
+ return all;
100
+ }
101
+ return names.map((name) => {
102
+ const match = all.find(
103
+ (plugin) => plugin.project === name || plugin.alias === name
104
+ );
105
+ if (!match) {
106
+ throw new Error(
107
+ `"${name}" is not a DDK plugin project. DDK plugins: ${
108
+ all.map((plugin) => plugin.project).join(", ") || "none"
109
+ }.`
110
+ );
111
+ }
112
+ return match;
113
+ });
114
+ }
115
+
116
+ function devMachineAddress(device) {
117
+ if (!device || /\/\/(localhost|127\.0\.0\.1)(:|\/|$)/.test(device)) {
118
+ return "localhost";
119
+ }
120
+ const external = Object.values(os.networkInterfaces())
121
+ .flat()
122
+ .find((net) => net?.family === "IPv4" && !net.internal);
123
+ return external?.address ?? "localhost";
124
+ }
125
+
126
+ /** The URL that loads `plugins` into the DDK served by `device`. */
127
+ export function deviceUrl(device, plugins) {
128
+ const address = devMachineAddress(device);
129
+ const servers = plugins
130
+ .map((plugin) => `http://${address}:${plugin.port}`)
131
+ .join(",");
132
+ const base = device ? device.replace(/\/+$/, "") : "<device-url>";
133
+ // A page URL such as .../ncui/index.html takes the query directly.
134
+ const separator = /\/[^/]+\.[a-z]+$/i.test(new URL(base, "http://x").pathname)
135
+ ? ""
136
+ : "/";
137
+ return `${base}${separator}?pluginDevServers=${servers}`;
138
+ }
139
+
140
+ export async function register(plop, { host }) {
141
+ plop.setActionType("ddk:runDev", async (answers) => {
142
+ const root = findWorkspaceRoot();
143
+ const rootKos = existsSync(path.join(root, ".kos.json"))
144
+ ? readJson(path.join(root, ".kos.json"))
145
+ : {};
146
+ const selected = selectPlugins(findDdkPlugins(root), {
147
+ plugins: answers.plugins,
148
+ scenario: answers.scenario,
149
+ scenarios: rootKos.development?.ddkScenarios,
150
+ });
151
+ if (selected.length === 0) {
152
+ throw new Error("No DDK plugin projects found in this workspace.");
153
+ }
154
+ const unserved = selected.filter((plugin) => !plugin.port);
155
+ if (unserved.length > 0) {
156
+ throw new Error(
157
+ `No serve port for ${unserved
158
+ .map((plugin) => plugin.project)
159
+ .join(", ")}: give its serve target an options.port.`
160
+ );
161
+ }
162
+
163
+ if (typeof host.startPluginDevServers !== "function") {
164
+ throw new Error(
165
+ "ddk:dev needs a newer @kosdev-code/kos-ui-cli; update it with: kosui cli:update"
166
+ );
167
+ }
168
+
169
+ const ready = await host.startPluginDevServers(selected, {
170
+ logDir: LOG_DIR,
171
+ });
172
+ if (!ready) {
173
+ throw new Error(`Some plugin servers failed to start; logs: ${LOG_DIR}`);
174
+ }
175
+ console.log(
176
+ [
177
+ "",
178
+ "DDK plugin dev servers:",
179
+ ...selected.map(
180
+ (plugin) => ` ${plugin.project}: http://localhost:${plugin.port}`
181
+ ),
182
+ "",
183
+ "Load them into a running DDK with:",
184
+ ` ${deviceUrl(answers.device, selected)}`,
185
+ "",
186
+ "Press Ctrl+C to stop.",
187
+ ].join("\n")
188
+ );
189
+ await new Promise(() => {});
190
+ });
191
+
192
+ plop.setGenerator("ddk:dev", {
193
+ description:
194
+ "Serve DDK plugin projects for a running DDK to load with ?pluginDevServers=",
195
+ prompts: [
196
+ ...host.DEFAULT_PROMPTS,
197
+ {
198
+ type: "input",
199
+ name: "scenario",
200
+ message:
201
+ "Scenario from .kos.json development.ddkScenarios (blank: none)?",
202
+ default: "",
203
+ },
204
+ {
205
+ type: "input",
206
+ name: "plugins",
207
+ message: "Plugins to start, comma-separated (blank: all DDK plugins)?",
208
+ default: "",
209
+ when: (answers) => !answers.scenario,
210
+ },
211
+ {
212
+ type: "input",
213
+ name: "device",
214
+ message:
215
+ "Device URL, e.g. http://192.168.1.50:8081 (blank: print a template)?",
216
+ default: "",
217
+ },
218
+ ],
219
+ actions: host.actionFactory("ddk:runDev", metadata),
220
+ });
221
+ }
@@ -0,0 +1,27 @@
1
+ // The --override and --rank prompts every rankable ddk:<point> command shares.
2
+ import { listOverridableContributions } from "../codegen/overrides.mjs";
3
+
4
+ export function overridePrompts(point) {
5
+ return [
6
+ {
7
+ type: "list",
8
+ name: "override",
9
+ message: "Override a standard contribution?",
10
+ choices: () => [
11
+ { name: "No, add a new one", value: "" },
12
+ ...listOverridableContributions(point).map((entry) => ({
13
+ name: `${entry.id} (${Object.values(entry.keys).join(", ")})`,
14
+ value: entry.id,
15
+ })),
16
+ ],
17
+ default: "",
18
+ },
19
+ {
20
+ type: "input",
21
+ name: "rank",
22
+ message:
23
+ "Rank (lower wins; blank: unranked, or one that beats the overridden contribution)?",
24
+ default: "",
25
+ },
26
+ ];
27
+ }
@@ -0,0 +1,34 @@
1
+ // ddk:plugin-project: a DDK plugin project. kos-nx-plugin's generic plugin project with
2
+ // the DDK KAB type, Storybook preview, registration, contribution keys and packages.
3
+ import { createDdkProject } from "../codegen/project.mjs";
4
+
5
+ export const metadata = {
6
+ key: "ddk:plugin-project",
7
+ name: "DDK Plugin Project",
8
+ invalidateCache: true,
9
+ namedArguments: { name: "name", interactive: "interactive" },
10
+ };
11
+
12
+ export async function register(plop, { host }) {
13
+ plop.setActionType("ddk:createPluginProject", (answers) => {
14
+ createDdkProject("plugin", {
15
+ workspaceRoot: process.cwd(),
16
+ name: answers.name,
17
+ stdio: "inherit",
18
+ });
19
+ return `DDK plugin project ${answers.name} created.`;
20
+ });
21
+
22
+ plop.setGenerator("ddk:plugin-project", {
23
+ description: "Create a new DDK plugin project",
24
+ prompts: [
25
+ {
26
+ type: "input",
27
+ name: "name",
28
+ message: "What is the name of the plugin project?",
29
+ validate: host.required,
30
+ },
31
+ ],
32
+ actions: host.actionFactory("ddk:createPluginProject", metadata),
33
+ });
34
+ }