@kosdev-code/kos-ui-cli 2.1.39 → 3.0.1
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,8 +1,1071 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
|
|
231
|
+
// ../kos-codegen-core/src/lib/format-files.ts
|
|
232
|
+
import * as fs4 from "fs";
|
|
233
|
+
import * as path4 from "path";
|
|
234
|
+
import prettier from "prettier";
|
|
235
|
+
var FORMATTABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
236
|
+
".ts",
|
|
237
|
+
".tsx",
|
|
238
|
+
".js",
|
|
239
|
+
".jsx",
|
|
240
|
+
".json",
|
|
241
|
+
".css",
|
|
242
|
+
".scss",
|
|
243
|
+
".md",
|
|
244
|
+
".yaml",
|
|
245
|
+
".yml",
|
|
246
|
+
".html"
|
|
247
|
+
]);
|
|
248
|
+
async function formatFiles(workspaceRoot, filePaths) {
|
|
249
|
+
const logger = getCodegenLogger();
|
|
250
|
+
for (const filePath of filePaths) {
|
|
251
|
+
const ext = path4.extname(filePath);
|
|
252
|
+
if (!FORMATTABLE_EXTENSIONS.has(ext)) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
const content = fs4.readFileSync(filePath, "utf-8");
|
|
257
|
+
const options = await prettier.resolveConfig(filePath, {
|
|
258
|
+
editorconfig: true
|
|
259
|
+
});
|
|
260
|
+
const formatted = await prettier.format(content, {
|
|
261
|
+
...options,
|
|
262
|
+
filepath: filePath
|
|
263
|
+
});
|
|
264
|
+
fs4.writeFileSync(filePath, formatted, "utf-8");
|
|
265
|
+
logger.debug(`Formatted ${path4.relative(workspaceRoot, filePath)}`);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
logger.warn(`Failed to format ${filePath}: ${err}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ../kos-codegen-core/src/lib/name-utils.ts
|
|
273
|
+
function dashCase(input) {
|
|
274
|
+
return input.replace(/\s+/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
275
|
+
}
|
|
276
|
+
function camelCase(input) {
|
|
277
|
+
if (input.length === 0)
|
|
278
|
+
return "";
|
|
279
|
+
const words = input.split(/-|\s+/);
|
|
280
|
+
if (words.length > 0 && words[0].length > 0) {
|
|
281
|
+
words[0] = words[0].charAt(0).toLowerCase() + words[0].slice(1);
|
|
282
|
+
}
|
|
283
|
+
for (let i = 1; i < words.length; i++) {
|
|
284
|
+
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
|
|
285
|
+
}
|
|
286
|
+
return words.join("");
|
|
287
|
+
}
|
|
288
|
+
function pascalCase(input) {
|
|
289
|
+
if (input.length === 0)
|
|
290
|
+
return "";
|
|
291
|
+
const cc = camelCase(input);
|
|
292
|
+
return cc[0].toUpperCase() + cc.slice(1);
|
|
293
|
+
}
|
|
294
|
+
function properCase(input) {
|
|
295
|
+
const words = input.toLowerCase().replaceAll("-", " ").split(" ").filter(Boolean);
|
|
296
|
+
for (let i = 0; i < words.length; i++) {
|
|
297
|
+
words[i] = words[i][0].toUpperCase() + words[i].slice(1);
|
|
298
|
+
}
|
|
299
|
+
return words.join("");
|
|
300
|
+
}
|
|
301
|
+
function constantCase(input) {
|
|
302
|
+
if (input.length === 0)
|
|
303
|
+
return "";
|
|
304
|
+
return input.toUpperCase().split(/[\s-]+/).filter(Boolean).join("_");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ../kos-codegen-core/src/lib/normalize-values.ts
|
|
308
|
+
var normalizeValue = (optionsName, value) => ({
|
|
309
|
+
[`${camelCase(optionsName)}CamelCase`]: camelCase(value),
|
|
310
|
+
[`${camelCase(optionsName)}ConstantCase`]: constantCase(value),
|
|
311
|
+
[`${camelCase(optionsName)}DashCase`]: dashCase(value),
|
|
312
|
+
[`${camelCase(optionsName)}PascalCase`]: pascalCase(value),
|
|
313
|
+
[`${camelCase(optionsName)}ProperCase`]: properCase(value),
|
|
314
|
+
[`${camelCase(optionsName)}LowerCase`]: value.toLowerCase(),
|
|
315
|
+
[`${optionsName}`]: value
|
|
316
|
+
});
|
|
317
|
+
var normalizeAllValues = (options) => {
|
|
318
|
+
let normalizedValues = {};
|
|
319
|
+
for (const key in options) {
|
|
320
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
321
|
+
const element = options[key];
|
|
322
|
+
const newOptions = typeof element !== "string" || element === "" ? { [key]: element } : normalizeValue(key, element);
|
|
323
|
+
normalizedValues = {
|
|
324
|
+
...normalizedValues,
|
|
325
|
+
...newOptions
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return normalizedValues;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// ../kos-codegen-core/src/lib/kos-config.ts
|
|
333
|
+
import * as path5 from "path";
|
|
334
|
+
function getCurrentDirectoryName(cwd) {
|
|
335
|
+
return cwd.split("/").pop();
|
|
336
|
+
}
|
|
337
|
+
function getProject(codegenFs, cwd) {
|
|
338
|
+
return findProjectForPath(codegenFs.root, cwd);
|
|
339
|
+
}
|
|
340
|
+
function getKosProjectConfiguration(codegenFs, projectName, projects) {
|
|
341
|
+
const project = findProjectByName(codegenFs.root, projectName, projects);
|
|
342
|
+
if (!project)
|
|
343
|
+
return void 0;
|
|
344
|
+
const configPath = path5.join(project.root, ".kos.json");
|
|
345
|
+
if (!codegenFs.exists(configPath)) {
|
|
346
|
+
const defaultConfig = {
|
|
347
|
+
name: `${dashCase(projectName)}-model`,
|
|
348
|
+
type: "kos.model",
|
|
349
|
+
version: "0.1.0",
|
|
350
|
+
models: {},
|
|
351
|
+
generator: { defaults: { model: { folder: "" } } }
|
|
352
|
+
};
|
|
353
|
+
codegenFs.write(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
354
|
+
}
|
|
355
|
+
const content = codegenFs.read(configPath);
|
|
356
|
+
return content ? JSON.parse(content) : void 0;
|
|
357
|
+
}
|
|
358
|
+
function getKosModelConfiguration(codegenFs, projectName, modelName, projects) {
|
|
359
|
+
const kosConfig = getKosProjectConfiguration(
|
|
360
|
+
codegenFs,
|
|
361
|
+
projectName,
|
|
362
|
+
projects
|
|
363
|
+
);
|
|
364
|
+
return kosConfig?.models?.[modelName];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ../kos-codegen-core/src/lib/template-resolver.ts
|
|
368
|
+
import * as path6 from "path";
|
|
369
|
+
import * as fs5 from "fs";
|
|
370
|
+
function findPackageRoot() {
|
|
371
|
+
if (process.env.KOS_TEMPLATE_BASE_DIR) {
|
|
372
|
+
return process.env.KOS_TEMPLATE_BASE_DIR;
|
|
373
|
+
}
|
|
374
|
+
let dir = __dirname;
|
|
375
|
+
while (dir !== path6.dirname(dir)) {
|
|
376
|
+
const pkgPath = path6.join(dir, "package.json");
|
|
377
|
+
if (fs5.existsSync(pkgPath)) {
|
|
378
|
+
try {
|
|
379
|
+
const pkg = JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
380
|
+
if (pkg.name === "@kosdev-code/kos-codegen-core") {
|
|
381
|
+
return dir;
|
|
382
|
+
}
|
|
383
|
+
} catch {
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
dir = path6.dirname(dir);
|
|
387
|
+
}
|
|
388
|
+
return path6.resolve(__dirname, "..", "..");
|
|
389
|
+
}
|
|
390
|
+
function getTemplateDir(generatorName) {
|
|
391
|
+
return path6.join(findPackageRoot(), "templates", generatorName);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// ../kos-codegen-core/src/lib/generators/normalize-options.ts
|
|
395
|
+
import * as path7 from "path";
|
|
396
|
+
function normalizeOptions(codegenFs, options, projects) {
|
|
397
|
+
const toNormalize = {
|
|
398
|
+
name: options.name
|
|
399
|
+
};
|
|
400
|
+
if (options.modelName) {
|
|
401
|
+
toNormalize.modelName = options.modelName;
|
|
402
|
+
}
|
|
403
|
+
if (options.companionModel) {
|
|
404
|
+
toNormalize.companionModel = options.companionModel;
|
|
405
|
+
}
|
|
406
|
+
const normalizedValues = normalizeAllValues(toNormalize);
|
|
407
|
+
const modelProject = options.modelProject;
|
|
408
|
+
const registrationProject = options.registrationProject || "";
|
|
409
|
+
const useModelProject = modelProject !== "__NONE__";
|
|
410
|
+
let importPath = "";
|
|
411
|
+
if (useModelProject) {
|
|
412
|
+
const modelProjectConfig = findProjectByName(
|
|
413
|
+
codegenFs.root,
|
|
414
|
+
modelProject,
|
|
415
|
+
projects
|
|
416
|
+
);
|
|
417
|
+
if (modelProjectConfig) {
|
|
418
|
+
const pkgJsonPath = path7.join(modelProjectConfig.root, "package.json");
|
|
419
|
+
try {
|
|
420
|
+
const pkgJson = readJson(codegenFs, pkgJsonPath);
|
|
421
|
+
importPath = pkgJson.name || "";
|
|
422
|
+
} catch {
|
|
423
|
+
importPath = "";
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const booleanDefaults = {
|
|
428
|
+
companion: false,
|
|
429
|
+
skipRegistration: false
|
|
430
|
+
};
|
|
431
|
+
return {
|
|
432
|
+
...booleanDefaults,
|
|
433
|
+
...options,
|
|
434
|
+
...normalizedValues,
|
|
435
|
+
modelProject,
|
|
436
|
+
importPath,
|
|
437
|
+
registrationProject,
|
|
438
|
+
template: ""
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// ../kos-codegen-core/src/lib/generators/barrel-utils.ts
|
|
443
|
+
function appendBarrelExport(codegenFs, indexPath, exportPath) {
|
|
444
|
+
const exportLine = `export * from '${exportPath}'`;
|
|
445
|
+
const content = codegenFs.read(indexPath) ?? "";
|
|
446
|
+
const lines = content.split("\n");
|
|
447
|
+
if (lines.some((line) => line.includes(exportLine))) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
lines.push(exportLine);
|
|
451
|
+
codegenFs.write(indexPath, lines.join("\n"));
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// ../kos-codegen-core/src/lib/generators/update-model-index.ts
|
|
455
|
+
import * as ts from "typescript";
|
|
456
|
+
|
|
457
|
+
// ../kos-codegen-core/src/lib/generators/generate-hook.ts
|
|
458
|
+
import * as path8 from "path";
|
|
459
|
+
function generateHook(codegenFs, templateDir, options, cwd, projects) {
|
|
460
|
+
const logger = getCodegenLogger();
|
|
461
|
+
if (!options.appProject) {
|
|
462
|
+
throw new Error("No app project specified");
|
|
463
|
+
}
|
|
464
|
+
const currentProject = getProject(codegenFs, cwd);
|
|
465
|
+
const modelProjectName = options.modelProject || currentProject?.name;
|
|
466
|
+
if (!modelProjectName) {
|
|
467
|
+
throw new Error(
|
|
468
|
+
"No model project found. Please specify a model project with --modelProject."
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
const modelName = options.name || getCurrentDirectoryName(cwd);
|
|
472
|
+
if (!modelName) {
|
|
473
|
+
throw new Error(
|
|
474
|
+
"No model name found. Please specify a model name with --name."
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
const kosModelConfig = getKosModelConfiguration(
|
|
478
|
+
codegenFs,
|
|
479
|
+
modelProjectName,
|
|
480
|
+
modelName,
|
|
481
|
+
projects
|
|
482
|
+
);
|
|
483
|
+
options.singleton = kosModelConfig ? !!kosModelConfig.singleton : false;
|
|
484
|
+
options.name = modelName;
|
|
485
|
+
options.modelProject = modelProjectName;
|
|
486
|
+
const normalized = normalizeOptions(codegenFs, options, projects);
|
|
487
|
+
const appProject = findProjectByName(
|
|
488
|
+
codegenFs.root,
|
|
489
|
+
normalized.appProject,
|
|
490
|
+
projects
|
|
491
|
+
);
|
|
492
|
+
if (!appProject) {
|
|
493
|
+
throw new Error(`App project '${normalized.appProject}' not found`);
|
|
494
|
+
}
|
|
495
|
+
const kosConfig = getKosProjectConfiguration(
|
|
496
|
+
codegenFs,
|
|
497
|
+
appProject.name,
|
|
498
|
+
projects
|
|
499
|
+
);
|
|
500
|
+
const componentLocation = kosConfig?.generator?.defaults?.components?.folder || "";
|
|
501
|
+
options.appDirectory = options.appDirectory || componentLocation;
|
|
502
|
+
const projectRoot = appProject.sourceRoot;
|
|
503
|
+
if (projectRoot) {
|
|
504
|
+
generateFilesFromTemplates(
|
|
505
|
+
codegenFs,
|
|
506
|
+
templateDir,
|
|
507
|
+
path8.join(projectRoot, options.appDirectory, "hooks", normalized.nameDashCase),
|
|
508
|
+
normalized
|
|
509
|
+
);
|
|
510
|
+
appendBarrelExport(
|
|
511
|
+
codegenFs,
|
|
512
|
+
path8.join(projectRoot, options.appDirectory, "hooks", "index.ts"),
|
|
513
|
+
`./${normalized.nameDashCase}`
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// ../kos-codegen-core/src/lib/generators/component/types.ts
|
|
519
|
+
var PLUGIN_TYPES = {
|
|
520
|
+
CUI: "cui",
|
|
521
|
+
UTILITY: "utility",
|
|
522
|
+
TROUBLE_ACTION: "troubleAction",
|
|
523
|
+
SETUP: "setup",
|
|
524
|
+
SETTING: "setting",
|
|
525
|
+
NAV: "nav",
|
|
526
|
+
CONTROL_POUR: "controlPour",
|
|
527
|
+
CUSTOM: "custom"
|
|
528
|
+
};
|
|
529
|
+
var CONTRIBUTION_TYPE_MAP = {
|
|
530
|
+
[PLUGIN_TYPES.SETUP]: "setup",
|
|
531
|
+
[PLUGIN_TYPES.CUI]: "cui",
|
|
532
|
+
[PLUGIN_TYPES.UTILITY]: "utility",
|
|
533
|
+
[PLUGIN_TYPES.SETTING]: "setting",
|
|
534
|
+
[PLUGIN_TYPES.NAV]: "nav",
|
|
535
|
+
[PLUGIN_TYPES.TROUBLE_ACTION]: "trouble-action",
|
|
536
|
+
[PLUGIN_TYPES.CONTROL_POUR]: "control-pour",
|
|
537
|
+
[PLUGIN_TYPES.CUSTOM]: "custom"
|
|
538
|
+
};
|
|
539
|
+
var LOCALIZED_PLUGIN_TYPES = /* @__PURE__ */ new Set([
|
|
540
|
+
PLUGIN_TYPES.CUI,
|
|
541
|
+
PLUGIN_TYPES.UTILITY,
|
|
542
|
+
PLUGIN_TYPES.SETUP,
|
|
543
|
+
PLUGIN_TYPES.SETTING,
|
|
544
|
+
PLUGIN_TYPES.NAV,
|
|
545
|
+
PLUGIN_TYPES.CONTROL_POUR,
|
|
546
|
+
PLUGIN_TYPES.TROUBLE_ACTION,
|
|
547
|
+
PLUGIN_TYPES.CUSTOM
|
|
548
|
+
]);
|
|
549
|
+
|
|
550
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/base.ts
|
|
551
|
+
var BasePluginHandler = class {
|
|
552
|
+
getContributionKey() {
|
|
553
|
+
return this.contributionKey;
|
|
554
|
+
}
|
|
555
|
+
requiresLocalization() {
|
|
556
|
+
return this.requiresI18n;
|
|
557
|
+
}
|
|
558
|
+
getTemplatePath() {
|
|
559
|
+
return this.contributionKey;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Helper to create experience configuration
|
|
563
|
+
*/
|
|
564
|
+
createExperience(options, experienceId) {
|
|
565
|
+
const compPath = this.getComponentPath(options);
|
|
566
|
+
return {
|
|
567
|
+
id: experienceId,
|
|
568
|
+
component: options.namePascalCase,
|
|
569
|
+
location: `./src/${compPath}`
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Helper to get component path
|
|
574
|
+
*/
|
|
575
|
+
getComponentPath(options) {
|
|
576
|
+
return `${options.appDirectory}/${this.contributionKey}/${options.nameDashCase}/${options.nameDashCase}.tsx`;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Helper to create config prefix
|
|
580
|
+
*/
|
|
581
|
+
getConfigPrefix(options) {
|
|
582
|
+
return `${options.appProject}.${options.nameCamelCase}`;
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/control-pour-handler.ts
|
|
587
|
+
var ControlPourPluginHandler = class extends BasePluginHandler {
|
|
588
|
+
pluginType = PLUGIN_TYPES.CONTROL_POUR;
|
|
589
|
+
contributionKey = "control-pour";
|
|
590
|
+
requiresI18n = true;
|
|
591
|
+
createConfiguration(options) {
|
|
592
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
593
|
+
const experienceId = `${configPrefix}.controlPour.experience`;
|
|
594
|
+
const contribution = {
|
|
595
|
+
id: `${configPrefix}.controlPour`,
|
|
596
|
+
title: `${configPrefix}.controlPour.title`,
|
|
597
|
+
namespace: options.appProject,
|
|
598
|
+
experienceId
|
|
599
|
+
};
|
|
600
|
+
const experience = this.createExperience(options, experienceId);
|
|
601
|
+
return {
|
|
602
|
+
contributions: {
|
|
603
|
+
controlPour: [contribution]
|
|
604
|
+
},
|
|
605
|
+
experiences: {
|
|
606
|
+
[experienceId]: experience
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/cui-handler.ts
|
|
613
|
+
var CuiPluginHandler = class extends BasePluginHandler {
|
|
614
|
+
pluginType = PLUGIN_TYPES.CUI;
|
|
615
|
+
contributionKey = "cui";
|
|
616
|
+
requiresI18n = true;
|
|
617
|
+
createConfiguration(options) {
|
|
618
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
619
|
+
const experienceId = `${configPrefix}.cui.experience`;
|
|
620
|
+
const contribution = {
|
|
621
|
+
id: configPrefix,
|
|
622
|
+
title: `${configPrefix}.cui.title`,
|
|
623
|
+
namespace: options.appProject,
|
|
624
|
+
experienceId
|
|
625
|
+
};
|
|
626
|
+
const experience = this.createExperience(options, experienceId);
|
|
627
|
+
return {
|
|
628
|
+
contributions: {
|
|
629
|
+
cui: [contribution]
|
|
630
|
+
},
|
|
631
|
+
experiences: {
|
|
632
|
+
[experienceId]: experience
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/custom-handler.ts
|
|
639
|
+
var CustomPluginHandler = class extends BasePluginHandler {
|
|
640
|
+
pluginType = PLUGIN_TYPES.CUSTOM;
|
|
641
|
+
contributionKey = "custom";
|
|
642
|
+
requiresI18n = true;
|
|
643
|
+
createConfiguration(options) {
|
|
644
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
645
|
+
const experienceId = `${configPrefix}.${options.contributionKey || "custom"}.experience`;
|
|
646
|
+
const userContributionKey = options.contributionKey || "custom";
|
|
647
|
+
const contribution = {
|
|
648
|
+
id: configPrefix,
|
|
649
|
+
title: `${configPrefix}.${userContributionKey}.title`,
|
|
650
|
+
namespace: options.appProject,
|
|
651
|
+
experienceId
|
|
652
|
+
// TODO: Add additional fields as required by the plugin-explorer specification
|
|
653
|
+
// Refer to the plugin-explorer documentation for your specific contribution type
|
|
654
|
+
};
|
|
655
|
+
const experience = this.createExperience(options, experienceId);
|
|
656
|
+
return {
|
|
657
|
+
contributions: {
|
|
658
|
+
[userContributionKey]: [contribution]
|
|
659
|
+
},
|
|
660
|
+
experiences: {
|
|
661
|
+
[experienceId]: experience
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
getTemplatePath() {
|
|
666
|
+
return this.contributionKey || "custom";
|
|
667
|
+
}
|
|
668
|
+
getComponentPath(options) {
|
|
669
|
+
const pathKey = options.contributionKey || "custom";
|
|
670
|
+
return `${options.appDirectory}/${pathKey}/${options.nameDashCase}/${options.nameDashCase}.tsx`;
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/default-handler.ts
|
|
675
|
+
var DefaultComponentHandler = class extends BasePluginHandler {
|
|
676
|
+
pluginType = "component";
|
|
677
|
+
contributionKey = "components";
|
|
678
|
+
requiresI18n = false;
|
|
679
|
+
createConfiguration(options) {
|
|
680
|
+
const compPath = this.getComponentPath(options);
|
|
681
|
+
const viewConfig = {
|
|
682
|
+
id: `${options.appProject}.${options.nameCamelCase}`,
|
|
683
|
+
title: "ddk.ncui.config.title",
|
|
684
|
+
namespace: options.appProject,
|
|
685
|
+
component: options.namePascalCase,
|
|
686
|
+
location: `./src/${compPath}`
|
|
687
|
+
};
|
|
688
|
+
return {
|
|
689
|
+
contributions: {},
|
|
690
|
+
experiences: {},
|
|
691
|
+
views: {
|
|
692
|
+
[this.getTabViewKey()]: [viewConfig]
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
getTabViewKey() {
|
|
697
|
+
return "ddk.ncui.settings.tabView";
|
|
698
|
+
}
|
|
699
|
+
getTemplatePath() {
|
|
700
|
+
return "files";
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/nav-handler.ts
|
|
705
|
+
var NavPluginHandler = class extends BasePluginHandler {
|
|
706
|
+
pluginType = PLUGIN_TYPES.NAV;
|
|
707
|
+
contributionKey = "nav";
|
|
708
|
+
requiresI18n = true;
|
|
709
|
+
createConfiguration(options) {
|
|
710
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
711
|
+
const experienceId = `${configPrefix}.nav.experience`;
|
|
712
|
+
const contribution = {
|
|
713
|
+
id: `${configPrefix}.nav`,
|
|
714
|
+
title: `${configPrefix}.nav.title`,
|
|
715
|
+
namespace: options.appProject,
|
|
716
|
+
navDescriptor: options.nameLowerCase,
|
|
717
|
+
experienceId
|
|
718
|
+
};
|
|
719
|
+
const experience = this.createExperience(options, experienceId);
|
|
720
|
+
return {
|
|
721
|
+
contributions: {
|
|
722
|
+
navViews: [contribution]
|
|
723
|
+
},
|
|
724
|
+
experiences: {
|
|
725
|
+
[experienceId]: experience
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/setting-handler.ts
|
|
732
|
+
var SettingPluginHandler = class extends BasePluginHandler {
|
|
733
|
+
pluginType = PLUGIN_TYPES.SETTING;
|
|
734
|
+
contributionKey = "setting";
|
|
735
|
+
requiresI18n = true;
|
|
736
|
+
createConfiguration(options) {
|
|
737
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
738
|
+
const experienceId = `${configPrefix}.settings.experience`;
|
|
739
|
+
const contribution = {
|
|
740
|
+
id: `${configPrefix}.setting`,
|
|
741
|
+
title: `${configPrefix}.setting.title`,
|
|
742
|
+
namespace: options.appProject,
|
|
743
|
+
settingsGroup: options.group || "general",
|
|
744
|
+
experienceId
|
|
745
|
+
};
|
|
746
|
+
const experience = this.createExperience(options, experienceId);
|
|
747
|
+
return {
|
|
748
|
+
contributions: {
|
|
749
|
+
settings: [contribution]
|
|
750
|
+
},
|
|
751
|
+
experiences: {
|
|
752
|
+
[experienceId]: experience
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/setup-handler.ts
|
|
759
|
+
var SetupPluginHandler = class extends BasePluginHandler {
|
|
760
|
+
pluginType = PLUGIN_TYPES.SETUP;
|
|
761
|
+
contributionKey = "setup";
|
|
762
|
+
requiresI18n = true;
|
|
763
|
+
createConfiguration(options) {
|
|
764
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
765
|
+
const experienceId = `${configPrefix}.setup.experience`;
|
|
766
|
+
const contribution = {
|
|
767
|
+
id: `${configPrefix}.setup`,
|
|
768
|
+
title: `${configPrefix}.setup.title`,
|
|
769
|
+
namespace: options.appProject,
|
|
770
|
+
setupDescriptor: options.nameCamelCase,
|
|
771
|
+
experienceId
|
|
772
|
+
};
|
|
773
|
+
const experience = this.createExperience(options, experienceId);
|
|
774
|
+
return {
|
|
775
|
+
contributions: {
|
|
776
|
+
setupStep: [contribution]
|
|
777
|
+
},
|
|
778
|
+
experiences: {
|
|
779
|
+
[experienceId]: experience
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/trouble-action-handler.ts
|
|
786
|
+
var TroubleActionPluginHandler = class extends BasePluginHandler {
|
|
787
|
+
pluginType = PLUGIN_TYPES.TROUBLE_ACTION;
|
|
788
|
+
contributionKey = "trouble-action";
|
|
789
|
+
requiresI18n = true;
|
|
790
|
+
createConfiguration(options) {
|
|
791
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
792
|
+
const experienceId = `${configPrefix}.troubleAction.experience`;
|
|
793
|
+
const contribution = {
|
|
794
|
+
id: `${configPrefix}.troubleAction`,
|
|
795
|
+
title: `${configPrefix}.troubleAction.title`,
|
|
796
|
+
namespace: options.appProject,
|
|
797
|
+
troubleType: options.nameCamelCase,
|
|
798
|
+
experienceId
|
|
799
|
+
};
|
|
800
|
+
const experience = this.createExperience(options, experienceId);
|
|
801
|
+
return {
|
|
802
|
+
contributions: {
|
|
803
|
+
troubleActions: [contribution]
|
|
804
|
+
},
|
|
805
|
+
experiences: {
|
|
806
|
+
[experienceId]: experience
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/utility-handler.ts
|
|
813
|
+
var UtilityPluginHandler = class extends BasePluginHandler {
|
|
814
|
+
pluginType = PLUGIN_TYPES.UTILITY;
|
|
815
|
+
contributionKey = "utility";
|
|
816
|
+
requiresI18n = true;
|
|
817
|
+
createConfiguration(options) {
|
|
818
|
+
const configPrefix = this.getConfigPrefix(options);
|
|
819
|
+
const experienceId = `${configPrefix}.util.experience`;
|
|
820
|
+
const contribution = {
|
|
821
|
+
id: `${configPrefix}.util`,
|
|
822
|
+
title: `${configPrefix}.utility.title`,
|
|
823
|
+
namespace: options.appProject,
|
|
824
|
+
utilDescriptor: options.nameCamelCase,
|
|
825
|
+
experienceId
|
|
826
|
+
};
|
|
827
|
+
const experience = this.createExperience(options, experienceId);
|
|
828
|
+
return {
|
|
829
|
+
contributions: {
|
|
830
|
+
utilities: [contribution]
|
|
831
|
+
},
|
|
832
|
+
experiences: {
|
|
833
|
+
[experienceId]: experience
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// ../kos-codegen-core/src/lib/generators/component/plugin-handlers/factory.ts
|
|
840
|
+
var PluginHandlerFactory = class {
|
|
841
|
+
static handlers = /* @__PURE__ */ new Map([
|
|
842
|
+
[PLUGIN_TYPES.CUI, CuiPluginHandler],
|
|
843
|
+
[PLUGIN_TYPES.UTILITY, UtilityPluginHandler],
|
|
844
|
+
[PLUGIN_TYPES.SETTING, SettingPluginHandler],
|
|
845
|
+
[PLUGIN_TYPES.SETUP, SetupPluginHandler],
|
|
846
|
+
[PLUGIN_TYPES.NAV, NavPluginHandler],
|
|
847
|
+
[PLUGIN_TYPES.CONTROL_POUR, ControlPourPluginHandler],
|
|
848
|
+
[PLUGIN_TYPES.TROUBLE_ACTION, TroubleActionPluginHandler],
|
|
849
|
+
[PLUGIN_TYPES.CUSTOM, CustomPluginHandler]
|
|
850
|
+
]);
|
|
851
|
+
static createHandler(pluginType) {
|
|
852
|
+
if (!pluginType) {
|
|
853
|
+
return new DefaultComponentHandler();
|
|
854
|
+
}
|
|
855
|
+
const HandlerClass = this.handlers.get(pluginType);
|
|
856
|
+
if (!HandlerClass) {
|
|
857
|
+
console.warn(
|
|
858
|
+
`No handler found for plugin type: ${pluginType}. Using default handler.`
|
|
859
|
+
);
|
|
860
|
+
return new DefaultComponentHandler();
|
|
861
|
+
}
|
|
862
|
+
return new HandlerClass();
|
|
863
|
+
}
|
|
864
|
+
static isValidPluginType(type) {
|
|
865
|
+
return this.handlers.has(type);
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
// src/lib/utils/action-factory.mjs
|
|
870
|
+
var actionFactory = (action, metadata2) => {
|
|
871
|
+
return () => {
|
|
872
|
+
const _actions = [{ type: action }];
|
|
873
|
+
if (metadata2.invalidateCache) {
|
|
874
|
+
_actions.push({ type: "clearCache" });
|
|
875
|
+
}
|
|
876
|
+
return _actions;
|
|
877
|
+
};
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
// src/lib/utils/nx-context.mjs
|
|
881
|
+
import { existsSync as existsSync4, readFileSync as readFileSync6, readdirSync as readdirSync3, statSync } from "fs";
|
|
882
|
+
import path10 from "path";
|
|
883
|
+
import { fileURLToPath } from "url";
|
|
884
|
+
|
|
885
|
+
// src/lib/utils/cache.mjs
|
|
886
|
+
import fs6 from "fs";
|
|
887
|
+
import path9 from "path";
|
|
888
|
+
var CACHE_PATH = path9.resolve(".nx/cli-cache.json");
|
|
889
|
+
var CACHE_TTL = 600 * 1e3;
|
|
890
|
+
var ARGS = process.argv;
|
|
891
|
+
var DISABLE_CACHE = process.env.DISABLE_CACHE === "true" || process.env.REFRESH === "true";
|
|
892
|
+
var _cache = {};
|
|
893
|
+
var _loaded = false;
|
|
894
|
+
function ensureCacheDir() {
|
|
895
|
+
const dir = path9.dirname(CACHE_PATH);
|
|
896
|
+
if (!fs6.existsSync(dir))
|
|
897
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
898
|
+
}
|
|
899
|
+
function loadCacheFromDisk() {
|
|
900
|
+
if (_loaded)
|
|
901
|
+
return;
|
|
902
|
+
_loaded = true;
|
|
903
|
+
try {
|
|
904
|
+
if (fs6.existsSync(CACHE_PATH)) {
|
|
905
|
+
const data = fs6.readFileSync(CACHE_PATH, "utf-8");
|
|
906
|
+
_cache = JSON.parse(data);
|
|
907
|
+
}
|
|
908
|
+
} catch (err) {
|
|
909
|
+
console.warn("Failed to load CLI cache:", err);
|
|
910
|
+
_cache = {};
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function saveCacheToDisk() {
|
|
914
|
+
try {
|
|
915
|
+
ensureCacheDir();
|
|
916
|
+
fs6.writeFileSync(CACHE_PATH, JSON.stringify(_cache, null, 2));
|
|
917
|
+
} catch (err) {
|
|
918
|
+
console.warn("Failed to save CLI cache:", err);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
function isFresh(entry, ttl = CACHE_TTL) {
|
|
922
|
+
if (!entry || !entry.timestamp)
|
|
923
|
+
return false;
|
|
924
|
+
return Date.now() - entry.timestamp < ttl;
|
|
925
|
+
}
|
|
926
|
+
function getCached(key, ttl = CACHE_TTL) {
|
|
927
|
+
if (DISABLE_CACHE)
|
|
928
|
+
return null;
|
|
929
|
+
loadCacheFromDisk();
|
|
930
|
+
const entry = _cache[key];
|
|
931
|
+
if (isFresh(entry, ttl))
|
|
932
|
+
return entry.data;
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
function setCached(key, data) {
|
|
936
|
+
loadCacheFromDisk();
|
|
937
|
+
_cache[key] = {
|
|
938
|
+
data,
|
|
939
|
+
timestamp: Date.now()
|
|
940
|
+
};
|
|
941
|
+
saveCacheToDisk();
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// src/lib/utils/nx-context.mjs
|
|
945
|
+
var __dirname2 = path10.dirname(fileURLToPath(import.meta.url));
|
|
946
|
+
function findKosJsonFiles(dir = process.cwd(), files = []) {
|
|
947
|
+
try {
|
|
948
|
+
const entries = readdirSync3(dir);
|
|
949
|
+
for (const entry of entries) {
|
|
950
|
+
if (entry === "node_modules" || entry === ".git" || entry === ".nx" || entry === "dist" || entry === "coverage" || entry === ".vscode" || entry === ".idea" || entry.startsWith(".") && entry !== ".kos.json") {
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
const fullPath = path10.join(dir, entry);
|
|
954
|
+
try {
|
|
955
|
+
const stat = statSync(fullPath);
|
|
956
|
+
if (stat.isFile() && entry === ".kos.json") {
|
|
957
|
+
files.push(fullPath);
|
|
958
|
+
} else if (stat.isDirectory()) {
|
|
959
|
+
if (entry !== "tmp" && entry !== "temp" && entry !== "build") {
|
|
960
|
+
findKosJsonFiles(fullPath, files);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
} catch (error) {
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
} catch (error) {
|
|
968
|
+
}
|
|
969
|
+
return files;
|
|
970
|
+
}
|
|
971
|
+
async function getAllProjects() {
|
|
972
|
+
const cached = getCached("allProjects");
|
|
973
|
+
if (cached)
|
|
974
|
+
return cached;
|
|
975
|
+
const projectMap = discoverProjects(process.cwd());
|
|
976
|
+
const projects = Array.from(projectMap.keys());
|
|
977
|
+
setCached("allProjects", projects);
|
|
978
|
+
return projects;
|
|
979
|
+
}
|
|
980
|
+
async function getAllKosProjects() {
|
|
981
|
+
const cached = getCached("allKosProjects");
|
|
982
|
+
if (cached)
|
|
983
|
+
return cached;
|
|
984
|
+
if (process.env.KOS_CLI_QUIET !== "true") {
|
|
985
|
+
console.warn(`[kos-cli] Discovering KOS projects by scanning .kos.json files...`);
|
|
986
|
+
}
|
|
987
|
+
const projectDirs = ["apps", "libs", "packages"];
|
|
988
|
+
const kosJsonFiles = [];
|
|
989
|
+
const workspaceRoot = process.cwd();
|
|
990
|
+
for (const dir of projectDirs) {
|
|
991
|
+
const dirPath = path10.join(workspaceRoot, dir);
|
|
992
|
+
if (existsSync4(dirPath)) {
|
|
993
|
+
findKosJsonFiles(dirPath, kosJsonFiles);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
const rootKosJson = path10.join(workspaceRoot, ".kos.json");
|
|
997
|
+
if (existsSync4(rootKosJson)) {
|
|
998
|
+
kosJsonFiles.push(rootKosJson);
|
|
999
|
+
}
|
|
1000
|
+
if (kosJsonFiles.length === 0) {
|
|
1001
|
+
if (process.env.KOS_CLI_QUIET !== "true") {
|
|
1002
|
+
console.warn(`[kos-cli] No .kos.json files found in common directories, performing full workspace scan...`);
|
|
1003
|
+
}
|
|
1004
|
+
findKosJsonFiles(workspaceRoot, kosJsonFiles);
|
|
1005
|
+
}
|
|
1006
|
+
const kosProjects = [];
|
|
1007
|
+
for (const kosJsonPath of kosJsonFiles) {
|
|
1008
|
+
try {
|
|
1009
|
+
const kosConfig = JSON.parse(readFileSync6(kosJsonPath, "utf-8"));
|
|
1010
|
+
const projectDir = path10.dirname(kosJsonPath);
|
|
1011
|
+
let projectName = null;
|
|
1012
|
+
const projectJsonPath = path10.join(projectDir, "project.json");
|
|
1013
|
+
if (existsSync4(projectJsonPath)) {
|
|
1014
|
+
try {
|
|
1015
|
+
const projectJson = JSON.parse(readFileSync6(projectJsonPath, "utf-8"));
|
|
1016
|
+
projectName = projectJson.name;
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
projectName = path10.basename(projectDir);
|
|
1019
|
+
}
|
|
1020
|
+
} else {
|
|
1021
|
+
projectName = path10.basename(projectDir);
|
|
1022
|
+
}
|
|
1023
|
+
if (kosConfig.type === "root") {
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
kosProjects.push({
|
|
1027
|
+
name: projectName,
|
|
1028
|
+
path: projectDir,
|
|
1029
|
+
kosJsonPath,
|
|
1030
|
+
config: kosConfig,
|
|
1031
|
+
projectType: kosConfig.generator?.projectType
|
|
1032
|
+
});
|
|
1033
|
+
} catch (error) {
|
|
1034
|
+
console.warn(`[kos-cli] Error reading ${kosJsonPath}: ${error.message}`);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
setCached("allKosProjects", kosProjects);
|
|
1038
|
+
return kosProjects;
|
|
1039
|
+
}
|
|
1040
|
+
async function getAllModels() {
|
|
1041
|
+
const cached = getCached("allModels");
|
|
1042
|
+
if (cached)
|
|
1043
|
+
return cached;
|
|
1044
|
+
if (process.env.KOS_CLI_QUIET !== "true") {
|
|
1045
|
+
console.warn(`[kos-cli] Scanning for models in KOS projects...`);
|
|
1046
|
+
}
|
|
1047
|
+
const allKosProjects = await getAllKosProjects();
|
|
1048
|
+
const models = [];
|
|
1049
|
+
for (const kosProject of allKosProjects) {
|
|
1050
|
+
if (kosProject.config.models) {
|
|
1051
|
+
Object.keys(kosProject.config.models).forEach((model) => {
|
|
1052
|
+
models.push({ model, project: kosProject.name });
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
models.sort((a, b) => {
|
|
1057
|
+
if (a.project === b.project) {
|
|
1058
|
+
return a.model.localeCompare(b.model);
|
|
1059
|
+
} else {
|
|
1060
|
+
return a.project.localeCompare(b.project);
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
setCached("allModels", models);
|
|
1064
|
+
return models;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/lib/generators/model/hook.mjs
|
|
1068
|
+
var metadata = {
|
|
6
1069
|
key: "hook",
|
|
7
1070
|
name: "KOS Model React Hook",
|
|
8
1071
|
namedArguments: {
|
|
@@ -11,51 +1074,47 @@ export const metadata = {
|
|
|
11
1074
|
project: "componentProject"
|
|
12
1075
|
}
|
|
13
1076
|
};
|
|
14
|
-
|
|
15
|
-
export default async function (plop) {
|
|
1077
|
+
async function hook_default(plop) {
|
|
16
1078
|
const allProjects = await getAllProjects();
|
|
17
|
-
|
|
18
|
-
// Check if we're in interactive mode by looking at process args
|
|
19
|
-
const isInteractive = process.argv.includes('-i') || process.argv.includes('--interactive');
|
|
20
|
-
|
|
21
|
-
// For interactive mode, use lazy loading. For non-interactive, load immediately.
|
|
1079
|
+
const isInteractive = process.argv.includes("-i") || process.argv.includes("--interactive");
|
|
22
1080
|
let modelChoices;
|
|
23
1081
|
if (isInteractive) {
|
|
24
1082
|
modelChoices = async () => {
|
|
25
1083
|
const allModels = await getAllModels();
|
|
26
1084
|
return allModels.map((m) => ({
|
|
27
1085
|
name: `${m.model} (${m.project})`,
|
|
28
|
-
value: m.model
|
|
1086
|
+
value: m.model
|
|
29
1087
|
}));
|
|
30
1088
|
};
|
|
31
1089
|
} else {
|
|
32
1090
|
const allModels = await getAllModels();
|
|
33
1091
|
modelChoices = allModels.map((m) => ({
|
|
34
1092
|
name: `${m.model} (${m.project})`,
|
|
35
|
-
value: m.model
|
|
1093
|
+
value: m.model
|
|
36
1094
|
}));
|
|
37
1095
|
}
|
|
38
|
-
|
|
39
|
-
|
|
1096
|
+
plop.setActionType("createHook", async function(answers) {
|
|
1097
|
+
const cwd = process.cwd();
|
|
1098
|
+
const codegenFs = new TrackingFileSystem(new DirectFileSystem(cwd));
|
|
40
1099
|
const allModels = await getAllModels();
|
|
41
1100
|
const modelProject = allModels.find(
|
|
42
1101
|
(m) => m.model === answers.modelName
|
|
43
1102
|
)?.project;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1103
|
+
generateHook(
|
|
1104
|
+
codegenFs,
|
|
1105
|
+
getTemplateDir("kos-hook"),
|
|
1106
|
+
{
|
|
1107
|
+
name: answers.modelName,
|
|
1108
|
+
appProject: answers.componentProject,
|
|
1109
|
+
modelProject,
|
|
1110
|
+
modelDirectory: "",
|
|
1111
|
+
appDirectory: ""
|
|
1112
|
+
},
|
|
1113
|
+
cwd
|
|
1114
|
+
);
|
|
1115
|
+
await formatFiles(codegenFs.root, codegenFs.writtenPaths);
|
|
56
1116
|
return `Hook created for ${answers.modelName} in ${answers.componentProject}`;
|
|
57
1117
|
});
|
|
58
|
-
|
|
59
1118
|
plop.setGenerator("hook", {
|
|
60
1119
|
description: "Create a hook for a KOS Model",
|
|
61
1120
|
prompts: [
|
|
@@ -63,15 +1122,20 @@ export default async function (plop) {
|
|
|
63
1122
|
type: "list",
|
|
64
1123
|
name: "modelName",
|
|
65
1124
|
message: "Which model to use?",
|
|
66
|
-
choices: modelChoices
|
|
1125
|
+
choices: modelChoices
|
|
67
1126
|
},
|
|
68
1127
|
{
|
|
69
1128
|
type: "list",
|
|
70
1129
|
name: "componentProject",
|
|
71
1130
|
message: "Which project should the hook be created in?",
|
|
72
|
-
choices: allProjects
|
|
73
|
-
}
|
|
1131
|
+
choices: allProjects
|
|
1132
|
+
}
|
|
74
1133
|
],
|
|
75
|
-
actions: actionFactory("createHook", metadata)
|
|
1134
|
+
actions: actionFactory("createHook", metadata)
|
|
76
1135
|
});
|
|
77
1136
|
}
|
|
1137
|
+
export {
|
|
1138
|
+
hook_default as default,
|
|
1139
|
+
metadata
|
|
1140
|
+
};
|
|
1141
|
+
//# sourceMappingURL=hook.mjs.map
|