@kosdev-code/kos-ddk-cli 0.0.0-stage → 0.1.0-dev.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -2
- package/agent-plugin/.claude-plugin/marketplace.json +13 -0
- package/agent-plugin/kos-ddk-tools/.claude-plugin/plugin.json +8 -0
- package/agent-plugin/kos-ddk-tools/.mcp.json +11 -0
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-planner.md +40 -0
- package/agent-plugin/kos-ddk-tools/agents/kos-ddk-plugin-reviewer.md +33 -0
- package/agent-plugin/kos-ddk-tools/catalog/contributions.json +877 -0
- package/agent-plugin/kos-ddk-tools/mcp.json +12 -0
- package/agent-plugin/kos-ddk-tools/plugin.json +7 -0
- package/agent-plugin/kos-ddk-tools/reference/reference.json +19339 -0
- package/agent-plugin/kos-ddk-tools/servers/kos-ddk.mjs +48633 -0
- package/agent-plugin/kos-ddk-tools/skills/build-ddk-plugin/SKILL.md +74 -0
- package/agent-plugin/kos-ddk-tools/skills/ddk-content-component/SKILL.md +49 -0
- package/agent-plugin/kos-ddk-tools/skills/ddk-storybook/SKILL.md +39 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/__nameDashCase__.tsx__template__ +35 -0
- package/agent-plugin/kos-ddk-tools/templates/cui/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-detail/detail/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
- package/agent-plugin/kos-ddk-tools/templates/dashboard-summary/summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
- package/agent-plugin/kos-ddk-tools/templates/macro-summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/__nameDashCase__.tsx__template__ +27 -0
- package/agent-plugin/kos-ddk-tools/templates/nav/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/preview.tsx.template +113 -0
- package/agent-plugin/kos-ddk-tools/templates/plugin-project/.storybook/registration.ts.template +6 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-detail/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
- package/agent-plugin/kos-ddk-tools/templates/pump-summary/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/__nameDashCase__.tsx__template__ +33 -0
- package/agent-plugin/kos-ddk-tools/templates/setup/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/component.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/generic.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/semantic.css.template +2 -0
- package/agent-plugin/kos-ddk-tools/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
- package/agent-plugin/kos-ddk-tools/templates/trouble-action/index.ts__template__ +1 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.stories.tsx__template__ +32 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/__nameDashCase__.tsx__template__ +37 -0
- package/agent-plugin/kos-ddk-tools/templates/utility/index.ts__template__ +1 -0
- package/catalog/contributions.json +877 -0
- package/guides/ddk-dev.md +47 -0
- package/guides/getting-started.md +117 -0
- package/guides/storybook.md +104 -0
- package/package.json +33 -3
- package/reference/reference.json +19339 -0
- package/src/build-paths.mjs +20 -0
- package/src/codegen/contribution.mjs +425 -0
- package/src/codegen/descriptor.mjs +210 -0
- package/src/codegen/ncui-descriptor.mjs +134 -0
- package/src/codegen/overrides.mjs +263 -0
- package/src/codegen/project.mjs +242 -0
- package/src/extension.mjs +32 -0
- package/src/generators/agent-install.mjs +80 -0
- package/src/generators/catalog.mjs +81 -0
- package/src/generators/contributions.mjs +151 -0
- package/src/generators/dashboard.mjs +241 -0
- package/src/generators/descriptor-entries.mjs +53 -0
- package/src/generators/descriptor-project.mjs +79 -0
- package/src/generators/dev.mjs +231 -0
- package/src/generators/override-prompts.mjs +27 -0
- package/src/generators/plugin-project.mjs +66 -0
- package/src/generators/theme-project.mjs +45 -0
- package/src/handlers.mjs +315 -0
- package/src/mcp/pkg-info.mjs +7 -0
- package/src/mcp/plugin-inspect.mjs +292 -0
- package/src/mcp/reference.mjs +264 -0
- package/src/mcp/server.mjs +12 -0
- package/src/mcp/tools.mjs +575 -0
- package/templates/cui/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/cui/__nameDashCase__.tsx__template__ +35 -0
- package/templates/cui/index.ts__template__ +1 -0
- package/templates/dashboard-detail/detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/dashboard-detail/detail/__nameDashCase__.tsx__template__ +52 -0
- package/templates/dashboard-detail/detail/index.ts__template__ +1 -0
- package/templates/dashboard-summary/summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/dashboard-summary/summary/__nameDashCase__.tsx__template__ +41 -0
- package/templates/dashboard-summary/summary/index.ts__template__ +1 -0
- package/templates/macro-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/macro-summary/__nameDashCase__.tsx__template__ +24 -0
- package/templates/macro-summary/index.ts__template__ +1 -0
- package/templates/nav/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/nav/__nameDashCase__.tsx__template__ +27 -0
- package/templates/nav/index.ts__template__ +1 -0
- package/templates/plugin-project/.storybook/preview.tsx.template +113 -0
- package/templates/plugin-project/.storybook/registration.ts.template +6 -0
- package/templates/pump-detail/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/pump-detail/__nameDashCase__.tsx__template__ +38 -0
- package/templates/pump-detail/index.ts__template__ +1 -0
- package/templates/pump-summary/__nameDashCase__.stories.tsx__template__ +34 -0
- package/templates/pump-summary/__nameDashCase__.tsx__template__ +25 -0
- package/templates/pump-summary/index.ts__template__ +1 -0
- package/templates/setup/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/setup/__nameDashCase__.tsx__template__ +33 -0
- package/templates/setup/index.ts__template__ +1 -0
- package/templates/theme-project/theme/assets/component.css.template +2 -0
- package/templates/theme-project/theme/assets/generic.css.template +2 -0
- package/templates/theme-project/theme/assets/semantic.css.template +2 -0
- package/templates/theme-project/theme/assets/theme-overlay.css.template +7 -0
- package/templates/trouble-action/__nameDashCase__.stories.tsx__template__ +31 -0
- package/templates/trouble-action/__nameDashCase__.tsx__template__ +57 -0
- package/templates/trouble-action/index.ts__template__ +1 -0
- package/templates/utility/__nameDashCase__.stories.tsx__template__ +32 -0
- package/templates/utility/__nameDashCase__.tsx__template__ +37 -0
- package/templates/utility/index.ts__template__ +1 -0
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
description:
|
|
15
|
+
"Serve DDK plugin projects for a running DDK to load with ?pluginDevServers=",
|
|
16
|
+
invalidateCache: false,
|
|
17
|
+
namedArguments: {
|
|
18
|
+
plugins: "plugins",
|
|
19
|
+
scenario: "scenario",
|
|
20
|
+
device: "device",
|
|
21
|
+
interactive: "interactive",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const readJson = (file) => JSON.parse(readFileSync(file, "utf-8"));
|
|
26
|
+
|
|
27
|
+
export function findWorkspaceRoot(start = process.cwd()) {
|
|
28
|
+
let dir = start;
|
|
29
|
+
while (dir !== path.dirname(dir)) {
|
|
30
|
+
if (existsSync(path.join(dir, "nx.json"))) return dir;
|
|
31
|
+
dir = path.dirname(dir);
|
|
32
|
+
}
|
|
33
|
+
throw new Error("ddk:dev must run inside an Nx workspace");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function findKosJsonFiles(dir, found) {
|
|
37
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
38
|
+
if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {
|
|
39
|
+
findKosJsonFiles(path.join(dir, entry.name), found);
|
|
40
|
+
} else if (entry.name === ".kos.json" && dir !== found.root) {
|
|
41
|
+
found.files.push(path.join(dir, entry.name));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return found.files;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* DDK plugin projects (`.kos.json` type ddk.ncui.plugin) with the port of their `serve`
|
|
49
|
+
* target and the alias the root `.kos.json` gives them, if any.
|
|
50
|
+
*/
|
|
51
|
+
export function findDdkPlugins(root) {
|
|
52
|
+
const rootKos = existsSync(path.join(root, ".kos.json"))
|
|
53
|
+
? readJson(path.join(root, ".kos.json"))
|
|
54
|
+
: {};
|
|
55
|
+
const aliases = new Map(
|
|
56
|
+
(rootKos.development?.hosts ?? [])
|
|
57
|
+
.flatMap((host) => host.plugins ?? [])
|
|
58
|
+
.map((plugin) => [plugin.project, plugin.alias])
|
|
59
|
+
);
|
|
60
|
+
return findKosJsonFiles(root, { root, files: [] })
|
|
61
|
+
.filter((file) => readJson(file).type === DDK_PLUGIN_TYPE)
|
|
62
|
+
.map((file) => {
|
|
63
|
+
const projectJson = path.join(path.dirname(file), "project.json");
|
|
64
|
+
const project = existsSync(projectJson) ? readJson(projectJson) : {};
|
|
65
|
+
const name = project.name ?? path.basename(path.dirname(file));
|
|
66
|
+
return {
|
|
67
|
+
project: name,
|
|
68
|
+
dir: path.relative(root, path.dirname(file)).split(path.sep).join("/"),
|
|
69
|
+
alias: aliases.get(name),
|
|
70
|
+
port: project.targets?.serve?.options?.port,
|
|
71
|
+
};
|
|
72
|
+
})
|
|
73
|
+
.sort((a, b) => a.project.localeCompare(b.project));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The plugins to start: `scenario` names a list under `.kos.json`
|
|
78
|
+
* development.ddkScenarios, `plugins` is a comma-separated list; entries match a
|
|
79
|
+
* project name or alias. Neither selects every DDK plugin.
|
|
80
|
+
*/
|
|
81
|
+
export function selectPlugins(all, { plugins, scenario, scenarios = {} }) {
|
|
82
|
+
let names;
|
|
83
|
+
if (scenario) {
|
|
84
|
+
names = scenarios[scenario];
|
|
85
|
+
if (!names) {
|
|
86
|
+
const known = Object.keys(scenarios);
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Unknown scenario "${scenario}". ${
|
|
89
|
+
known.length
|
|
90
|
+
? `Scenarios: ${known.join(", ")}.`
|
|
91
|
+
: "Define scenarios under development.ddkScenarios in .kos.json."
|
|
92
|
+
}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} else if (plugins) {
|
|
96
|
+
names = plugins
|
|
97
|
+
.split(",")
|
|
98
|
+
.map((name) => name.trim())
|
|
99
|
+
.filter(Boolean);
|
|
100
|
+
} else {
|
|
101
|
+
return all;
|
|
102
|
+
}
|
|
103
|
+
return names.map((name) => {
|
|
104
|
+
const match = all.find(
|
|
105
|
+
(plugin) => plugin.project === name || plugin.alias === name
|
|
106
|
+
);
|
|
107
|
+
if (!match) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`"${name}" is not a DDK plugin project. DDK plugins: ${
|
|
110
|
+
all.map((plugin) => plugin.project).join(", ") || "none"
|
|
111
|
+
}.`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return match;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function devMachineAddress(device) {
|
|
119
|
+
if (!device || /\/\/(localhost|127\.0\.0\.1)(:|\/|$)/.test(device)) {
|
|
120
|
+
return "localhost";
|
|
121
|
+
}
|
|
122
|
+
const external = Object.values(os.networkInterfaces())
|
|
123
|
+
.flat()
|
|
124
|
+
.find((net) => net?.family === "IPv4" && !net.internal);
|
|
125
|
+
return external?.address ?? "localhost";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Where a device or simulator serves the DDK NCUI. */
|
|
129
|
+
export const NCUI_PATH = "/app/kosdev.ddk/ncui/index.html";
|
|
130
|
+
|
|
131
|
+
/** The URL that loads `plugins` into the DDK served by `device`. */
|
|
132
|
+
export function deviceUrl(device, plugins) {
|
|
133
|
+
const address = devMachineAddress(device);
|
|
134
|
+
const servers = plugins
|
|
135
|
+
.map((plugin) => `http://${address}:${plugin.port}`)
|
|
136
|
+
.join(",");
|
|
137
|
+
const base = device ? device.replace(/\/+$/, "") : "<device-url>";
|
|
138
|
+
const pathname = new URL(base, "http://x").pathname;
|
|
139
|
+
// An origin gets the NCUI page; a page URL such as .../ncui/index.html takes the
|
|
140
|
+
// query directly.
|
|
141
|
+
const page = !device
|
|
142
|
+
? "/"
|
|
143
|
+
: pathname === "/"
|
|
144
|
+
? NCUI_PATH
|
|
145
|
+
: /\/[^/]+\.[a-z]+$/i.test(pathname)
|
|
146
|
+
? ""
|
|
147
|
+
: "/";
|
|
148
|
+
return `${base}${page}?pluginDevServers=${servers}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function register(plop, { host }) {
|
|
152
|
+
plop.setActionType("ddk:runDev", async (answers) => {
|
|
153
|
+
const root = findWorkspaceRoot();
|
|
154
|
+
const rootKos = existsSync(path.join(root, ".kos.json"))
|
|
155
|
+
? readJson(path.join(root, ".kos.json"))
|
|
156
|
+
: {};
|
|
157
|
+
const selected = selectPlugins(findDdkPlugins(root), {
|
|
158
|
+
plugins: answers.plugins,
|
|
159
|
+
scenario: answers.scenario,
|
|
160
|
+
scenarios: rootKos.development?.ddkScenarios,
|
|
161
|
+
});
|
|
162
|
+
if (selected.length === 0) {
|
|
163
|
+
throw new Error("No DDK plugin projects found in this workspace.");
|
|
164
|
+
}
|
|
165
|
+
const unserved = selected.filter((plugin) => !plugin.port);
|
|
166
|
+
if (unserved.length > 0) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`No serve port for ${unserved
|
|
169
|
+
.map((plugin) => plugin.project)
|
|
170
|
+
.join(", ")}: give its serve target an options.port.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (typeof host.startPluginDevServers !== "function") {
|
|
175
|
+
throw new Error(
|
|
176
|
+
"ddk:dev needs a newer @kosdev-code/kos-ui-cli; update it with: kosui cli:update"
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const ready = await host.startPluginDevServers(selected, {
|
|
181
|
+
logDir: LOG_DIR,
|
|
182
|
+
});
|
|
183
|
+
if (!ready) {
|
|
184
|
+
throw new Error(`Some plugin servers failed to start; logs: ${LOG_DIR}`);
|
|
185
|
+
}
|
|
186
|
+
console.log(
|
|
187
|
+
[
|
|
188
|
+
"",
|
|
189
|
+
"DDK plugin dev servers:",
|
|
190
|
+
...selected.map(
|
|
191
|
+
(plugin) => ` ${plugin.project}: http://localhost:${plugin.port}`
|
|
192
|
+
),
|
|
193
|
+
"",
|
|
194
|
+
"Load them into a running DDK with:",
|
|
195
|
+
` ${deviceUrl(answers.device, selected)}`,
|
|
196
|
+
"",
|
|
197
|
+
"Press Ctrl+C to stop.",
|
|
198
|
+
].join("\n")
|
|
199
|
+
);
|
|
200
|
+
await new Promise(() => {});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
plop.setGenerator("ddk:dev", {
|
|
204
|
+
description: metadata.description,
|
|
205
|
+
prompts: [
|
|
206
|
+
...host.DEFAULT_PROMPTS,
|
|
207
|
+
{
|
|
208
|
+
type: "input",
|
|
209
|
+
name: "scenario",
|
|
210
|
+
message:
|
|
211
|
+
"Scenario from .kos.json development.ddkScenarios (blank: none)?",
|
|
212
|
+
default: "",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
type: "input",
|
|
216
|
+
name: "plugins",
|
|
217
|
+
message: "Plugins to start, comma-separated (blank: all DDK plugins)?",
|
|
218
|
+
default: "",
|
|
219
|
+
when: (answers) => !answers.scenario,
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
type: "input",
|
|
223
|
+
name: "device",
|
|
224
|
+
message:
|
|
225
|
+
"Device URL, e.g. http://192.168.1.50:8081 (blank: print a template)?",
|
|
226
|
+
default: "",
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
actions: host.actionFactory("ddk:runDev", metadata),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
@@ -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,66 @@
|
|
|
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
|
+
const installNote = (toInstall) =>
|
|
6
|
+
toInstall?.length
|
|
7
|
+
? `Run npm install: the project added ${toInstall.join(", ")}.`
|
|
8
|
+
: "";
|
|
9
|
+
|
|
10
|
+
export const metadata = {
|
|
11
|
+
key: "ddk:plugin-project",
|
|
12
|
+
name: "DDK Plugin Project",
|
|
13
|
+
description:
|
|
14
|
+
"Create a new DDK plugin project; --directory sets the parent folder, --host the host it registers with",
|
|
15
|
+
invalidateCache: true,
|
|
16
|
+
namedArguments: {
|
|
17
|
+
name: "name",
|
|
18
|
+
directory: "directory",
|
|
19
|
+
host: "host",
|
|
20
|
+
interactive: "interactive",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export async function register(plop, { host }) {
|
|
25
|
+
plop.setActionType("ddk:createPluginProject", (answers) => {
|
|
26
|
+
const { toInstall } = createDdkProject("plugin", {
|
|
27
|
+
workspaceRoot: process.cwd(),
|
|
28
|
+
name: answers.name,
|
|
29
|
+
directory: answers.directory || undefined,
|
|
30
|
+
host: answers.host || undefined,
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
});
|
|
33
|
+
return [
|
|
34
|
+
`DDK plugin project ${answers.name} created.`,
|
|
35
|
+
installNote(toInstall),
|
|
36
|
+
]
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.join("\n");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
plop.setGenerator("ddk:plugin-project", {
|
|
42
|
+
description: metadata.description,
|
|
43
|
+
prompts: [
|
|
44
|
+
{
|
|
45
|
+
type: "input",
|
|
46
|
+
name: "name",
|
|
47
|
+
message: "What is the name of the plugin project?",
|
|
48
|
+
validate: host.required,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "input",
|
|
52
|
+
name: "directory",
|
|
53
|
+
message: "Folder to create it in (blank: plugins)?",
|
|
54
|
+
default: "",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "input",
|
|
58
|
+
name: "host",
|
|
59
|
+
message:
|
|
60
|
+
"Host to register with (blank: the kosdev.ddk host, else none)?",
|
|
61
|
+
default: "",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
actions: host.actionFactory("ddk:createPluginProject", metadata),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const installNote = (toInstall) =>
|
|
6
|
+
toInstall?.length
|
|
7
|
+
? `Run npm install: the project added ${toInstall.join(", ")}.`
|
|
8
|
+
: "";
|
|
9
|
+
|
|
10
|
+
export const metadata = {
|
|
11
|
+
key: "ddk:theme-project",
|
|
12
|
+
name: "DDK Theme Project",
|
|
13
|
+
description: "Create a new DDK theme project",
|
|
14
|
+
invalidateCache: true,
|
|
15
|
+
namedArguments: { name: "name", interactive: "interactive" },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function register(plop, { host }) {
|
|
19
|
+
plop.setActionType("ddk:createThemeProject", (answers) => {
|
|
20
|
+
const { toInstall } = createDdkProject("theme", {
|
|
21
|
+
workspaceRoot: process.cwd(),
|
|
22
|
+
name: answers.name,
|
|
23
|
+
stdio: "inherit",
|
|
24
|
+
});
|
|
25
|
+
return [
|
|
26
|
+
`DDK theme project ${answers.name} created.`,
|
|
27
|
+
installNote(toInstall),
|
|
28
|
+
]
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join("\n");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
plop.setGenerator("ddk:theme-project", {
|
|
34
|
+
description: metadata.description,
|
|
35
|
+
prompts: [
|
|
36
|
+
{
|
|
37
|
+
type: "input",
|
|
38
|
+
name: "name",
|
|
39
|
+
message: "What is the name of the theme project?",
|
|
40
|
+
validate: host.required,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
actions: host.actionFactory("ddk:createThemeProject", metadata),
|
|
44
|
+
});
|
|
45
|
+
}
|
package/src/handlers.mjs
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
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
|
+
if (!options.descriptor) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"A CUI configuration needs its cuiDescriptor (descriptor)"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return this.contribute(options, {
|
|
60
|
+
suffix: "",
|
|
61
|
+
experienceSuffix: "cui",
|
|
62
|
+
key: "cui",
|
|
63
|
+
fields: {
|
|
64
|
+
titleSuffix: "cui",
|
|
65
|
+
extra: { cuiDescriptor: options.descriptor },
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class DdkSetupHandler extends DdkHandler {
|
|
72
|
+
pluginType = "ddk.setup";
|
|
73
|
+
contributionKey = "setup";
|
|
74
|
+
rankable = true;
|
|
75
|
+
|
|
76
|
+
createConfiguration(options) {
|
|
77
|
+
return this.contribute(options, {
|
|
78
|
+
suffix: "setup",
|
|
79
|
+
experienceSuffix: "setup",
|
|
80
|
+
key: "setupStep",
|
|
81
|
+
fields: {
|
|
82
|
+
titleSuffix: "setup",
|
|
83
|
+
extra: {
|
|
84
|
+
setupDescriptor: options.descriptor || options.nameCamelCase,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class DdkUtilityHandler extends DdkHandler {
|
|
92
|
+
pluginType = "ddk.utility";
|
|
93
|
+
contributionKey = "utility";
|
|
94
|
+
rankable = true;
|
|
95
|
+
|
|
96
|
+
createConfiguration(options) {
|
|
97
|
+
return this.contribute(options, {
|
|
98
|
+
suffix: "util",
|
|
99
|
+
experienceSuffix: "util",
|
|
100
|
+
key: "utilities",
|
|
101
|
+
fields: {
|
|
102
|
+
titleSuffix: "utility",
|
|
103
|
+
extra: {
|
|
104
|
+
utilDescriptor: options.descriptor || options.nameCamelCase,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class DdkNavHandler extends DdkHandler {
|
|
112
|
+
pluginType = "ddk.nav";
|
|
113
|
+
contributionKey = "nav";
|
|
114
|
+
rankable = true;
|
|
115
|
+
|
|
116
|
+
createConfiguration(options) {
|
|
117
|
+
return this.contribute(options, {
|
|
118
|
+
suffix: "nav",
|
|
119
|
+
experienceSuffix: "nav",
|
|
120
|
+
key: "navViews",
|
|
121
|
+
fields: {
|
|
122
|
+
titleSuffix: "nav",
|
|
123
|
+
extra: {
|
|
124
|
+
navDescriptor: options.descriptor || options.nameLowerCase,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Contributions that carry their extension point's `type` literal. Ids, title key
|
|
132
|
+
// and i18n entry all hang off `${project}.${name}.${contributionKey}`.
|
|
133
|
+
class TypedDdkHandler extends DdkHandler {
|
|
134
|
+
rankable = true;
|
|
135
|
+
|
|
136
|
+
/** Exposed component name, which must be unique within the plugin. */
|
|
137
|
+
componentName(options) {
|
|
138
|
+
return options.namePascalCase;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
contributionFields() {
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
createConfiguration(options) {
|
|
146
|
+
const config = this.contribute(options, {
|
|
147
|
+
suffix: this.contributionKey,
|
|
148
|
+
experienceSuffix: this.contributionKey,
|
|
149
|
+
key: this.kosJsonKey,
|
|
150
|
+
fields: {
|
|
151
|
+
titleSuffix: this.contributionKey,
|
|
152
|
+
extra: {
|
|
153
|
+
type: this.extensionType,
|
|
154
|
+
...this.contributionFields(options),
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
for (const experience of Object.values(config.experiences)) {
|
|
159
|
+
experience.component = this.componentName(options);
|
|
160
|
+
}
|
|
161
|
+
return config;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
class DashboardCardHandler extends TypedDdkHandler {
|
|
166
|
+
getTargetDirectory() {
|
|
167
|
+
return "dashboard";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
getComponentPath(options) {
|
|
171
|
+
return `${options.appDirectory}/dashboard/${options.nameDashCase}/${this.part}/${options.nameDashCase}.tsx`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
componentName(options) {
|
|
175
|
+
return `${options.namePascalCase}${
|
|
176
|
+
this.part === "summary" ? "Summary" : "Detail"
|
|
177
|
+
}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
contributionFields(options) {
|
|
181
|
+
return { dashboardKey: options.dashboardKey };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export class DdkDashboardSummaryHandler extends DashboardCardHandler {
|
|
186
|
+
pluginType = "ddk.dashboardSummary";
|
|
187
|
+
contributionKey = "dashboardSummary";
|
|
188
|
+
kosJsonKey = "dashboardSummary";
|
|
189
|
+
extensionType = "dashboard.summary";
|
|
190
|
+
part = "summary";
|
|
191
|
+
|
|
192
|
+
getTemplatePath() {
|
|
193
|
+
return "dashboard-summary";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export class DdkDashboardDetailHandler extends DashboardCardHandler {
|
|
198
|
+
pluginType = "ddk.dashboardDetail";
|
|
199
|
+
contributionKey = "dashboardDetail";
|
|
200
|
+
kosJsonKey = "dashboardDetail";
|
|
201
|
+
extensionType = "dashboard.detail";
|
|
202
|
+
part = "detail";
|
|
203
|
+
|
|
204
|
+
getTemplatePath() {
|
|
205
|
+
return "dashboard-detail";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export class DdkPumpDetailHandler extends TypedDdkHandler {
|
|
210
|
+
pluginType = "ddk.pumpDetail";
|
|
211
|
+
contributionKey = "dashboardPumpDetail";
|
|
212
|
+
kosJsonKey = "dashboardPumpDetail";
|
|
213
|
+
extensionType = "dashboard.detail.pump";
|
|
214
|
+
|
|
215
|
+
getTargetDirectory() {
|
|
216
|
+
return "dashboard/pumpDetail";
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
getTemplatePath() {
|
|
220
|
+
return "pump-detail";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
contributionFields(options) {
|
|
224
|
+
return { dashboardKey: options.dashboardKey };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export class DdkPumpSummaryHandler extends TypedDdkHandler {
|
|
229
|
+
pluginType = "ddk.pumpSummary";
|
|
230
|
+
contributionKey = "dashboardPumpSummary";
|
|
231
|
+
kosJsonKey = "dashboardPumpSummary";
|
|
232
|
+
extensionType = "dashboard.summary.pump";
|
|
233
|
+
|
|
234
|
+
getTargetDirectory() {
|
|
235
|
+
return "dashboard/pumpSummary";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getTemplatePath() {
|
|
239
|
+
return "pump-summary";
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Distinct from the pump detail of the same name, which is exposed as its PascalCase name.
|
|
243
|
+
componentName(options) {
|
|
244
|
+
return `${options.namePascalCase}Summary`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
contributionFields(options) {
|
|
248
|
+
return { dashboardKey: options.dashboardKey };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export class DdkMacroSummaryHandler extends TypedDdkHandler {
|
|
253
|
+
pluginType = "ddk.macroSummary";
|
|
254
|
+
contributionKey = "dashboardMacroSummary";
|
|
255
|
+
kosJsonKey = "dashboardMacroSummary";
|
|
256
|
+
extensionType = "dashboard.macro.summary";
|
|
257
|
+
|
|
258
|
+
getTargetDirectory() {
|
|
259
|
+
return "dashboard/macroSummary";
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
getTemplatePath() {
|
|
263
|
+
return "macro-summary";
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
contributionFields(options) {
|
|
267
|
+
return { dashboardKey: options.dashboardKey };
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export class DdkTroubleActionHandler extends TypedDdkHandler {
|
|
272
|
+
pluginType = "ddk.troubleAction";
|
|
273
|
+
contributionKey = "troubleAction";
|
|
274
|
+
kosJsonKey = "troubleActions";
|
|
275
|
+
extensionType = "trouble.action";
|
|
276
|
+
|
|
277
|
+
getTargetDirectory() {
|
|
278
|
+
return "trouble-action";
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
getTemplatePath() {
|
|
282
|
+
return "trouble-action";
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
contributionFields(options) {
|
|
286
|
+
return {
|
|
287
|
+
troubleType: options.troubleType,
|
|
288
|
+
stateKey: options.stateKey || options.troubleType,
|
|
289
|
+
stateValue: options.stateValue || options.troubleType,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export const DDK_HANDLERS = [
|
|
295
|
+
DdkCuiHandler,
|
|
296
|
+
DdkSetupHandler,
|
|
297
|
+
DdkUtilityHandler,
|
|
298
|
+
DdkNavHandler,
|
|
299
|
+
DdkDashboardSummaryHandler,
|
|
300
|
+
DdkDashboardDetailHandler,
|
|
301
|
+
DdkPumpDetailHandler,
|
|
302
|
+
DdkPumpSummaryHandler,
|
|
303
|
+
DdkMacroSummaryHandler,
|
|
304
|
+
DdkTroubleActionHandler,
|
|
305
|
+
];
|
|
306
|
+
|
|
307
|
+
/** Register every DDK handler once with this copy of codegen-core. */
|
|
308
|
+
export function registerDdkHandlers() {
|
|
309
|
+
for (const Handler of DDK_HANDLERS) {
|
|
310
|
+
const type = new Handler().pluginType;
|
|
311
|
+
if (!PluginHandlerFactory.isValidPluginType(type)) {
|
|
312
|
+
PluginHandlerFactory.register(type, Handler);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -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
|
+
);
|