@kosdev-code/kos-ddk-cli 0.0.0-stage → 0.1.0-dev.107

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 (124) hide show
  1. package/README.md +181 -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 +45 -0
  6. package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +43 -0
  7. package/agent-plugin/kos-ddk-tools/catalog/contributions.json +965 -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 +21161 -0
  11. package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48656 -0
  12. package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +110 -0
  13. package/agent-plugin/kos-ddk-tools/skills/ddk-config-page/SKILL.md +130 -0
  14. package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +59 -0
  15. package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +45 -0
  16. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
  17. package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  18. package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
  19. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
  20. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  21. package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  22. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/__nameDashCase__.stories.tsx__template__ +38 -0
  23. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/__nameDashCase__.tsx__template__ +28 -0
  24. package/agent-plugin/kos-ddk-tools/templates/dashboard-region/index.ts__template__ +1 -0
  25. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
  26. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  27. package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  28. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  29. package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  30. package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
  31. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
  32. package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  33. package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
  34. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +113 -0
  35. package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
  36. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
  37. package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  38. package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
  39. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  40. package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  41. package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
  42. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
  43. package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  44. package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
  45. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
  46. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
  47. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
  48. package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  49. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
  50. package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  51. package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
  52. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +60 -0
  53. package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +88 -0
  54. package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
  55. package/catalog/contributions.json +965 -0
  56. package/guides/config-property-cards.md +77 -0
  57. package/guides/ddk-dev.md +59 -0
  58. package/guides/getting-started.md +126 -0
  59. package/guides/storybook.md +127 -0
  60. package/package.json +33 -3
  61. package/reference/reference.json +21161 -0
  62. package/src/build-paths.mjs +20 -0
  63. package/src/codegen/contribution.mjs +530 -0
  64. package/src/codegen/descriptor.mjs +422 -0
  65. package/src/codegen/json-preserve.mjs +137 -0
  66. package/src/codegen/ncui-descriptor.mjs +167 -0
  67. package/src/codegen/overrides.mjs +263 -0
  68. package/src/codegen/project.mjs +271 -0
  69. package/src/extension.mjs +32 -0
  70. package/src/generators/agent-install.mjs +80 -0
  71. package/src/generators/catalog.mjs +81 -0
  72. package/src/generators/contributions.mjs +164 -0
  73. package/src/generators/dashboard.mjs +282 -0
  74. package/src/generators/descriptor-entries.mjs +53 -0
  75. package/src/generators/descriptor-project.mjs +84 -0
  76. package/src/generators/dev.mjs +231 -0
  77. package/src/generators/override-prompts.mjs +27 -0
  78. package/src/generators/plugin-project.mjs +71 -0
  79. package/src/generators/theme-project.mjs +53 -0
  80. package/src/handlers.mjs +335 -0
  81. package/src/mcp/pkg-info.mjs +7 -0
  82. package/src/mcp/plugin-inspect.mjs +328 -0
  83. package/src/mcp/reference.mjs +315 -0
  84. package/src/mcp/server.mjs +12 -0
  85. package/src/mcp/tools.mjs +619 -0
  86. package/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
  87. package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
  88. package/templates/cui/index.ts__template__ +1 -0
  89. package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
  90. package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
  91. package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
  92. package/templates/dashboard-region/__nameDashCase__.stories.tsx__template__ +38 -0
  93. package/templates/dashboard-region/__nameDashCase__.tsx__template__ +28 -0
  94. package/templates/dashboard-region/index.ts__template__ +1 -0
  95. package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
  96. package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
  97. package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
  98. package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  99. package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
  100. package/templates/macro-summary/index.ts__template__ +1 -0
  101. package/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
  102. package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
  103. package/templates/nav/index.ts__template__ +1 -0
  104. package/templates/plugin-project/.storybook/preview.tsx.template +113 -0
  105. package/templates/plugin-project/.storybook/registration.ts.template +6 -0
  106. package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
  107. package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
  108. package/templates/pump-detail/index.ts__template__ +1 -0
  109. package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
  110. package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
  111. package/templates/pump-summary/index.ts__template__ +1 -0
  112. package/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
  113. package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
  114. package/templates/setup/index.ts__template__ +1 -0
  115. package/templates/theme-project/theme/assets/component.css.template +2 -0
  116. package/templates/theme-project/theme/assets/generic.css.template +2 -0
  117. package/templates/theme-project/theme/assets/semantic.css.template +2 -0
  118. package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
  119. package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
  120. package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
  121. package/templates/trouble-action/index.ts__template__ +1 -0
  122. package/templates/utility/__nameDashCase__.stories.tsx__template__ +60 -0
  123. package/templates/utility/__nameDashCase__.tsx__template__ +88 -0
  124. package/templates/utility/index.ts__template__ +1 -0
@@ -0,0 +1,32 @@
1
+ // kosui extension entry: adds the ddk:* commands when this package is installed in a
2
+ // KOS workspace (or globally beside kosui). kosui passes its CLI helpers as `host`.
3
+ import * as agentInstall from "./generators/agent-install.mjs";
4
+ import * as catalog from "./generators/catalog.mjs";
5
+ import * as contributions from "./generators/contributions.mjs";
6
+ import * as dashboard from "./generators/dashboard.mjs";
7
+ import * as descriptorEntries from "./generators/descriptor-entries.mjs";
8
+ import * as descriptorProject from "./generators/descriptor-project.mjs";
9
+ import * as dev from "./generators/dev.mjs";
10
+ import * as pluginProject from "./generators/plugin-project.mjs";
11
+ import * as themeProject from "./generators/theme-project.mjs";
12
+
13
+ export default {
14
+ id: "ddk",
15
+ generators: [
16
+ { metadata: contributions.metadata, register: contributions.register },
17
+ { metadata: dashboard.metadata, register: dashboard.register },
18
+ { metadata: catalog.metadata, register: catalog.register },
19
+ { metadata: pluginProject.metadata, register: pluginProject.register },
20
+ { metadata: themeProject.metadata, register: themeProject.register },
21
+ {
22
+ metadata: descriptorProject.metadata,
23
+ register: descriptorProject.register,
24
+ },
25
+ {
26
+ metadata: descriptorEntries.metadata,
27
+ register: descriptorEntries.register,
28
+ },
29
+ { metadata: dev.metadata, register: dev.register },
30
+ { metadata: agentInstall.metadata, register: agentInstall.register },
31
+ ],
32
+ };
@@ -0,0 +1,80 @@
1
+ // ddk:agent-install: registers this package's kos-ddk-tools agent plugin with an agent
2
+ // client, through kosui's `plugin install --from`.
3
+ import { spawnSync } from "node:child_process";
4
+ import { existsSync } from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ export const AGENT_PLUGIN_DIR = path.resolve(
9
+ path.dirname(fileURLToPath(import.meta.url)),
10
+ "../../agent-plugin"
11
+ );
12
+
13
+ export const metadata = {
14
+ key: "ddk:agent-install",
15
+ name: "DDK Agent Plugin Install",
16
+ description:
17
+ "Install the kos-ddk-tools agent plugin (kos-ddk MCP server) for an agent client",
18
+ invalidateCache: false,
19
+ namedArguments: {
20
+ client: "client",
21
+ scope: "scope",
22
+ interactive: "interactive",
23
+ },
24
+ };
25
+
26
+ /** The `plugin install` arguments for the bundle, the client and the scope. */
27
+ export function installArgs({ client, scope }, dir = AGENT_PLUGIN_DIR) {
28
+ return [
29
+ "plugin",
30
+ "install",
31
+ "--from",
32
+ dir,
33
+ ...(client ? ["--client", client] : []),
34
+ ...(scope ? ["--scope", scope] : []),
35
+ ];
36
+ }
37
+
38
+ export async function register(plop, { host }) {
39
+ plop.setActionType("ddk:agentInstall", (answers) => {
40
+ if (!existsSync(AGENT_PLUGIN_DIR)) {
41
+ throw new Error(
42
+ `Agent plugin bundle missing at ${AGENT_PLUGIN_DIR}; it is written by the kos-ddk-cli build.`
43
+ );
44
+ }
45
+ // process.argv[1] is the kosui entry running this extension.
46
+ const result = spawnSync(
47
+ process.execPath,
48
+ [process.argv[1], ...installArgs(answers)],
49
+ { stdio: "inherit" }
50
+ );
51
+ if (result.status !== 0) {
52
+ throw new Error(`kosui plugin install exited with ${result.status}`);
53
+ }
54
+ return "kos-ddk-tools agent plugin installed";
55
+ });
56
+
57
+ plop.setGenerator("ddk:agent-install", {
58
+ description: metadata.description,
59
+ prompts: [
60
+ ...host.DEFAULT_PROMPTS,
61
+ {
62
+ type: "input",
63
+ name: "client",
64
+ message: "Agent client, e.g. claude (blank: detect)?",
65
+ default: "",
66
+ },
67
+ {
68
+ type: "list",
69
+ name: "scope",
70
+ message: "Install scope?",
71
+ choices: [
72
+ { name: "user: every repo", value: "user" },
73
+ { name: "repo: this checkout only", value: "repo" },
74
+ ],
75
+ default: "user",
76
+ },
77
+ ],
78
+ actions: host.actionFactory("ddk:agentInstall", metadata),
79
+ });
80
+ }
@@ -0,0 +1,81 @@
1
+ // ddk:contributions: the standard contributions a ddk:<point> --override can replace.
2
+ import {
3
+ OVERRIDABLE_POINTS,
4
+ describeOverridablePoints,
5
+ listOverridableContributions,
6
+ } from "../codegen/overrides.mjs";
7
+
8
+ export const metadata = [
9
+ {
10
+ key: "ddk:contributions",
11
+ name: "DDK Overridable Contributions",
12
+ description:
13
+ "List the standard DDK contributions a ddk:<point> --override can replace",
14
+ invalidateCache: false,
15
+ namedArguments: { point: "point", interactive: "interactive" },
16
+ },
17
+ ];
18
+
19
+ const describeRank = (rank) =>
20
+ typeof rank === "number" ? `rank ${rank}` : "unranked";
21
+
22
+ /** One line per contribution, grouped by command, with how to override it. */
23
+ export function formatOverridableContributions(point) {
24
+ const entries = listOverridableContributions(point || undefined);
25
+ if (entries.length === 0) return "No overridable contributions.";
26
+ const lines = [];
27
+ for (const {
28
+ point: name,
29
+ contributionKeys,
30
+ noStandardContributions,
31
+ } of describeOverridablePoints(point || undefined)) {
32
+ const group = entries.filter((entry) => entry.point === name);
33
+ if (group.length === 0) continue;
34
+ const unfilled = noStandardContributions
35
+ ? `; no standard ${noStandardContributions.join(", ")}`
36
+ : "";
37
+ lines.push(
38
+ `ddk:${name} (writes ${contributionKeys.join(", ")}${unfilled})`
39
+ );
40
+ for (const entry of group) {
41
+ const slot = Object.entries(entry.keys)
42
+ .map(([key, value]) => `${key}=${value}`)
43
+ .join(" ");
44
+ lines.push(
45
+ ` ${entry.id} ${slot} ${describeRank(entry.rank)} (${entry.plugin})`
46
+ );
47
+ }
48
+ }
49
+ lines.push(
50
+ "",
51
+ "Override one with: kosui ddk:<point> --name <name> --project <plugin> --override <id> [--rank <n>]",
52
+ "Lower rank wins; an unranked contribution loses to any ranked one."
53
+ );
54
+ return lines.join("\n");
55
+ }
56
+
57
+ export async function register(plop, { host }) {
58
+ plop.setActionType("ddk:listContributions", (answers) =>
59
+ formatOverridableContributions(answers.point)
60
+ );
61
+ plop.setGenerator("ddk:contributions", {
62
+ description: metadata[0].description,
63
+ prompts: [
64
+ ...host.DEFAULT_PROMPTS,
65
+ {
66
+ type: "list",
67
+ name: "point",
68
+ message: "Which command's contributions?",
69
+ choices: [
70
+ { name: "All", value: "" },
71
+ ...Object.keys(OVERRIDABLE_POINTS).map((name) => ({
72
+ name: `ddk:${name}`,
73
+ value: name,
74
+ })),
75
+ ],
76
+ default: "",
77
+ },
78
+ ],
79
+ actions: host.actionFactory("ddk:listContributions", metadata[0]),
80
+ });
81
+ }
@@ -0,0 +1,164 @@
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
+ descriptorProject: "descriptorProject",
22
+ roles: "roles",
23
+ };
24
+
25
+ export const metadata = Object.entries(CONTRIBUTION_TYPES).map(
26
+ ([type, spec]) => ({
27
+ key: `ddk:${type}`,
28
+ name: spec.label,
29
+ description: spec.description,
30
+ projectType: "plugin",
31
+ invalidateCache: false,
32
+ namedArguments: {
33
+ ...baseArguments,
34
+ ...(spec.overridable ? rankArguments : {}),
35
+ ...(spec.descriptorType === "utility" ? { column: "column" } : {}),
36
+ ...(spec.layouts ? { layout: "layout" } : {}),
37
+ ...(spec.required ? { descriptor: "descriptor" } : {}),
38
+ },
39
+ })
40
+ );
41
+
42
+ export async function register(plop, { host }) {
43
+ const pluginProjects = await host.getPluginProjectsWithFallback();
44
+
45
+ plop.setActionType("ddk:createContribution", async (answers, config) => {
46
+ const cwd = process.cwd();
47
+ const dryRun = !!answers.dryRun;
48
+ const codegenFs = host.codegenFsFor(cwd, dryRun);
49
+ const { label, notes } = generateDdkContribution(codegenFs, {
50
+ type: config.data.type,
51
+ name: answers.componentName,
52
+ project: answers.componentProject,
53
+ descriptor: answers.descriptor,
54
+ override: answers.override,
55
+ rank: answers.rank,
56
+ descriptorProject: answers.descriptorProject || undefined,
57
+ roles: answers.roles || undefined,
58
+ column: answers.column || undefined,
59
+ layout: answers.layout || undefined,
60
+ });
61
+ return host.reportCodegen(
62
+ codegenFs,
63
+ cwd,
64
+ dryRun,
65
+ [
66
+ `${label} ${answers.componentName} created in ${answers.componentProject}`,
67
+ ...notes,
68
+ ].join("\n")
69
+ );
70
+ });
71
+
72
+ for (const meta of metadata) {
73
+ const type = meta.key.slice("ddk:".length);
74
+ const spec = CONTRIBUTION_TYPES[type];
75
+ plop.setGenerator(meta.key, {
76
+ description: spec.description,
77
+ prompts: [
78
+ ...host.DEFAULT_PROMPTS,
79
+ {
80
+ type: "input",
81
+ name: "componentName",
82
+ message: "Enter the name of the component",
83
+ validate: host.required,
84
+ },
85
+ {
86
+ type: "list",
87
+ name: "componentProject",
88
+ message: "Which plugin project should the component be created in?",
89
+ choices: pluginProjects,
90
+ },
91
+ ...(spec.layouts
92
+ ? [
93
+ {
94
+ type: "list",
95
+ name: "layout",
96
+ message: "Modal layout?",
97
+ choices: spec.layouts,
98
+ default: spec.layouts[0],
99
+ },
100
+ ]
101
+ : []),
102
+ ...(spec.required
103
+ ? [
104
+ {
105
+ type: "input",
106
+ name: "descriptor",
107
+ message: `${spec.required}?`,
108
+ validate: host.required,
109
+ },
110
+ ]
111
+ : []),
112
+ ...(spec.overridable
113
+ ? [
114
+ ...overridePrompts(type),
115
+ {
116
+ type: "input",
117
+ name: "descriptor",
118
+ message: `${spec.overridable} (blank: derived from the component name)?`,
119
+ default: "",
120
+ when: (answers) => !answers.override,
121
+ },
122
+ {
123
+ type: "input",
124
+ name: "descriptorProject",
125
+ message:
126
+ "Descriptor project to list it in (blank: none; see ddk:descriptor-project)?",
127
+ default: "",
128
+ when: (answers) => !answers.override,
129
+ },
130
+ {
131
+ type: "input",
132
+ name: "roles",
133
+ message:
134
+ "Roles that see it, comma-separated (blank: the default)?",
135
+ default: "",
136
+ when: (answers) =>
137
+ !answers.override && !!answers.descriptorProject,
138
+ },
139
+ ...(spec.descriptorType === "utility"
140
+ ? [
141
+ {
142
+ type: "input",
143
+ name: "column",
144
+ message: "Utilities column (blank: the last)?",
145
+ default: "",
146
+ when: (answers) =>
147
+ !answers.override && !!answers.descriptorProject,
148
+ },
149
+ ]
150
+ : []),
151
+ ]
152
+ : []),
153
+ ],
154
+ actions: () =>
155
+ host
156
+ .actionFactory("ddk:createContribution", meta)()
157
+ .map((action) =>
158
+ action.type === "ddk:createContribution"
159
+ ? { ...action, data: { type } }
160
+ : action
161
+ ),
162
+ });
163
+ }
164
+ }
@@ -0,0 +1,282 @@
1
+ // ddk:dashboard-card, ddk:pump-detail, ddk:pump-card, ddk:macro-summary,
2
+ // ddk:dashboard-region and ddk:trouble-action.
3
+ import {
4
+ generateDashboardCard,
5
+ generateDashboardRegion,
6
+ generateMacroSummary,
7
+ generatePumpCard,
8
+ generatePumpDetail,
9
+ generateTroubleAction,
10
+ } from "../codegen/contribution.mjs";
11
+ import { overridePrompts } from "./override-prompts.mjs";
12
+
13
+ const common = {
14
+ name: "componentName",
15
+ componentName: "componentName",
16
+ project: "componentProject",
17
+ componentProject: "componentProject",
18
+ dryRun: "dryRun",
19
+ interactive: "interactive",
20
+ override: "override",
21
+ rank: "rank",
22
+ };
23
+
24
+ const notOverriding = (answers) => !answers.override;
25
+
26
+ const dashboardKeyPrompt = (message) => ({
27
+ type: "input",
28
+ name: "dashboardKey",
29
+ message,
30
+ when: notOverriding,
31
+ });
32
+
33
+ const COMMANDS = [
34
+ {
35
+ key: "ddk:dashboard-card",
36
+ point: "dashboard-card",
37
+ name: "DDK Dashboard Card",
38
+ description:
39
+ "Create a dashboard summary card and the detail it opens, sharing one dashboardKey and rank; --detail false writes the summary only",
40
+ namedArguments: {
41
+ ...common,
42
+ dashboardKey: "dashboardKey",
43
+ detail: "detail",
44
+ },
45
+ prompts: [
46
+ dashboardKeyPrompt(
47
+ "Dashboard key (the assembly property whose models get a card)?"
48
+ ),
49
+ {
50
+ type: "confirm",
51
+ name: "detail",
52
+ message: "Also create the detail the card opens?",
53
+ default: true,
54
+ },
55
+ ],
56
+ generate: (codegenFs, a) =>
57
+ generateDashboardCard(codegenFs, {
58
+ name: a.componentName,
59
+ project: a.componentProject,
60
+ dashboardKey: a.dashboardKey,
61
+ detail: a.detail !== false,
62
+ override: a.override,
63
+ rank: a.rank,
64
+ }),
65
+ },
66
+ {
67
+ key: "ddk:pump-detail",
68
+ point: "pump-detail",
69
+ name: "DDK Pump Detail",
70
+ description: "Create a pump detail for holders with a given dashboard key",
71
+ namedArguments: { ...common, dashboardKey: "dashboardKey" },
72
+ prompts: [
73
+ dashboardKeyPrompt("Dashboard key (default factory: the pump type)?"),
74
+ ],
75
+ generate: (codegenFs, a) =>
76
+ generatePumpDetail(codegenFs, {
77
+ name: a.componentName,
78
+ project: a.componentProject,
79
+ dashboardKey: a.dashboardKey,
80
+ override: a.override,
81
+ rank: a.rank,
82
+ }),
83
+ },
84
+ {
85
+ key: "ddk:pump-card",
86
+ point: "pump-card",
87
+ name: "DDK Pump Card",
88
+ description:
89
+ "Create a pump card for a pump type: the holder card body and the pump detail, sharing one dashboardKey and rank; --detail false writes the body only",
90
+ namedArguments: {
91
+ ...common,
92
+ dashboardKey: "dashboardKey",
93
+ detail: "detail",
94
+ },
95
+ prompts: [
96
+ dashboardKeyPrompt("Dashboard key (default factory: the pump type)?"),
97
+ {
98
+ type: "confirm",
99
+ name: "detail",
100
+ message: "Also create the pump detail the holder modal shows?",
101
+ default: true,
102
+ },
103
+ ],
104
+ generate: (codegenFs, a) =>
105
+ generatePumpCard(codegenFs, {
106
+ name: a.componentName,
107
+ project: a.componentProject,
108
+ dashboardKey: a.dashboardKey,
109
+ detail: a.detail !== false,
110
+ override: a.override,
111
+ rank: a.rank,
112
+ }),
113
+ },
114
+ {
115
+ key: "ddk:macro-summary",
116
+ point: "macro-summary",
117
+ name: "DDK Macro Summary",
118
+ description: "Create the macro holder card body for a holder name or key",
119
+ namedArguments: { ...common, dashboardKey: "dashboardKey" },
120
+ prompts: [dashboardKeyPrompt("Holder name or dashboard key?")],
121
+ generate: (codegenFs, a) =>
122
+ generateMacroSummary(codegenFs, {
123
+ name: a.componentName,
124
+ project: a.componentProject,
125
+ dashboardKey: a.dashboardKey,
126
+ override: a.override,
127
+ rank: a.rank,
128
+ }),
129
+ },
130
+ {
131
+ key: "ddk:dashboard-region",
132
+ name: "DDK Dashboard Region",
133
+ description:
134
+ "Create a component that renders a whole dashboard region; --regionKey is the descriptor region's component or name (default: from the name), --descriptorProject adds the region",
135
+ namedArguments: {
136
+ name: "componentName",
137
+ componentName: "componentName",
138
+ project: "componentProject",
139
+ componentProject: "componentProject",
140
+ dryRun: "dryRun",
141
+ interactive: "interactive",
142
+ rank: "rank",
143
+ regionKey: "regionKey",
144
+ descriptorProject: "descriptorProject",
145
+ },
146
+ prompts: [
147
+ {
148
+ type: "input",
149
+ name: "regionKey",
150
+ message:
151
+ "Region key (a descriptor region's component or name; blank: from the name)?",
152
+ default: "",
153
+ },
154
+ {
155
+ type: "input",
156
+ name: "rank",
157
+ message: "Rank (lower wins; blank: unranked)?",
158
+ default: "",
159
+ },
160
+ ],
161
+ generate: (codegenFs, a) =>
162
+ generateDashboardRegion(codegenFs, {
163
+ name: a.componentName,
164
+ project: a.componentProject,
165
+ regionKey: a.regionKey,
166
+ rank: a.rank,
167
+ descriptorProject: a.descriptorProject,
168
+ }),
169
+ },
170
+ {
171
+ key: "ddk:trouble-action",
172
+ point: "trouble-action",
173
+ name: "DDK Trouble Action",
174
+ description:
175
+ "Create the experience shown while the device has an active trouble of a type",
176
+ namedArguments: {
177
+ ...common,
178
+ troubleType: "troubleType",
179
+ stateKey: "stateKey",
180
+ stateValue: "stateValue",
181
+ },
182
+ prompts: [
183
+ {
184
+ type: "input",
185
+ name: "troubleType",
186
+ message: "Trouble type (exactly as the device raises it)?",
187
+ when: notOverriding,
188
+ },
189
+ {
190
+ type: "input",
191
+ name: "stateKey",
192
+ message:
193
+ "State key shared with related troubles (blank: the trouble type)?",
194
+ default: "",
195
+ when: notOverriding,
196
+ },
197
+ {
198
+ type: "input",
199
+ name: "stateValue",
200
+ message: "State value (blank: the trouble type)?",
201
+ default: "",
202
+ when: notOverriding,
203
+ },
204
+ ],
205
+ generate: (codegenFs, a) =>
206
+ generateTroubleAction(codegenFs, {
207
+ name: a.componentName,
208
+ project: a.componentProject,
209
+ troubleType: a.troubleType,
210
+ stateKey: a.stateKey,
211
+ stateValue: a.stateValue,
212
+ override: a.override,
213
+ rank: a.rank,
214
+ }),
215
+ },
216
+ ];
217
+
218
+ export const metadata = COMMANDS.map(
219
+ ({ key, name, description, namedArguments }) => ({
220
+ key,
221
+ name,
222
+ description,
223
+ projectType: "plugin",
224
+ invalidateCache: false,
225
+ namedArguments,
226
+ })
227
+ );
228
+
229
+ export async function register(plop, { host }) {
230
+ const pluginProjects = await host.getPluginProjectsWithFallback();
231
+
232
+ plop.setActionType(
233
+ "ddk:createDashboardContribution",
234
+ async (answers, config) => {
235
+ const command = COMMANDS.find((c) => c.key === config.data.key);
236
+ const cwd = process.cwd();
237
+ const dryRun = !!answers.dryRun;
238
+ const codegenFs = host.codegenFsFor(cwd, dryRun);
239
+ const { label, notes } = command.generate(codegenFs, answers);
240
+ return host.reportCodegen(
241
+ codegenFs,
242
+ cwd,
243
+ dryRun,
244
+ [
245
+ `${label} ${answers.componentName} created in ${answers.componentProject}`,
246
+ ...notes,
247
+ ].join("\n")
248
+ );
249
+ }
250
+ );
251
+
252
+ for (const [i, command] of COMMANDS.entries()) {
253
+ plop.setGenerator(command.key, {
254
+ description: command.description,
255
+ prompts: [
256
+ ...host.DEFAULT_PROMPTS,
257
+ {
258
+ type: "input",
259
+ name: "componentName",
260
+ message: "Enter the name of the component",
261
+ validate: host.required,
262
+ },
263
+ {
264
+ type: "list",
265
+ name: "componentProject",
266
+ message: "Which plugin project should the component be created in?",
267
+ choices: pluginProjects,
268
+ },
269
+ ...(command.point ? overridePrompts(command.point) : []),
270
+ ...command.prompts,
271
+ ],
272
+ actions: () =>
273
+ host
274
+ .actionFactory("ddk:createDashboardContribution", metadata[i])()
275
+ .map((action) =>
276
+ action.type === "ddk:createDashboardContribution"
277
+ ? { ...action, data: { key: command.key } }
278
+ : action
279
+ ),
280
+ });
281
+ }
282
+ }
@@ -0,0 +1,53 @@
1
+ // ddk:descriptor-entries: lists the utility, setup step and navigation slots a plugin
2
+ // already contributes in an NCUI descriptor project.
3
+ import { addPluginDescriptorEntries } from "../codegen/descriptor.mjs";
4
+
5
+ export const metadata = {
6
+ key: "ddk:descriptor-entries",
7
+ name: "DDK Descriptor Entries",
8
+ description:
9
+ "List a plugin's utility, setup step and navigation slots in an NCUI descriptor project (for contributions written before it)",
10
+ projectType: "plugin",
11
+ invalidateCache: false,
12
+ namedArguments: {
13
+ project: "componentProject",
14
+ descriptorProject: "descriptorProject",
15
+ dryRun: "dryRun",
16
+ interactive: "interactive",
17
+ },
18
+ };
19
+
20
+ export async function register(plop, { host }) {
21
+ const pluginProjects = await host.getPluginProjectsWithFallback();
22
+
23
+ plop.setActionType("ddk:addDescriptorEntries", (answers) => {
24
+ const cwd = process.cwd();
25
+ const dryRun = !!answers.dryRun;
26
+ const codegenFs = host.codegenFsFor(cwd, dryRun);
27
+ const { notes } = addPluginDescriptorEntries(codegenFs, {
28
+ project: answers.componentProject,
29
+ descriptorProject: answers.descriptorProject,
30
+ });
31
+ return host.reportCodegen(codegenFs, cwd, dryRun, notes.join("\n"));
32
+ });
33
+
34
+ plop.setGenerator("ddk:descriptor-entries", {
35
+ description: metadata.description,
36
+ prompts: [
37
+ ...host.DEFAULT_PROMPTS,
38
+ {
39
+ type: "list",
40
+ name: "componentProject",
41
+ message: "Which plugin project?",
42
+ choices: pluginProjects,
43
+ },
44
+ {
45
+ type: "input",
46
+ name: "descriptorProject",
47
+ message: "Which descriptor project?",
48
+ validate: host.required,
49
+ },
50
+ ],
51
+ actions: host.actionFactory("ddk:addDescriptorEntries", metadata),
52
+ });
53
+ }