@kosdev-code/kos-ui-cli 2.1.39 → 3.0.0
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/package.json +5 -6
- package/src/lib/cli.mjs +34 -10
- package/src/lib/generators/component/index.mjs +1230 -27
- package/src/lib/generators/component/index.mjs.map +7 -0
- package/src/lib/generators/model/add-future.mjs +1449 -43
- package/src/lib/generators/model/add-future.mjs.map +7 -0
- package/src/lib/generators/model/companion.mjs +1465 -56
- package/src/lib/generators/model/companion.mjs.map +7 -0
- package/src/lib/generators/model/container.mjs +1234 -45
- package/src/lib/generators/model/container.mjs.map +7 -0
- package/src/lib/generators/model/context.mjs +1102 -35
- package/src/lib/generators/model/context.mjs.map +7 -0
- package/src/lib/generators/model/hook.mjs +1097 -33
- package/src/lib/generators/model/hook.mjs.map +7 -0
- package/src/lib/generators/model/model.mjs +1411 -39
- package/src/lib/generators/model/model.mjs.map +7 -0
- package/src/lib/generators/plugin/index.mjs +1275 -74
- package/src/lib/generators/plugin/index.mjs.map +7 -0
- package/src/lib/generators/project/splash.mjs +691 -21
- package/src/lib/generators/project/splash.mjs.map +7 -0
- package/src/lib/utils/dev-config.mjs +7 -12
- package/src/lib/utils/nx-context.mjs +584 -170
- package/src/lib/utils/nx-context.mjs.map +7 -0
- package/README.md +0 -484
- package/src/index.d.ts +0 -2
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -1
- package/src/index.js.map +0 -1
|
@@ -1,14 +1,1203 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// ../kos-codegen-core/src/lib/codegen-filesystem.ts
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
var TrackingFileSystem = class {
|
|
5
|
+
inner;
|
|
6
|
+
_writtenPaths = [];
|
|
7
|
+
constructor(inner) {
|
|
8
|
+
this.inner = inner;
|
|
9
|
+
}
|
|
10
|
+
get root() {
|
|
11
|
+
return this.inner.root;
|
|
12
|
+
}
|
|
13
|
+
get writtenPaths() {
|
|
14
|
+
return [...this._writtenPaths];
|
|
15
|
+
}
|
|
16
|
+
read(filePath) {
|
|
17
|
+
return this.inner.read(filePath);
|
|
18
|
+
}
|
|
19
|
+
write(filePath, content) {
|
|
20
|
+
this.inner.write(filePath, content);
|
|
21
|
+
this._writtenPaths.push(
|
|
22
|
+
path.isAbsolute(filePath) ? filePath : path.join(this.inner.root, filePath)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
exists(filePath) {
|
|
26
|
+
return this.inner.exists(filePath);
|
|
27
|
+
}
|
|
28
|
+
delete(filePath) {
|
|
29
|
+
this.inner.delete(filePath);
|
|
30
|
+
}
|
|
31
|
+
listFiles(dirPath) {
|
|
32
|
+
return this.inner.listFiles(dirPath);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var DirectFileSystem = class {
|
|
36
|
+
root;
|
|
37
|
+
constructor(workspaceRoot) {
|
|
38
|
+
this.root = path.resolve(workspaceRoot);
|
|
39
|
+
}
|
|
40
|
+
read(filePath) {
|
|
41
|
+
const abs = this.resolve(filePath);
|
|
42
|
+
try {
|
|
43
|
+
return fs.readFileSync(abs, "utf-8");
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
write(filePath, content) {
|
|
49
|
+
const abs = this.resolve(filePath);
|
|
50
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
51
|
+
fs.writeFileSync(abs, content, "utf-8");
|
|
52
|
+
}
|
|
53
|
+
exists(filePath) {
|
|
54
|
+
return fs.existsSync(this.resolve(filePath));
|
|
55
|
+
}
|
|
56
|
+
delete(filePath) {
|
|
57
|
+
const abs = this.resolve(filePath);
|
|
58
|
+
try {
|
|
59
|
+
fs.unlinkSync(abs);
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
listFiles(dirPath) {
|
|
64
|
+
const abs = this.resolve(dirPath);
|
|
65
|
+
if (!fs.existsSync(abs)) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
return this.walkDir(abs).map((file) => path.relative(this.root, file));
|
|
69
|
+
}
|
|
70
|
+
resolve(filePath) {
|
|
71
|
+
if (path.isAbsolute(filePath)) {
|
|
72
|
+
return filePath;
|
|
73
|
+
}
|
|
74
|
+
return path.join(this.root, filePath);
|
|
75
|
+
}
|
|
76
|
+
walkDir(dir) {
|
|
77
|
+
const results = [];
|
|
78
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
const full = path.join(dir, entry.name);
|
|
81
|
+
if (entry.isDirectory()) {
|
|
82
|
+
results.push(...this.walkDir(full));
|
|
83
|
+
} else {
|
|
84
|
+
results.push(full);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return results;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// ../kos-codegen-core/src/lib/generate-files.ts
|
|
92
|
+
import * as fs2 from "fs";
|
|
93
|
+
import * as path2 from "path";
|
|
94
|
+
import * as ejs from "ejs";
|
|
95
|
+
|
|
96
|
+
// ../kos-codegen-core/src/lib/logger.ts
|
|
97
|
+
var noopLogger = {
|
|
98
|
+
debug: () => {
|
|
99
|
+
},
|
|
100
|
+
info: () => {
|
|
101
|
+
},
|
|
102
|
+
warn: () => {
|
|
103
|
+
},
|
|
104
|
+
error: () => {
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var activeLogger = noopLogger;
|
|
108
|
+
function getCodegenLogger() {
|
|
109
|
+
return activeLogger;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ../kos-codegen-core/src/lib/generate-files.ts
|
|
113
|
+
function generateFilesFromTemplates(codegenFs, srcFolder, destFolder, substitutions) {
|
|
114
|
+
const logger = getCodegenLogger();
|
|
115
|
+
const templateFiles = walkTemplateDir(srcFolder);
|
|
116
|
+
for (const templateFile of templateFiles) {
|
|
117
|
+
const relPath = path2.relative(srcFolder, templateFile);
|
|
118
|
+
let destRelPath = interpolateFilename(relPath, substitutions);
|
|
119
|
+
if (destRelPath.endsWith(".template")) {
|
|
120
|
+
destRelPath = destRelPath.slice(0, -".template".length);
|
|
121
|
+
}
|
|
122
|
+
const destPath = path2.join(destFolder, destRelPath);
|
|
123
|
+
const rawContent = fs2.readFileSync(templateFile, "utf-8");
|
|
124
|
+
const rendered = ejs.render(rawContent, substitutions, {
|
|
125
|
+
filename: templateFile
|
|
126
|
+
// for EJS error messages and includes
|
|
127
|
+
});
|
|
128
|
+
logger.debug(`Generating ${destPath}`);
|
|
129
|
+
codegenFs.write(destPath, rendered);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function interpolateFilename(filePath, substitutions) {
|
|
133
|
+
return filePath.replace(/__([^_]+)__/g, (match, key) => {
|
|
134
|
+
if (key in substitutions) {
|
|
135
|
+
return String(substitutions[key]);
|
|
136
|
+
}
|
|
137
|
+
return match;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function walkTemplateDir(dir) {
|
|
141
|
+
const results = [];
|
|
142
|
+
const entries = fs2.readdirSync(dir, { withFileTypes: true });
|
|
143
|
+
for (const entry of entries) {
|
|
144
|
+
const full = path2.join(dir, entry.name);
|
|
145
|
+
if (entry.isDirectory()) {
|
|
146
|
+
results.push(...walkTemplateDir(full));
|
|
147
|
+
} else {
|
|
148
|
+
results.push(full);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return results;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ../kos-codegen-core/src/lib/project-discovery.ts
|
|
155
|
+
import * as fs3 from "fs";
|
|
156
|
+
import * as path3 from "path";
|
|
157
|
+
import fg from "fast-glob";
|
|
158
|
+
function discoverProjects(workspaceRoot) {
|
|
159
|
+
const logger = getCodegenLogger();
|
|
160
|
+
const projects = /* @__PURE__ */ new Map();
|
|
161
|
+
const projectJsonPaths = fg.sync("**/project.json", {
|
|
162
|
+
cwd: workspaceRoot,
|
|
163
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/.git/**"],
|
|
164
|
+
absolute: false
|
|
165
|
+
});
|
|
166
|
+
for (const relPath of projectJsonPaths) {
|
|
167
|
+
const absPath = path3.join(workspaceRoot, relPath);
|
|
168
|
+
try {
|
|
169
|
+
const raw = fs3.readFileSync(absPath, "utf-8");
|
|
170
|
+
const json = JSON.parse(raw);
|
|
171
|
+
const projectRoot = path3.dirname(relPath);
|
|
172
|
+
const name = json.name ?? path3.basename(projectRoot);
|
|
173
|
+
const config = {
|
|
174
|
+
name,
|
|
175
|
+
root: projectRoot,
|
|
176
|
+
sourceRoot: json.sourceRoot ?? path3.join(projectRoot, "src"),
|
|
177
|
+
projectType: json.projectType,
|
|
178
|
+
targets: json.targets,
|
|
179
|
+
tags: json.tags
|
|
180
|
+
};
|
|
181
|
+
projects.set(name, config);
|
|
182
|
+
logger.debug(`Discovered project: ${name} at ${projectRoot}`);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
logger.warn(`Failed to parse ${absPath}: ${err}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
logger.info(`Discovered ${projects.size} projects`);
|
|
188
|
+
return projects;
|
|
189
|
+
}
|
|
190
|
+
function findProjectByName(workspaceRoot, projectName, projects) {
|
|
191
|
+
const map = projects ?? discoverProjects(workspaceRoot);
|
|
192
|
+
return map.get(projectName);
|
|
193
|
+
}
|
|
194
|
+
function findProjectForPath(workspaceRoot, filePath) {
|
|
195
|
+
const resolved = path3.resolve(workspaceRoot);
|
|
196
|
+
let dir = path3.dirname(path3.resolve(filePath));
|
|
197
|
+
while (dir.startsWith(resolved) && dir !== resolved) {
|
|
198
|
+
const projectJsonPath = path3.join(dir, "project.json");
|
|
199
|
+
if (fs3.existsSync(projectJsonPath)) {
|
|
200
|
+
try {
|
|
201
|
+
const raw = fs3.readFileSync(projectJsonPath, "utf-8");
|
|
202
|
+
const json = JSON.parse(raw);
|
|
203
|
+
const projectRoot = path3.relative(resolved, dir);
|
|
204
|
+
const name = json.name ?? path3.basename(dir);
|
|
205
|
+
return {
|
|
206
|
+
name,
|
|
207
|
+
root: projectRoot,
|
|
208
|
+
sourceRoot: json.sourceRoot ?? path3.join(projectRoot, "src"),
|
|
209
|
+
projectType: json.projectType,
|
|
210
|
+
targets: json.targets,
|
|
211
|
+
tags: json.tags
|
|
212
|
+
};
|
|
213
|
+
} catch {
|
|
214
|
+
return void 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
dir = path3.dirname(dir);
|
|
218
|
+
}
|
|
219
|
+
return void 0;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ../kos-codegen-core/src/lib/json-utils.ts
|
|
223
|
+
function readJson(codegenFs, filePath) {
|
|
224
|
+
const content = codegenFs.read(filePath);
|
|
225
|
+
if (content === null) {
|
|
226
|
+
throw new Error(`File not found: ${filePath}`);
|
|
227
|
+
}
|
|
228
|
+
return JSON.parse(content);
|
|
229
|
+
}
|
|
230
|
+
function writeJson(codegenFs, filePath, value) {
|
|
231
|
+
codegenFs.write(filePath, JSON.stringify(value, null, 2) + "\n");
|
|
232
|
+
}
|
|
233
|
+
function updateJson(codegenFs, filePath, updater) {
|
|
234
|
+
const current = readJson(codegenFs, filePath);
|
|
235
|
+
const updated = updater(current);
|
|
236
|
+
writeJson(codegenFs, filePath, updated);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ../kos-codegen-core/src/lib/format-files.ts
|
|
240
|
+
import * as fs4 from "fs";
|
|
241
|
+
import * as path4 from "path";
|
|
242
|
+
import prettier from "prettier";
|
|
243
|
+
var FORMATTABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
244
|
+
".ts",
|
|
245
|
+
".tsx",
|
|
246
|
+
".js",
|
|
247
|
+
".jsx",
|
|
248
|
+
".json",
|
|
249
|
+
".css",
|
|
250
|
+
".scss",
|
|
251
|
+
".md",
|
|
252
|
+
".yaml",
|
|
253
|
+
".yml",
|
|
254
|
+
".html"
|
|
255
|
+
]);
|
|
256
|
+
async function formatFiles(workspaceRoot, filePaths) {
|
|
257
|
+
const logger = getCodegenLogger();
|
|
258
|
+
for (const filePath of filePaths) {
|
|
259
|
+
const ext = path4.extname(filePath);
|
|
260
|
+
if (!FORMATTABLE_EXTENSIONS.has(ext)) {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const content = fs4.readFileSync(filePath, "utf-8");
|
|
265
|
+
const options = await prettier.resolveConfig(filePath, {
|
|
266
|
+
editorconfig: true
|
|
267
|
+
});
|
|
268
|
+
const formatted = await prettier.format(content, {
|
|
269
|
+
...options,
|
|
270
|
+
filepath: filePath
|
|
271
|
+
});
|
|
272
|
+
fs4.writeFileSync(filePath, formatted, "utf-8");
|
|
273
|
+
logger.debug(`Formatted ${path4.relative(workspaceRoot, filePath)}`);
|
|
274
|
+
} catch (err) {
|
|
275
|
+
logger.warn(`Failed to format ${filePath}: ${err}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ../kos-codegen-core/src/lib/name-utils.ts
|
|
281
|
+
function dashCase(input) {
|
|
282
|
+
return input.replace(/\s+/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
283
|
+
}
|
|
284
|
+
function camelCase(input) {
|
|
285
|
+
if (input.length === 0)
|
|
286
|
+
return "";
|
|
287
|
+
const words = input.split(/-|\s+/);
|
|
288
|
+
if (words.length > 0 && words[0].length > 0) {
|
|
289
|
+
words[0] = words[0].charAt(0).toLowerCase() + words[0].slice(1);
|
|
290
|
+
}
|
|
291
|
+
for (let i = 1; i < words.length; i++) {
|
|
292
|
+
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
|
|
293
|
+
}
|
|
294
|
+
return words.join("");
|
|
295
|
+
}
|
|
296
|
+
function pascalCase(input) {
|
|
297
|
+
if (input.length === 0)
|
|
298
|
+
return "";
|
|
299
|
+
const cc = camelCase(input);
|
|
300
|
+
return cc[0].toUpperCase() + cc.slice(1);
|
|
301
|
+
}
|
|
302
|
+
function properCase(input) {
|
|
303
|
+
const words = input.toLowerCase().replaceAll("-", " ").split(" ").filter(Boolean);
|
|
304
|
+
for (let i = 0; i < words.length; i++) {
|
|
305
|
+
words[i] = words[i][0].toUpperCase() + words[i].slice(1);
|
|
306
|
+
}
|
|
307
|
+
return words.join("");
|
|
308
|
+
}
|
|
309
|
+
function constantCase(input) {
|
|
310
|
+
if (input.length === 0)
|
|
311
|
+
return "";
|
|
312
|
+
return input.toUpperCase().split(/[\s-]+/).filter(Boolean).join("_");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ../kos-codegen-core/src/lib/normalize-values.ts
|
|
316
|
+
var normalizeValue = (optionsName, value) => ({
|
|
317
|
+
[`${camelCase(optionsName)}CamelCase`]: camelCase(value),
|
|
318
|
+
[`${camelCase(optionsName)}ConstantCase`]: constantCase(value),
|
|
319
|
+
[`${camelCase(optionsName)}DashCase`]: dashCase(value),
|
|
320
|
+
[`${camelCase(optionsName)}PascalCase`]: pascalCase(value),
|
|
321
|
+
[`${camelCase(optionsName)}ProperCase`]: properCase(value),
|
|
322
|
+
[`${camelCase(optionsName)}LowerCase`]: value.toLowerCase(),
|
|
323
|
+
[`${optionsName}`]: value
|
|
324
|
+
});
|
|
325
|
+
var normalizeAllValues = (options) => {
|
|
326
|
+
let normalizedValues = {};
|
|
327
|
+
for (const key in options) {
|
|
328
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
329
|
+
const element = options[key];
|
|
330
|
+
const newOptions = typeof element !== "string" || element === "" ? { [key]: element } : normalizeValue(key, element);
|
|
331
|
+
normalizedValues = {
|
|
332
|
+
...normalizedValues,
|
|
333
|
+
...newOptions
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return normalizedValues;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// ../kos-codegen-core/src/lib/kos-config.ts
|
|
341
|
+
import * as path5 from "path";
|
|
342
|
+
function getCurrentDirectoryName(cwd) {
|
|
343
|
+
return cwd.split("/").pop();
|
|
344
|
+
}
|
|
345
|
+
function getProject(codegenFs, cwd) {
|
|
346
|
+
return findProjectForPath(codegenFs.root, cwd);
|
|
347
|
+
}
|
|
348
|
+
function getKosProjectConfiguration(codegenFs, projectName, projects) {
|
|
349
|
+
const project = findProjectByName(codegenFs.root, projectName, projects);
|
|
350
|
+
if (!project)
|
|
351
|
+
return void 0;
|
|
352
|
+
const configPath = path5.join(project.root, ".kos.json");
|
|
353
|
+
if (!codegenFs.exists(configPath)) {
|
|
354
|
+
const defaultConfig = {
|
|
355
|
+
name: `${dashCase(projectName)}-model`,
|
|
356
|
+
type: "kos.model",
|
|
357
|
+
version: "0.1.0",
|
|
358
|
+
models: {},
|
|
359
|
+
generator: { defaults: { model: { folder: "" } } }
|
|
360
|
+
};
|
|
361
|
+
codegenFs.write(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
362
|
+
}
|
|
363
|
+
const content = codegenFs.read(configPath);
|
|
364
|
+
return content ? JSON.parse(content) : void 0;
|
|
365
|
+
}
|
|
366
|
+
function addKosModelConfiguration(params) {
|
|
367
|
+
const logger = getCodegenLogger();
|
|
368
|
+
const kosConfigPath = path5.join(params.projectRoot, ".kos.json");
|
|
369
|
+
if (!params.codegenFs.exists(kosConfigPath)) {
|
|
370
|
+
logger.info(`Creating .kos.json in ${params.projectRoot}`);
|
|
371
|
+
const defaultConfig = {
|
|
372
|
+
name: params.projectName,
|
|
373
|
+
type: "kos.model",
|
|
374
|
+
version: "0.1.0",
|
|
375
|
+
models: {},
|
|
376
|
+
generator: { defaults: { model: { folder: "" } } }
|
|
377
|
+
};
|
|
378
|
+
params.codegenFs.write(
|
|
379
|
+
kosConfigPath,
|
|
380
|
+
JSON.stringify(defaultConfig, null, 2) + "\n"
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
updateJson(params.codegenFs, kosConfigPath, (json) => {
|
|
384
|
+
json.models = {
|
|
385
|
+
...json.models,
|
|
386
|
+
[params.modelName]: {
|
|
387
|
+
name: params.modelName,
|
|
388
|
+
type: `${params.modelName}-model`,
|
|
389
|
+
singleton: !!params.singleton,
|
|
390
|
+
container: !!params.container
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
return json;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ../kos-codegen-core/src/lib/template-resolver.ts
|
|
398
|
+
import * as path6 from "path";
|
|
399
|
+
import * as fs5 from "fs";
|
|
400
|
+
function findPackageRoot() {
|
|
401
|
+
if (process.env.KOS_TEMPLATE_BASE_DIR) {
|
|
402
|
+
return process.env.KOS_TEMPLATE_BASE_DIR;
|
|
403
|
+
}
|
|
404
|
+
let dir = __dirname;
|
|
405
|
+
while (dir !== path6.dirname(dir)) {
|
|
406
|
+
const pkgPath = path6.join(dir, "package.json");
|
|
407
|
+
if (fs5.existsSync(pkgPath)) {
|
|
408
|
+
try {
|
|
409
|
+
const pkg = JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
410
|
+
if (pkg.name === "@kosdev-code/kos-codegen-core") {
|
|
411
|
+
return dir;
|
|
412
|
+
}
|
|
413
|
+
} catch {
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
dir = path6.dirname(dir);
|
|
417
|
+
}
|
|
418
|
+
return path6.resolve(__dirname, "..", "..");
|
|
419
|
+
}
|
|
420
|
+
function getTemplateDir(generatorName) {
|
|
421
|
+
return path6.join(findPackageRoot(), "templates", generatorName);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ../kos-codegen-core/src/lib/generators/normalize-options.ts
|
|
425
|
+
import * as path7 from "path";
|
|
426
|
+
function normalizeOptions(codegenFs, options, projects) {
|
|
427
|
+
const toNormalize = {
|
|
428
|
+
name: options.name
|
|
429
|
+
};
|
|
430
|
+
if (options.modelName) {
|
|
431
|
+
toNormalize.modelName = options.modelName;
|
|
432
|
+
}
|
|
433
|
+
if (options.companionModel) {
|
|
434
|
+
toNormalize.companionModel = options.companionModel;
|
|
435
|
+
}
|
|
436
|
+
const normalizedValues = normalizeAllValues(toNormalize);
|
|
437
|
+
const modelProject = options.modelProject;
|
|
438
|
+
const registrationProject = options.registrationProject || "";
|
|
439
|
+
const useModelProject = modelProject !== "__NONE__";
|
|
440
|
+
let importPath = "";
|
|
441
|
+
if (useModelProject) {
|
|
442
|
+
const modelProjectConfig = findProjectByName(
|
|
443
|
+
codegenFs.root,
|
|
444
|
+
modelProject,
|
|
445
|
+
projects
|
|
446
|
+
);
|
|
447
|
+
if (modelProjectConfig) {
|
|
448
|
+
const pkgJsonPath = path7.join(modelProjectConfig.root, "package.json");
|
|
449
|
+
try {
|
|
450
|
+
const pkgJson = readJson(codegenFs, pkgJsonPath);
|
|
451
|
+
importPath = pkgJson.name || "";
|
|
452
|
+
} catch {
|
|
453
|
+
importPath = "";
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const booleanDefaults = {
|
|
458
|
+
companion: false,
|
|
459
|
+
skipRegistration: false
|
|
460
|
+
};
|
|
461
|
+
return {
|
|
462
|
+
...booleanDefaults,
|
|
463
|
+
...options,
|
|
464
|
+
...normalizedValues,
|
|
465
|
+
modelProject,
|
|
466
|
+
importPath,
|
|
467
|
+
registrationProject,
|
|
468
|
+
template: ""
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// ../kos-codegen-core/src/lib/generators/update-model-index.ts
|
|
473
|
+
import * as ts from "typescript";
|
|
474
|
+
function updateModelIndex(codegenFs, indexPath, modelPath) {
|
|
475
|
+
const logger = getCodegenLogger();
|
|
476
|
+
if (!indexPath)
|
|
477
|
+
return;
|
|
478
|
+
const content = codegenFs.read(indexPath);
|
|
479
|
+
if (content === null) {
|
|
480
|
+
logger.warn(`Index file not found: ${indexPath}`);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
logger.info(`Updating ${indexPath} \u2014 adding export for ${modelPath}`);
|
|
484
|
+
const sourceFile = ts.createSourceFile(
|
|
485
|
+
indexPath,
|
|
486
|
+
content,
|
|
487
|
+
ts.ScriptTarget.Latest,
|
|
488
|
+
true
|
|
489
|
+
);
|
|
490
|
+
const exportDeclaration = ts.factory.createExportDeclaration(
|
|
491
|
+
void 0,
|
|
492
|
+
false,
|
|
493
|
+
void 0,
|
|
494
|
+
ts.factory.createStringLiteral(`./${modelPath}`)
|
|
495
|
+
);
|
|
496
|
+
const updatedSourceFile = ts.factory.updateSourceFile(sourceFile, [
|
|
497
|
+
...sourceFile.statements,
|
|
498
|
+
exportDeclaration
|
|
499
|
+
]);
|
|
500
|
+
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
501
|
+
const newContents = printer.printFile(updatedSourceFile);
|
|
502
|
+
codegenFs.write(indexPath, newContents);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// ../kos-codegen-core/src/lib/generators/generate-container-model.ts
|
|
506
|
+
import * as path8 from "path";
|
|
507
|
+
function generateContainerModel(codegenFs, templateDir, options, cwd, projects) {
|
|
508
|
+
const logger = getCodegenLogger();
|
|
509
|
+
const currentProject = getProject(codegenFs, cwd);
|
|
510
|
+
const modelProjectName = options.modelProject || currentProject?.name;
|
|
511
|
+
if (!modelProjectName) {
|
|
512
|
+
throw new Error(
|
|
513
|
+
"No model project found. Please specify a model project with --modelProject."
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
const modelName = options.modelName || getCurrentDirectoryName(cwd);
|
|
517
|
+
if (!modelName) {
|
|
518
|
+
throw new Error(
|
|
519
|
+
"No model name found. Please specify a model name with --name."
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
options.modelName = modelName;
|
|
523
|
+
options.name = `${modelName}-container`;
|
|
524
|
+
const normalized = normalizeOptions(codegenFs, options, projects);
|
|
525
|
+
const projectConfig = findProjectByName(
|
|
526
|
+
codegenFs.root,
|
|
527
|
+
normalized.modelProject,
|
|
528
|
+
projects
|
|
529
|
+
);
|
|
530
|
+
if (!projectConfig) {
|
|
531
|
+
throw new Error(`Model project '${normalized.modelProject}' not found`);
|
|
532
|
+
}
|
|
533
|
+
addKosModelConfiguration({
|
|
534
|
+
codegenFs,
|
|
535
|
+
modelName: normalized.nameDashCase,
|
|
536
|
+
projectName: projectConfig.name,
|
|
537
|
+
projectRoot: projectConfig.root,
|
|
538
|
+
singleton: !!options.singleton,
|
|
539
|
+
container: true
|
|
540
|
+
});
|
|
541
|
+
const kosConfig = getKosProjectConfiguration(
|
|
542
|
+
codegenFs,
|
|
543
|
+
projectConfig.name,
|
|
544
|
+
projects
|
|
545
|
+
);
|
|
546
|
+
const modelLocation = kosConfig?.generator?.defaults?.model?.folder || "";
|
|
547
|
+
const internal = !!kosConfig?.generator?.internal;
|
|
548
|
+
options.modelDirectory = options.modelDirectory || modelLocation;
|
|
549
|
+
const projectRoot = projectConfig.sourceRoot;
|
|
550
|
+
if (projectRoot) {
|
|
551
|
+
logger.info(
|
|
552
|
+
`Generating container model ${normalized.nameDashCase} in ${projectRoot}`
|
|
553
|
+
);
|
|
554
|
+
const modelNameDashCase = normalized.modelNameDashCase || normalized.nameDashCase;
|
|
555
|
+
generateFilesFromTemplates(
|
|
556
|
+
codegenFs,
|
|
557
|
+
path8.join(templateDir, "model"),
|
|
558
|
+
path8.join(projectRoot, options.modelDirectory || "", modelNameDashCase),
|
|
559
|
+
{ ...normalized, internal }
|
|
560
|
+
);
|
|
561
|
+
if (options.dataServices) {
|
|
562
|
+
logger.info(
|
|
563
|
+
`Generating data services for ${modelNameDashCase}`
|
|
564
|
+
);
|
|
565
|
+
generateFilesFromTemplates(
|
|
566
|
+
codegenFs,
|
|
567
|
+
path8.join(templateDir, "services"),
|
|
568
|
+
path8.join(
|
|
569
|
+
projectRoot,
|
|
570
|
+
options.modelDirectory,
|
|
571
|
+
modelNameDashCase,
|
|
572
|
+
"services"
|
|
573
|
+
),
|
|
574
|
+
{ ...normalized, internal }
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
const modelIndex = path8.join(projectRoot, "index.ts");
|
|
578
|
+
const modelPath = normalized.modelDirectory ? `${normalized.modelDirectory}/${modelNameDashCase}` : modelNameDashCase;
|
|
579
|
+
updateModelIndex(codegenFs, modelIndex, modelPath);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// ../kos-codegen-core/src/lib/generators/component/types.ts
|
|
584
|
+
var PLUGIN_TYPES = {
|
|
585
|
+
CUI: "cui",
|
|
586
|
+
UTILITY: "utility",
|
|
587
|
+
TROUBLE_ACTION: "troubleAction",
|
|
588
|
+
SETUP: "setup",
|
|
589
|
+
SETTING: "setting",
|
|
590
|
+
NAV: "nav",
|
|
591
|
+
CONTROL_POUR: "controlPour",
|
|
592
|
+
CUSTOM: "custom"
|
|
593
|
+
};
|
|
594
|
+
var CONTRIBUTION_TYPE_MAP = {
|
|
595
|
+
[PLUGIN_TYPES.SETUP]: "setup",
|
|
596
|
+
[PLUGIN_TYPES.CUI]: "cui",
|
|
597
|
+
[PLUGIN_TYPES.UTILITY]: "utility",
|
|
598
|
+
[PLUGIN_TYPES.SETTING]: "setting",
|
|
599
|
+
[PLUGIN_TYPES.NAV]: "nav",
|
|
600
|
+
[PLUGIN_TYPES.TROUBLE_ACTION]: "trouble-action",
|
|
601
|
+
[PLUGIN_TYPES.CONTROL_POUR]: "control-pour",
|
|
602
|
+
[PLUGIN_TYPES.CUSTOM]: "custom"
|
|
603
|
+
};
|
|
604
|
+
var LOCALIZED_PLUGIN_TYPES = /* @__PURE__ */ new Set([
|
|
605
|
+
PLUGIN_TYPES.CUI,
|
|
606
|
+
PLUGIN_TYPES.UTILITY,
|
|
607
|
+
PLUGIN_TYPES.SETUP,
|
|
608
|
+
PLUGIN_TYPES.SETTING,
|
|
609
|
+
PLUGIN_TYPES.NAV,
|
|
610
|
+
PLUGIN_TYPES.CONTROL_POUR,
|
|
611
|
+
PLUGIN_TYPES.TROUBLE_ACTION,
|
|
612
|
+
PLUGIN_TYPES.CUSTOM
|
|
613
|
+
]);
|
|
614
|
+
|
|
615
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/base.ts
|
|
616
|
+
var BasePluginHandler = class {
|
|
617
|
+
getContributionKey() {
|
|
618
|
+
return this.contributionKey;
|
|
619
|
+
}
|
|
620
|
+
requiresLocalization() {
|
|
621
|
+
return this.requiresI18n;
|
|
622
|
+
}
|
|
623
|
+
getTemplatePath() {
|
|
624
|
+
return this.contributionKey;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Helper to create experience configuration
|
|
628
|
+
*/
|
|
629
|
+
createExperience(options, experienceId) {
|
|
630
|
+
const compPath = this.getComponentPath(options);
|
|
631
|
+
return {
|
|
632
|
+
id: experienceId,
|
|
633
|
+
component: options.namePascalCase,
|
|
634
|
+
location: `./src/${compPath}`
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Helper to get component path
|
|
639
|
+
*/
|
|
640
|
+
getComponentPath(options) {
|
|
641
|
+
return `${options.appDirectory}/${this.contributionKey}/${options.nameDashCase}/${options.nameDashCase}.tsx`;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Helper to create config prefix
|
|
645
|
+
*/
|
|
646
|
+
getConfigPrefix(options) {
|
|
647
|
+
return `${options.appProject}.${options.nameCamelCase}`;
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/control-pour-handler.ts
|
|
652
|
+
var ControlPourPluginHandler = class extends BasePluginHandler {
|
|
653
|
+
pluginType = PLUGIN_TYPES.CONTROL_POUR;
|
|
654
|
+
contributionKey = "control-pour";
|
|
655
|
+
requiresI18n = true;
|
|
656
|
+
createConfiguration(options) {
|
|
657
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
658
|
+
const experienceId = `${configPrefix}.controlPour.experience`;
|
|
659
|
+
const contribution = {
|
|
660
|
+
id: `${configPrefix}.controlPour`,
|
|
661
|
+
title: `${configPrefix}.controlPour.title`,
|
|
662
|
+
namespace: options.appProject,
|
|
663
|
+
experienceId
|
|
664
|
+
};
|
|
665
|
+
const experience = this.createExperience(options, experienceId);
|
|
666
|
+
return {
|
|
667
|
+
contributions: {
|
|
668
|
+
controlPour: [contribution]
|
|
669
|
+
},
|
|
670
|
+
experiences: {
|
|
671
|
+
[experienceId]: experience
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/cui-handler.ts
|
|
678
|
+
var CuiPluginHandler = class extends BasePluginHandler {
|
|
679
|
+
pluginType = PLUGIN_TYPES.CUI;
|
|
680
|
+
contributionKey = "cui";
|
|
681
|
+
requiresI18n = true;
|
|
682
|
+
createConfiguration(options) {
|
|
683
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
684
|
+
const experienceId = `${configPrefix}.cui.experience`;
|
|
685
|
+
const contribution = {
|
|
686
|
+
id: configPrefix,
|
|
687
|
+
title: `${configPrefix}.cui.title`,
|
|
688
|
+
namespace: options.appProject,
|
|
689
|
+
experienceId
|
|
690
|
+
};
|
|
691
|
+
const experience = this.createExperience(options, experienceId);
|
|
692
|
+
return {
|
|
693
|
+
contributions: {
|
|
694
|
+
cui: [contribution]
|
|
695
|
+
},
|
|
696
|
+
experiences: {
|
|
697
|
+
[experienceId]: experience
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/custom-handler.ts
|
|
704
|
+
var CustomPluginHandler = class extends BasePluginHandler {
|
|
705
|
+
pluginType = PLUGIN_TYPES.CUSTOM;
|
|
706
|
+
contributionKey = "custom";
|
|
707
|
+
requiresI18n = true;
|
|
708
|
+
createConfiguration(options) {
|
|
709
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
710
|
+
const experienceId = `${configPrefix}.${options.contributionKey || "custom"}.experience`;
|
|
711
|
+
const userContributionKey = options.contributionKey || "custom";
|
|
712
|
+
const contribution = {
|
|
713
|
+
id: configPrefix,
|
|
714
|
+
title: `${configPrefix}.${userContributionKey}.title`,
|
|
715
|
+
namespace: options.appProject,
|
|
716
|
+
experienceId
|
|
717
|
+
// TODO: Add additional fields as required by the plugin-explorer specification
|
|
718
|
+
// Refer to the plugin-explorer documentation for your specific contribution type
|
|
719
|
+
};
|
|
720
|
+
const experience = this.createExperience(options, experienceId);
|
|
721
|
+
return {
|
|
722
|
+
contributions: {
|
|
723
|
+
[userContributionKey]: [contribution]
|
|
724
|
+
},
|
|
725
|
+
experiences: {
|
|
726
|
+
[experienceId]: experience
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
getTemplatePath() {
|
|
731
|
+
return this.contributionKey || "custom";
|
|
732
|
+
}
|
|
733
|
+
getComponentPath(options) {
|
|
734
|
+
const pathKey = options.contributionKey || "custom";
|
|
735
|
+
return `${options.appDirectory}/${pathKey}/${options.nameDashCase}/${options.nameDashCase}.tsx`;
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/default-handler.ts
|
|
740
|
+
var DefaultComponentHandler = class extends BasePluginHandler {
|
|
741
|
+
pluginType = "component";
|
|
742
|
+
contributionKey = "components";
|
|
743
|
+
requiresI18n = false;
|
|
744
|
+
createConfiguration(options) {
|
|
745
|
+
const compPath = this.getComponentPath(options);
|
|
746
|
+
const viewConfig = {
|
|
747
|
+
id: `${options.appProject}.${options.nameCamelCase}`,
|
|
748
|
+
title: "ddk.ncui.config.title",
|
|
749
|
+
namespace: options.appProject,
|
|
750
|
+
component: options.namePascalCase,
|
|
751
|
+
location: `./src/${compPath}`
|
|
752
|
+
};
|
|
753
|
+
return {
|
|
754
|
+
contributions: {},
|
|
755
|
+
experiences: {},
|
|
756
|
+
views: {
|
|
757
|
+
[this.getTabViewKey()]: [viewConfig]
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
getTabViewKey() {
|
|
762
|
+
return "ddk.ncui.settings.tabView";
|
|
763
|
+
}
|
|
764
|
+
getTemplatePath() {
|
|
765
|
+
return "files";
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/nav-handler.ts
|
|
770
|
+
var NavPluginHandler = class extends BasePluginHandler {
|
|
771
|
+
pluginType = PLUGIN_TYPES.NAV;
|
|
772
|
+
contributionKey = "nav";
|
|
773
|
+
requiresI18n = true;
|
|
774
|
+
createConfiguration(options) {
|
|
775
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
776
|
+
const experienceId = `${configPrefix}.nav.experience`;
|
|
777
|
+
const contribution = {
|
|
778
|
+
id: `${configPrefix}.nav`,
|
|
779
|
+
title: `${configPrefix}.nav.title`,
|
|
780
|
+
namespace: options.appProject,
|
|
781
|
+
navDescriptor: options.nameLowerCase,
|
|
782
|
+
experienceId
|
|
783
|
+
};
|
|
784
|
+
const experience = this.createExperience(options, experienceId);
|
|
785
|
+
return {
|
|
786
|
+
contributions: {
|
|
787
|
+
navViews: [contribution]
|
|
788
|
+
},
|
|
789
|
+
experiences: {
|
|
790
|
+
[experienceId]: experience
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/setting-handler.ts
|
|
797
|
+
var SettingPluginHandler = class extends BasePluginHandler {
|
|
798
|
+
pluginType = PLUGIN_TYPES.SETTING;
|
|
799
|
+
contributionKey = "setting";
|
|
800
|
+
requiresI18n = true;
|
|
801
|
+
createConfiguration(options) {
|
|
802
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
803
|
+
const experienceId = `${configPrefix}.settings.experience`;
|
|
804
|
+
const contribution = {
|
|
805
|
+
id: `${configPrefix}.setting`,
|
|
806
|
+
title: `${configPrefix}.setting.title`,
|
|
807
|
+
namespace: options.appProject,
|
|
808
|
+
settingsGroup: options.group || "general",
|
|
809
|
+
experienceId
|
|
810
|
+
};
|
|
811
|
+
const experience = this.createExperience(options, experienceId);
|
|
812
|
+
return {
|
|
813
|
+
contributions: {
|
|
814
|
+
settings: [contribution]
|
|
815
|
+
},
|
|
816
|
+
experiences: {
|
|
817
|
+
[experienceId]: experience
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/setup-handler.ts
|
|
824
|
+
var SetupPluginHandler = class extends BasePluginHandler {
|
|
825
|
+
pluginType = PLUGIN_TYPES.SETUP;
|
|
826
|
+
contributionKey = "setup";
|
|
827
|
+
requiresI18n = true;
|
|
828
|
+
createConfiguration(options) {
|
|
829
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
830
|
+
const experienceId = `${configPrefix}.setup.experience`;
|
|
831
|
+
const contribution = {
|
|
832
|
+
id: `${configPrefix}.setup`,
|
|
833
|
+
title: `${configPrefix}.setup.title`,
|
|
834
|
+
namespace: options.appProject,
|
|
835
|
+
setupDescriptor: options.nameCamelCase,
|
|
836
|
+
experienceId
|
|
837
|
+
};
|
|
838
|
+
const experience = this.createExperience(options, experienceId);
|
|
839
|
+
return {
|
|
840
|
+
contributions: {
|
|
841
|
+
setupStep: [contribution]
|
|
842
|
+
},
|
|
843
|
+
experiences: {
|
|
844
|
+
[experienceId]: experience
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/trouble-action-handler.ts
|
|
851
|
+
var TroubleActionPluginHandler = class extends BasePluginHandler {
|
|
852
|
+
pluginType = PLUGIN_TYPES.TROUBLE_ACTION;
|
|
853
|
+
contributionKey = "trouble-action";
|
|
854
|
+
requiresI18n = true;
|
|
855
|
+
createConfiguration(options) {
|
|
856
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
857
|
+
const experienceId = `${configPrefix}.troubleAction.experience`;
|
|
858
|
+
const contribution = {
|
|
859
|
+
id: `${configPrefix}.troubleAction`,
|
|
860
|
+
title: `${configPrefix}.troubleAction.title`,
|
|
861
|
+
namespace: options.appProject,
|
|
862
|
+
troubleType: options.nameCamelCase,
|
|
863
|
+
experienceId
|
|
864
|
+
};
|
|
865
|
+
const experience = this.createExperience(options, experienceId);
|
|
866
|
+
return {
|
|
867
|
+
contributions: {
|
|
868
|
+
troubleActions: [contribution]
|
|
869
|
+
},
|
|
870
|
+
experiences: {
|
|
871
|
+
[experienceId]: experience
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/utility-handler.ts
|
|
878
|
+
var UtilityPluginHandler = class extends BasePluginHandler {
|
|
879
|
+
pluginType = PLUGIN_TYPES.UTILITY;
|
|
880
|
+
contributionKey = "utility";
|
|
881
|
+
requiresI18n = true;
|
|
882
|
+
createConfiguration(options) {
|
|
883
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
884
|
+
const experienceId = `${configPrefix}.util.experience`;
|
|
885
|
+
const contribution = {
|
|
886
|
+
id: `${configPrefix}.util`,
|
|
887
|
+
title: `${configPrefix}.utility.title`,
|
|
888
|
+
namespace: options.appProject,
|
|
889
|
+
utilDescriptor: options.nameCamelCase,
|
|
890
|
+
experienceId
|
|
891
|
+
};
|
|
892
|
+
const experience = this.createExperience(options, experienceId);
|
|
893
|
+
return {
|
|
894
|
+
contributions: {
|
|
895
|
+
utilities: [contribution]
|
|
896
|
+
},
|
|
897
|
+
experiences: {
|
|
898
|
+
[experienceId]: experience
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/factory.ts
|
|
905
|
+
var PluginHandlerFactory = class {
|
|
906
|
+
static handlers = /* @__PURE__ */ new Map([
|
|
907
|
+
[PLUGIN_TYPES.CUI, CuiPluginHandler],
|
|
908
|
+
[PLUGIN_TYPES.UTILITY, UtilityPluginHandler],
|
|
909
|
+
[PLUGIN_TYPES.SETTING, SettingPluginHandler],
|
|
910
|
+
[PLUGIN_TYPES.SETUP, SetupPluginHandler],
|
|
911
|
+
[PLUGIN_TYPES.NAV, NavPluginHandler],
|
|
912
|
+
[PLUGIN_TYPES.CONTROL_POUR, ControlPourPluginHandler],
|
|
913
|
+
[PLUGIN_TYPES.TROUBLE_ACTION, TroubleActionPluginHandler],
|
|
914
|
+
[PLUGIN_TYPES.CUSTOM, CustomPluginHandler]
|
|
915
|
+
]);
|
|
916
|
+
static createHandler(pluginType) {
|
|
917
|
+
if (!pluginType) {
|
|
918
|
+
return new DefaultComponentHandler();
|
|
919
|
+
}
|
|
920
|
+
const HandlerClass = this.handlers.get(pluginType);
|
|
921
|
+
if (!HandlerClass) {
|
|
922
|
+
console.warn(
|
|
923
|
+
`No handler found for plugin type: ${pluginType}. Using default handler.`
|
|
924
|
+
);
|
|
925
|
+
return new DefaultComponentHandler();
|
|
926
|
+
}
|
|
927
|
+
return new HandlerClass();
|
|
928
|
+
}
|
|
929
|
+
static isValidPluginType(type) {
|
|
930
|
+
return this.handlers.has(type);
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
// src/lib/utils/action-factory.mjs
|
|
935
|
+
var actionFactory = (action, metadata2) => {
|
|
936
|
+
return () => {
|
|
937
|
+
const _actions = [{ type: action }];
|
|
938
|
+
if (metadata2.invalidateCache) {
|
|
939
|
+
_actions.push({ type: "clearCache" });
|
|
940
|
+
}
|
|
941
|
+
return _actions;
|
|
942
|
+
};
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
// src/lib/utils/nx-context.mjs
|
|
946
|
+
import { existsSync as existsSync4, readFileSync as readFileSync6, readdirSync as readdirSync3, statSync } from "fs";
|
|
947
|
+
import path10 from "path";
|
|
948
|
+
import { fileURLToPath } from "url";
|
|
949
|
+
|
|
950
|
+
// src/lib/utils/cache.mjs
|
|
951
|
+
import fs6 from "fs";
|
|
952
|
+
import path9 from "path";
|
|
953
|
+
var CACHE_PATH = path9.resolve(".nx/cli-cache.json");
|
|
954
|
+
var CACHE_TTL = 600 * 1e3;
|
|
955
|
+
var ARGS = process.argv;
|
|
956
|
+
var DISABLE_CACHE = process.env.DISABLE_CACHE === "true" || process.env.REFRESH === "true";
|
|
957
|
+
var _cache = {};
|
|
958
|
+
var _loaded = false;
|
|
959
|
+
function ensureCacheDir() {
|
|
960
|
+
const dir = path9.dirname(CACHE_PATH);
|
|
961
|
+
if (!fs6.existsSync(dir))
|
|
962
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
963
|
+
}
|
|
964
|
+
function loadCacheFromDisk() {
|
|
965
|
+
if (_loaded)
|
|
966
|
+
return;
|
|
967
|
+
_loaded = true;
|
|
968
|
+
try {
|
|
969
|
+
if (fs6.existsSync(CACHE_PATH)) {
|
|
970
|
+
const data = fs6.readFileSync(CACHE_PATH, "utf-8");
|
|
971
|
+
_cache = JSON.parse(data);
|
|
972
|
+
}
|
|
973
|
+
} catch (err) {
|
|
974
|
+
console.warn("Failed to load CLI cache:", err);
|
|
975
|
+
_cache = {};
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
function saveCacheToDisk() {
|
|
979
|
+
try {
|
|
980
|
+
ensureCacheDir();
|
|
981
|
+
fs6.writeFileSync(CACHE_PATH, JSON.stringify(_cache, null, 2));
|
|
982
|
+
} catch (err) {
|
|
983
|
+
console.warn("Failed to save CLI cache:", err);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function isFresh(entry, ttl = CACHE_TTL) {
|
|
987
|
+
if (!entry || !entry.timestamp)
|
|
988
|
+
return false;
|
|
989
|
+
return Date.now() - entry.timestamp < ttl;
|
|
990
|
+
}
|
|
991
|
+
function getCached(key, ttl = CACHE_TTL) {
|
|
992
|
+
if (DISABLE_CACHE)
|
|
993
|
+
return null;
|
|
994
|
+
loadCacheFromDisk();
|
|
995
|
+
const entry = _cache[key];
|
|
996
|
+
if (isFresh(entry, ttl))
|
|
997
|
+
return entry.data;
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
function setCached(key, data) {
|
|
1001
|
+
loadCacheFromDisk();
|
|
1002
|
+
_cache[key] = {
|
|
1003
|
+
data,
|
|
1004
|
+
timestamp: Date.now()
|
|
1005
|
+
};
|
|
1006
|
+
saveCacheToDisk();
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// src/lib/utils/nx-context.mjs
|
|
1010
|
+
var __dirname2 = path10.dirname(fileURLToPath(import.meta.url));
|
|
1011
|
+
function findKosJsonFiles(dir = process.cwd(), files = []) {
|
|
1012
|
+
try {
|
|
1013
|
+
const entries = readdirSync3(dir);
|
|
1014
|
+
for (const entry of entries) {
|
|
1015
|
+
if (entry === "node_modules" || entry === ".git" || entry === ".nx" || entry === "dist" || entry === "coverage" || entry === ".vscode" || entry === ".idea" || entry.startsWith(".") && entry !== ".kos.json") {
|
|
1016
|
+
continue;
|
|
1017
|
+
}
|
|
1018
|
+
const fullPath = path10.join(dir, entry);
|
|
1019
|
+
try {
|
|
1020
|
+
const stat = statSync(fullPath);
|
|
1021
|
+
if (stat.isFile() && entry === ".kos.json") {
|
|
1022
|
+
files.push(fullPath);
|
|
1023
|
+
} else if (stat.isDirectory()) {
|
|
1024
|
+
if (entry !== "tmp" && entry !== "temp" && entry !== "build") {
|
|
1025
|
+
findKosJsonFiles(fullPath, files);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
} catch (error) {
|
|
1029
|
+
continue;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
} catch (error) {
|
|
1033
|
+
}
|
|
1034
|
+
return files;
|
|
1035
|
+
}
|
|
1036
|
+
async function getAllProjects() {
|
|
1037
|
+
const cached = getCached("allProjects");
|
|
1038
|
+
if (cached)
|
|
1039
|
+
return cached;
|
|
1040
|
+
const projectMap = discoverProjects(process.cwd());
|
|
1041
|
+
const projects = Array.from(projectMap.keys());
|
|
1042
|
+
setCached("allProjects", projects);
|
|
1043
|
+
return projects;
|
|
1044
|
+
}
|
|
1045
|
+
async function getAllKosProjects() {
|
|
1046
|
+
const cached = getCached("allKosProjects");
|
|
1047
|
+
if (cached)
|
|
1048
|
+
return cached;
|
|
1049
|
+
if (process.env.KOS_CLI_QUIET !== "true") {
|
|
1050
|
+
console.warn(`[kos-cli] Discovering KOS projects by scanning .kos.json files...`);
|
|
1051
|
+
}
|
|
1052
|
+
const projectDirs = ["apps", "libs", "packages"];
|
|
1053
|
+
const kosJsonFiles = [];
|
|
1054
|
+
const workspaceRoot = process.cwd();
|
|
1055
|
+
for (const dir of projectDirs) {
|
|
1056
|
+
const dirPath = path10.join(workspaceRoot, dir);
|
|
1057
|
+
if (existsSync4(dirPath)) {
|
|
1058
|
+
findKosJsonFiles(dirPath, kosJsonFiles);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
const rootKosJson = path10.join(workspaceRoot, ".kos.json");
|
|
1062
|
+
if (existsSync4(rootKosJson)) {
|
|
1063
|
+
kosJsonFiles.push(rootKosJson);
|
|
1064
|
+
}
|
|
1065
|
+
if (kosJsonFiles.length === 0) {
|
|
1066
|
+
if (process.env.KOS_CLI_QUIET !== "true") {
|
|
1067
|
+
console.warn(`[kos-cli] No .kos.json files found in common directories, performing full workspace scan...`);
|
|
1068
|
+
}
|
|
1069
|
+
findKosJsonFiles(workspaceRoot, kosJsonFiles);
|
|
1070
|
+
}
|
|
1071
|
+
const kosProjects = [];
|
|
1072
|
+
for (const kosJsonPath of kosJsonFiles) {
|
|
1073
|
+
try {
|
|
1074
|
+
const kosConfig = JSON.parse(readFileSync6(kosJsonPath, "utf-8"));
|
|
1075
|
+
const projectDir = path10.dirname(kosJsonPath);
|
|
1076
|
+
let projectName = null;
|
|
1077
|
+
const projectJsonPath = path10.join(projectDir, "project.json");
|
|
1078
|
+
if (existsSync4(projectJsonPath)) {
|
|
1079
|
+
try {
|
|
1080
|
+
const projectJson = JSON.parse(readFileSync6(projectJsonPath, "utf-8"));
|
|
1081
|
+
projectName = projectJson.name;
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
projectName = path10.basename(projectDir);
|
|
1084
|
+
}
|
|
1085
|
+
} else {
|
|
1086
|
+
projectName = path10.basename(projectDir);
|
|
1087
|
+
}
|
|
1088
|
+
if (kosConfig.type === "root") {
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
kosProjects.push({
|
|
1092
|
+
name: projectName,
|
|
1093
|
+
path: projectDir,
|
|
1094
|
+
kosJsonPath,
|
|
1095
|
+
config: kosConfig,
|
|
1096
|
+
projectType: kosConfig.generator?.projectType
|
|
1097
|
+
});
|
|
1098
|
+
} catch (error) {
|
|
1099
|
+
console.warn(`[kos-cli] Error reading ${kosJsonPath}: ${error.message}`);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
setCached("allKosProjects", kosProjects);
|
|
1103
|
+
return kosProjects;
|
|
1104
|
+
}
|
|
1105
|
+
async function getAllModels() {
|
|
1106
|
+
const cached = getCached("allModels");
|
|
1107
|
+
if (cached)
|
|
1108
|
+
return cached;
|
|
1109
|
+
if (process.env.KOS_CLI_QUIET !== "true") {
|
|
1110
|
+
console.warn(`[kos-cli] Scanning for models in KOS projects...`);
|
|
1111
|
+
}
|
|
1112
|
+
const allKosProjects = await getAllKosProjects();
|
|
1113
|
+
const models = [];
|
|
1114
|
+
for (const kosProject of allKosProjects) {
|
|
1115
|
+
if (kosProject.config.models) {
|
|
1116
|
+
Object.keys(kosProject.config.models).forEach((model) => {
|
|
1117
|
+
models.push({ model, project: kosProject.name });
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
models.sort((a, b) => {
|
|
1122
|
+
if (a.project === b.project) {
|
|
1123
|
+
return a.model.localeCompare(b.model);
|
|
1124
|
+
} else {
|
|
1125
|
+
return a.project.localeCompare(b.project);
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
setCached("allModels", models);
|
|
1129
|
+
return models;
|
|
1130
|
+
}
|
|
1131
|
+
async function getProjectDetails(projectName) {
|
|
1132
|
+
const cacheKey = `projectDetails:${projectName}`;
|
|
1133
|
+
const cached = getCached(cacheKey);
|
|
1134
|
+
if (cached)
|
|
1135
|
+
return cached;
|
|
1136
|
+
const details = findProjectByName(process.cwd(), projectName);
|
|
1137
|
+
if (!details) {
|
|
1138
|
+
throw new Error(`Project "${projectName}" not found in workspace`);
|
|
1139
|
+
}
|
|
1140
|
+
setCached(cacheKey, details);
|
|
1141
|
+
return details;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// src/lib/utils/prompts.mjs
|
|
1145
|
+
var DEFAULT_PROMPTS = [
|
|
1146
|
+
{
|
|
1147
|
+
type: "confirm",
|
|
1148
|
+
name: "interactive",
|
|
1149
|
+
message: "Use interactive mode?",
|
|
1150
|
+
default: false,
|
|
1151
|
+
when: false
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
type: "confirm",
|
|
1155
|
+
name: "dryRun",
|
|
1156
|
+
message: "Dry run the command?",
|
|
1157
|
+
default: false,
|
|
1158
|
+
when: false
|
|
1159
|
+
}
|
|
1160
|
+
];
|
|
1161
|
+
var MODEL_PROMPTS = [
|
|
1162
|
+
{
|
|
1163
|
+
type: "confirm",
|
|
1164
|
+
name: "container",
|
|
1165
|
+
message: "Requires container model?",
|
|
1166
|
+
default: false
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
type: "confirm",
|
|
1170
|
+
name: "parentAware",
|
|
1171
|
+
message: "Aware of parent container?",
|
|
1172
|
+
default: false
|
|
1173
|
+
},
|
|
1174
|
+
{
|
|
1175
|
+
type: "confirm",
|
|
1176
|
+
name: "singleton",
|
|
1177
|
+
message: "Is singleton?",
|
|
1178
|
+
default: false
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
type: "confirm",
|
|
1182
|
+
name: "dataServices",
|
|
1183
|
+
message: "Create data services?",
|
|
1184
|
+
default: true
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
type: "list",
|
|
1188
|
+
name: "futureAware",
|
|
1189
|
+
message: "Include Future-aware capabilities?",
|
|
1190
|
+
choices: [
|
|
1191
|
+
{ name: "No Future support", value: "none" },
|
|
1192
|
+
{ name: "Minimal (external access only)", value: "minimal" },
|
|
1193
|
+
{ name: "Complete (internal + external access)", value: "complete" }
|
|
1194
|
+
],
|
|
1195
|
+
default: "none"
|
|
1196
|
+
}
|
|
1197
|
+
];
|
|
1198
|
+
|
|
1199
|
+
// src/lib/generators/model/container.mjs
|
|
1200
|
+
var metadata = {
|
|
12
1201
|
key: "container",
|
|
13
1202
|
name: "KOS Container Model",
|
|
14
1203
|
namedArguments: {
|
|
@@ -20,59 +1209,54 @@ export const metadata = {
|
|
|
20
1209
|
dataServices: "dataServices",
|
|
21
1210
|
autoRegister: "autoRegister",
|
|
22
1211
|
dryRun: "dryRun",
|
|
23
|
-
interactive: "interactive"
|
|
24
|
-
}
|
|
1212
|
+
interactive: "interactive"
|
|
1213
|
+
}
|
|
25
1214
|
};
|
|
26
|
-
|
|
27
|
-
export default async function (plop) {
|
|
1215
|
+
async function container_default(plop) {
|
|
28
1216
|
const allProjects = await getAllProjects();
|
|
29
|
-
|
|
30
|
-
// Check if we're in interactive mode by looking at process args
|
|
31
|
-
const isInteractive = process.argv.includes('-i') || process.argv.includes('--interactive');
|
|
32
|
-
|
|
33
|
-
// For interactive mode, use lazy loading. For non-interactive, load immediately.
|
|
1217
|
+
const isInteractive = process.argv.includes("-i") || process.argv.includes("--interactive");
|
|
34
1218
|
let modelChoices;
|
|
35
1219
|
if (isInteractive) {
|
|
36
1220
|
modelChoices = async () => {
|
|
37
1221
|
const allModels = await getAllModels();
|
|
38
1222
|
return allModels.map((m) => ({
|
|
39
1223
|
name: `${m.model} (${m.project})`,
|
|
40
|
-
value: m.model
|
|
1224
|
+
value: m.model
|
|
41
1225
|
}));
|
|
42
1226
|
};
|
|
43
1227
|
} else {
|
|
44
1228
|
const allModels = await getAllModels();
|
|
45
1229
|
modelChoices = allModels.map((m) => ({
|
|
46
1230
|
name: `${m.model} (${m.project})`,
|
|
47
|
-
value: m.model
|
|
1231
|
+
value: m.model
|
|
48
1232
|
}));
|
|
49
1233
|
}
|
|
50
|
-
|
|
51
|
-
|
|
1234
|
+
plop.setActionType("createContainer", async function(answers) {
|
|
1235
|
+
const cwd = process.cwd();
|
|
1236
|
+
const codegenFs = new TrackingFileSystem(new DirectFileSystem(cwd));
|
|
52
1237
|
const allModels = await getAllModels();
|
|
53
1238
|
const modelProject = allModels.find(
|
|
54
1239
|
(m) => m.model === answers.modelName
|
|
55
1240
|
)?.project;
|
|
56
1241
|
const projectDetails = await getProjectDetails(modelProject);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
1242
|
+
generateContainerModel(
|
|
1243
|
+
codegenFs,
|
|
1244
|
+
getTemplateDir("kos-container-model"),
|
|
1245
|
+
{
|
|
1246
|
+
name: answers.modelName,
|
|
1247
|
+
modelName: answers.modelName,
|
|
1248
|
+
modelProject: projectDetails.name,
|
|
1249
|
+
modelDirectory: "",
|
|
1250
|
+
skipRegistration: true,
|
|
1251
|
+
dataServices: !!answers.dataServices,
|
|
1252
|
+
singleton: !!answers.singleton,
|
|
1253
|
+
autoRegister: !!answers.autoRegister
|
|
1254
|
+
},
|
|
1255
|
+
cwd
|
|
1256
|
+
);
|
|
1257
|
+
await formatFiles(codegenFs.root, codegenFs.writtenPaths);
|
|
73
1258
|
return `Container model created for ${answers.modelName}`;
|
|
74
1259
|
});
|
|
75
|
-
|
|
76
1260
|
plop.setGenerator("container", {
|
|
77
1261
|
description: "Create a new KOS Container Model",
|
|
78
1262
|
prompts: [
|
|
@@ -81,16 +1265,21 @@ export default async function (plop) {
|
|
|
81
1265
|
type: "list",
|
|
82
1266
|
name: "modelName",
|
|
83
1267
|
message: "Which model to use?",
|
|
84
|
-
choices: modelChoices
|
|
1268
|
+
choices: modelChoices
|
|
85
1269
|
},
|
|
86
1270
|
{
|
|
87
1271
|
type: "list",
|
|
88
1272
|
name: "registrationProject",
|
|
89
1273
|
message: "Which project should the model be registered in?",
|
|
90
|
-
choices: allProjects
|
|
1274
|
+
choices: allProjects
|
|
91
1275
|
},
|
|
92
|
-
...MODEL_PROMPTS
|
|
1276
|
+
...MODEL_PROMPTS
|
|
93
1277
|
],
|
|
94
|
-
actions: actionFactory("createContainer", metadata)
|
|
1278
|
+
actions: actionFactory("createContainer", metadata)
|
|
95
1279
|
});
|
|
96
1280
|
}
|
|
1281
|
+
export {
|
|
1282
|
+
container_default as default,
|
|
1283
|
+
metadata
|
|
1284
|
+
};
|
|
1285
|
+
//# sourceMappingURL=container.mjs.map
|