@kosdev-code/kos-nx-plugin 2.1.23 → 2.1.26
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 +2 -2
- package/src/generators/kos-ui-project/files/.kos.json.template +7 -2
- package/src/generators/kos-ui-project/generator.d.ts.map +1 -1
- package/src/generators/kos-ui-project/generator.js +47 -0
- package/src/generators/kos-ui-project/generator.js.map +1 -1
- package/src/generators/kos-ui-project/schema.d.ts +1 -0
- package/src/generators/kos-ui-project/schema.json +4 -0
- package/src/generators/preset/generator.js +2 -2
- package/src/generators/preset/generator.js.map +1 -1
- package/src/generators/preset/tools/tools/scripts/generate-api-types-split.mjs.template +403 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosdev-code/kos-nx-plugin",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.26",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"generators": "./generators.json",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"main": "./src/index.js",
|
|
20
20
|
"kos": {
|
|
21
21
|
"build": {
|
|
22
|
-
"gitHash": "
|
|
22
|
+
"gitHash": "5af05d3d902c4ddbee74f34723b5acd86dfbdeb7"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "<%= nameDashCase
|
|
3
|
-
"type": "<%= uiType
|
|
2
|
+
"name": "<%= nameDashCase %>",
|
|
3
|
+
"type": "<%= uiType %>",
|
|
4
4
|
"version": "0.0.0-SNAPSHOT",
|
|
5
5
|
"generator": {
|
|
6
6
|
"projectType": "ui"
|
|
7
|
+
},
|
|
8
|
+
"test": {
|
|
9
|
+
"plugin": {
|
|
10
|
+
"context": "<%= nameDashCase %>"
|
|
11
|
+
}
|
|
7
12
|
}
|
|
8
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-ui-project/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,IAAI,EAEL,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-ui-project/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,IAAI,EAEL,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAIvD,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,iBA+MrC;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -5,6 +5,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const eslint_1 = require("@nx/eslint");
|
|
6
6
|
const react_1 = require("@nx/react");
|
|
7
7
|
const path = require("path");
|
|
8
|
+
const kos_config_helpers_1 = require("../../utils/kos-config-helpers");
|
|
8
9
|
const normalize_value_1 = require("../kos-model/lib/normalize-value");
|
|
9
10
|
async function kosUiProjectGenerator(tree, options) {
|
|
10
11
|
const normalizedOptions = (0, normalize_value_1.normalizeAllValues)({
|
|
@@ -47,6 +48,52 @@ async function kosUiProjectGenerator(tree, options) {
|
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, normalized.projectName);
|
|
51
|
+
// Register host with root .kos.json development configuration
|
|
52
|
+
if (tree.exists(".kos.json")) {
|
|
53
|
+
const rootConfigContent = tree.read(".kos.json", "utf-8");
|
|
54
|
+
if (rootConfigContent) {
|
|
55
|
+
const rootConfig = JSON.parse(rootConfigContent);
|
|
56
|
+
if ((0, kos_config_helpers_1.hasDevelopmentConfig)(rootConfig)) {
|
|
57
|
+
// Determine plugin context from options or generate default
|
|
58
|
+
const pluginContext = options.pluginContext || normalized.nameDashCase;
|
|
59
|
+
// Determine UI type for host configuration
|
|
60
|
+
let hostType = "cui";
|
|
61
|
+
if (normalized.uiType.includes("ncui")) {
|
|
62
|
+
hostType = "ncui";
|
|
63
|
+
}
|
|
64
|
+
else if (normalized.uiType.includes("admin")) {
|
|
65
|
+
hostType = "admin";
|
|
66
|
+
}
|
|
67
|
+
// Check if host already exists
|
|
68
|
+
const existingHost = rootConfig.development.hosts.find((h) => h.name === normalized.nameDashCase);
|
|
69
|
+
if (!existingHost) {
|
|
70
|
+
// Calculate next port range - increment by 100 for each new host
|
|
71
|
+
const hostCount = rootConfig.development.hosts.length;
|
|
72
|
+
const nextPortStart = 4200 + hostCount * 100;
|
|
73
|
+
// Add host configuration
|
|
74
|
+
rootConfig.development.hosts.push({
|
|
75
|
+
name: normalized.nameDashCase,
|
|
76
|
+
project: normalized.nameDashCase,
|
|
77
|
+
port: nextPortStart,
|
|
78
|
+
type: hostType,
|
|
79
|
+
pluginContext: pluginContext,
|
|
80
|
+
plugins: [],
|
|
81
|
+
});
|
|
82
|
+
// Add port range
|
|
83
|
+
rootConfig.development.portRanges[normalized.nameDashCase] = {
|
|
84
|
+
start: nextPortStart,
|
|
85
|
+
next: nextPortStart + 1,
|
|
86
|
+
};
|
|
87
|
+
// Write updated .kos.json
|
|
88
|
+
tree.write(".kos.json", JSON.stringify(rootConfig, null, 2) + "\n");
|
|
89
|
+
console.log(`✓ Registered host '${normalized.nameDashCase}' in .kos.json`);
|
|
90
|
+
console.log(` - Port: ${nextPortStart}`);
|
|
91
|
+
console.log(` - Type: ${hostType}`);
|
|
92
|
+
console.log(` - Plugin Context: ${pluginContext}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
50
97
|
const archivePath = normalized.directory || "packages";
|
|
51
98
|
const externalJson = {
|
|
52
99
|
kab: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-ui-project/generator.ts"],"names":[],"mappings":";;;AAAA,uCAOoB;AACpB,uCAAoC;AACpC,qCAAgE;AAChE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-ui-project/generator.ts"],"names":[],"mappings":";;;AAAA,uCAOoB;AACpB,uCAAoC;AACpC,qCAAgE;AAChE,6BAA6B;AAE7B,uEAAsE;AAGtE,sEAAsE;AAE/D,KAAK,UAAU,qBAAqB,CACzC,IAAU,EACV,OAAoC;IAEpC,MAAM,iBAAiB,GAAG,IAAA,oCAAkB,EAAC;QAC3C,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC,CAAC;IACH,MAAM,UAAU,GAAG;QACjB,GAAG,iBAAiB;QACpB,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,WAAW,EAAE,OAAO,CAAC,IAAI;QACzB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ;KACnC,CAAC;IAEF,MAAM,SAAS,GAAG,GAAG,UAAU,CAAC,YAAY,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;IACtE,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAA,4BAAoB,EAAC,IAAI,EAAE;YAC/B,MAAM,EAAE,IAAI;YACZ,aAAa,EAAE,MAAM;YACrB,SAAS,EAAE,MAAM;YACjB,MAAM,EAAE,eAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM;YACf,cAAc,EAAE,MAAM;YACtB,IAAI,EAAE,GAAG,SAAS,EAAE;YACpB,KAAK,EAAE,iBAAi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CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,GAAG,oBAAoB,CAAC,IAAI,yBAAyB,CAAC,CAAC;IACnE,IAAI,CAAC,MAAM,CAAC,GAAG,oBAAoB,CAAC,IAAI,eAAe,CAAC,CAAC;IACzD,IAAI,CAAC,MAAM,CAAC,GAAG,oBAAoB,CAAC,IAAI,uBAAuB,CAAC,CAAC;IACjE,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAjND,sDAiNC;AAED,kBAAe,qBAAqB,CAAC"}
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"type": "string",
|
|
29
29
|
"description": "KAB type of UI",
|
|
30
30
|
"default": "kos.ui"
|
|
31
|
+
},
|
|
32
|
+
"pluginContext": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Plugin context group identifier for compatible plugins (e.g., 'kosdev.ddk', 'cui')"
|
|
31
35
|
}
|
|
32
36
|
},
|
|
33
37
|
"required": ["name"]
|
|
@@ -76,7 +76,6 @@ async function presetGenerator(tree, options) {
|
|
|
76
76
|
"@kosdev-code/kos-nx-plugin": "~2.1.0",
|
|
77
77
|
"@types/node": "^18.16.9",
|
|
78
78
|
archiver: "^5.3.1",
|
|
79
|
-
"openapi-typescript": "^7.6.1",
|
|
80
79
|
"webpack-merge": "^5.10.0",
|
|
81
80
|
});
|
|
82
81
|
// const configTxt = tree.read("nx.json", "utf-8") || "";
|
|
@@ -207,9 +206,10 @@ async function presetGenerator(tree, options) {
|
|
|
207
206
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, "root"), "./", normalized);
|
|
208
207
|
const modelJson = {
|
|
209
208
|
api: {
|
|
210
|
-
command: `
|
|
209
|
+
command: `kosui api:generate --project=${normalized.nameDashCase}-models`,
|
|
211
210
|
options: {
|
|
212
211
|
host: `http://127.0.0.1:8081`,
|
|
212
|
+
defaultVersion: `snapshot`,
|
|
213
213
|
},
|
|
214
214
|
},
|
|
215
215
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/preset/generator.ts"],"names":[],"mappings":";;;AAAA,uCAQoB;AAEpB,yBAA0B;AAE1B,+BAAmE;AACnE,qCAA4D;AAE5D,uCAAoC;AACpC,+BAA4B;AAC5B,qDAAqD;AACrD,+CAA4C;AAC5C,iEAAiE;AAE1D,KAAK,UAAU,eAAe,CACnC,IAAU,EACV,OAA8B;IAE9B,eAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjC,eAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,IAAA,oCAAkB,EAAC,OAAO,CAAC,CAAC;IAE/C,6BAA6B;IAC7B,MAAM,eAAe,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE,GAAG,UAAU,CAAC,YAAY,SAAS,CAAC,CAAC;IAC1E,MAAM,IAAA,qBAAqB,EAAC,IAAI,EAAE;QAChC,IAAI,EAAE,GAAG,UAAU,CAAC,YAAY,SAAS;QACzC,wBAAwB,EAAE,aAAa;QACvC,cAAc,EAAE,MAAM;QACtB,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,eAAM,CAAC,MAAM;QACrB,SAAS,EAAE,eAAe;KAC3B,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAA,iCAAwB,EAC3C,IAAI,EACJ,GAAG,UAAU,CAAC,YAAY,SAAS,CACpC,CAAC;IAEF,wCAAwC;IACxC,MAAM,kBAAkB,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC5D,MAAM,IAAA,wBAAgB,EAAC,IAAI,EAAE;QAC3B,IAAI,EAAE,kBAAkB;QACxB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AE,QAAQ;QACtC,aAAa,EAAE,UAAU;QACzB,QAAQ,EAAE,QAAQ;QAClB,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/preset/generator.ts"],"names":[],"mappings":";;;AAAA,uCAQoB;AAEpB,yBAA0B;AAE1B,+BAAmE;AACnE,qCAA4D;AAE5D,uCAAoC;AACpC,+BAA4B;AAC5B,qDAAqD;AACrD,+CAA4C;AAC5C,iEAAiE;AAE1D,KAAK,UAAU,eAAe,CACnC,IAAU,EACV,OAA8B;IAE9B,eAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjC,eAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,IAAA,oCAAkB,EAAC,OAAO,CAAC,CAAC;IAE/C,6BAA6B;IAC7B,MAAM,eAAe,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE,GAAG,UAAU,CAAC,YAAY,SAAS,CAAC,CAAC;IAC1E,MAAM,IAAA,qBAAqB,EAAC,IAAI,EAAE;QAChC,IAAI,EAAE,GAAG,UAAU,CAAC,YAAY,SAAS;QACzC,wBAAwB,EAAE,aAAa;QACvC,cAAc,EAAE,MAAM;QACtB,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,eAAM,CAAC,MAAM;QACrB,SAAS,EAAE,eAAe;KAC3B,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAA,iCAAwB,EAC3C,IAAI,EACJ,GAAG,UAAU,CAAC,YAAY,SAAS,CACpC,CAAC;IAEF,wCAAwC;IACxC,MAAM,kBAAkB,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC5D,MAAM,IAAA,wBAAgB,EAAC,IAAI,EAA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C,IAAI,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE;QACjD,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,cAAc;QACxB,aAAa,EAAE,UAAU,CAAC,YAAY;QACtC,QAAQ,EAAE,EAAE;KACb,CAAC,CAAC;IAEH,IAAA,mBAAU,EAAC,IAAI,EAAE,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE;QACxC,2CAA2C;QAC3C,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,EAAE,0BAA0B;YAC/B,YAAY,EAAE,+CAA+C;YAC7D,YAAY,EAAE,wCAAwC;YACtD,WAAW,EAAE,uCAAuC;YACpD,GAAG,EAAE,0BAA0B;YAC/B,KAAK,EAAE,4BAA4B;YACnC,GAAG,EAAE,WAAW;YAChB,aAAa,EAAE,mCAAmC;YAClD,GAAG,IAAI,CAAC,OAAO;SAChB,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,IAAA,mBAAU,EAAC,IAAI,EAAE,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE;QAC9C,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IACxB,IAAA,4BAAmB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AA3TD,0CA2TC;AAED,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import devkit from '@nx/devkit';
|
|
2
|
+
import { mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
3
|
+
import openapiTS, { astToString } from 'openapi-typescript';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
const { readCachedProjectGraph } = devkit;
|
|
6
|
+
const [, , name, ...appsToInclude] = process.argv;
|
|
7
|
+
|
|
8
|
+
// Core services bundled with KOS SDKs - exclude these by default for third-party apps
|
|
9
|
+
const CORE_SDK_SERVICES = ['kos', 'vfs', 'dispense', 'freestyle', 'handle', 'kosdev.ddk'];
|
|
10
|
+
const excludeCoreServices = !appsToInclude.includes('--include-core');
|
|
11
|
+
|
|
12
|
+
let graph, project, host, src, outputPath, serviceExportAliases, defaultVersion, appVersions;
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
graph = readCachedProjectGraph();
|
|
16
|
+
project = graph.nodes[name];
|
|
17
|
+
host = project.data.targets.api?.options?.host || 'http://127.0.0.1:8081';
|
|
18
|
+
outputPath = project.data.targets.api?.options?.outputPath;
|
|
19
|
+
serviceExportAliases = project.data.targets.api?.options?.serviceExportAliases || {};
|
|
20
|
+
defaultVersion = project.data.targets.api?.options?.defaultVersion;
|
|
21
|
+
appVersions = project.data.targets.api?.options?.appVersions || {};
|
|
22
|
+
src = project.data.sourceRoot || project.data.root;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// Fallback if project graph reading fails
|
|
25
|
+
console.warn('Warning: Could not read project graph, using defaults');
|
|
26
|
+
host = 'http://127.0.0.1:8081';
|
|
27
|
+
src = `libs/${name}/src`;
|
|
28
|
+
serviceExportAliases = {};
|
|
29
|
+
defaultVersion = undefined;
|
|
30
|
+
appVersions = {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Use custom output path if specified, otherwise default to src/utils
|
|
34
|
+
const utilsDir = outputPath ? join(src, outputPath) : join(src, 'utils');
|
|
35
|
+
const servicesDir = join(utilsDir, 'services');
|
|
36
|
+
mkdirSync(servicesDir, { recursive: true });
|
|
37
|
+
|
|
38
|
+
console.log(`Generating API types for ${name} from ${host}`);
|
|
39
|
+
|
|
40
|
+
// Fetch the full OpenAPI spec
|
|
41
|
+
const openapiUrl = new URL(`${host}/api/kos/openapi/api`, import.meta.url);
|
|
42
|
+
const response = await fetch(openapiUrl);
|
|
43
|
+
const fullSpec = await response.json();
|
|
44
|
+
|
|
45
|
+
// Helper function to determine app name from path
|
|
46
|
+
function getAppFromPath(path) {
|
|
47
|
+
const segments = path.split('/').filter(Boolean);
|
|
48
|
+
|
|
49
|
+
if (segments.length < 2) {
|
|
50
|
+
return 'other';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// /api/kos/* → "kos"
|
|
54
|
+
if (path.startsWith('/api/kos')) {
|
|
55
|
+
return 'kos';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// /api/app/{appName}/* → appName
|
|
59
|
+
if (path.startsWith('/api/app/')) {
|
|
60
|
+
return segments[2] || 'app';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// /api/ext/{extName}/* → extName
|
|
64
|
+
if (path.startsWith('/api/ext/')) {
|
|
65
|
+
return segments[2] || 'ext';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// /api/{other}/* → other
|
|
69
|
+
if (path.startsWith('/api/')) {
|
|
70
|
+
return segments[1] || 'other';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return 'other';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Group paths by app
|
|
77
|
+
const appGroups = {};
|
|
78
|
+
for (const [path, pathItem] of Object.entries(fullSpec.paths || {})) {
|
|
79
|
+
const appName = getAppFromPath(path);
|
|
80
|
+
|
|
81
|
+
if (!appGroups[appName]) {
|
|
82
|
+
appGroups[appName] = {
|
|
83
|
+
paths: {},
|
|
84
|
+
components: new Set()
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
appGroups[appName].paths[path] = pathItem;
|
|
89
|
+
|
|
90
|
+
// Collect referenced components from this path
|
|
91
|
+
const pathJson = JSON.stringify(pathItem);
|
|
92
|
+
const refMatches = pathJson.matchAll(/#\/components\/schemas\/([^"]+)/g);
|
|
93
|
+
for (const match of refMatches) {
|
|
94
|
+
appGroups[appName].components.add(match[1]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Helper function to recursively collect component dependencies
|
|
99
|
+
function collectComponentDependencies(componentId, allComponents, collected = new Set()) {
|
|
100
|
+
if (collected.has(componentId)) {
|
|
101
|
+
return collected;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
collected.add(componentId);
|
|
105
|
+
|
|
106
|
+
const component = allComponents[componentId];
|
|
107
|
+
if (!component) {
|
|
108
|
+
return collected;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Find all schema references in this component
|
|
112
|
+
const componentJson = JSON.stringify(component);
|
|
113
|
+
const refMatches = componentJson.matchAll(/#\/components\/schemas\/([^"]+)/g);
|
|
114
|
+
|
|
115
|
+
for (const match of refMatches) {
|
|
116
|
+
const refId = match[1];
|
|
117
|
+
if (!collected.has(refId)) {
|
|
118
|
+
collectComponentDependencies(refId, allComponents, collected);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return collected;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Filter apps based on command line arguments and core service exclusion
|
|
126
|
+
let appsToProcess = Object.entries(appGroups);
|
|
127
|
+
|
|
128
|
+
// Remove --include-core flag from appsToInclude if present
|
|
129
|
+
const filteredAppsToInclude = appsToInclude.filter(app => app !== '--include-core');
|
|
130
|
+
|
|
131
|
+
// Exclude core services by default unless --include-core flag is present
|
|
132
|
+
if (excludeCoreServices) {
|
|
133
|
+
appsToProcess = appsToProcess.filter(([appName]) => !CORE_SDK_SERVICES.includes(appName));
|
|
134
|
+
console.log(`Excluding core SDK services: ${CORE_SDK_SERVICES.join(', ')}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// If specific apps are requested, further filter to only those
|
|
138
|
+
if (filteredAppsToInclude.length > 0) {
|
|
139
|
+
appsToProcess = appsToProcess.filter(([appName]) => filteredAppsToInclude.includes(appName));
|
|
140
|
+
console.log(`Filtering to include only: ${filteredAppsToInclude.join(', ')}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Generate a separate OpenAPI spec file for each app
|
|
144
|
+
const generatedFiles = [];
|
|
145
|
+
|
|
146
|
+
for (const [appName, appData] of appsToProcess) {
|
|
147
|
+
// Collect all component dependencies
|
|
148
|
+
const allComponentIds = new Set();
|
|
149
|
+
for (const componentId of appData.components) {
|
|
150
|
+
collectComponentDependencies(componentId, fullSpec.components?.schemas || {}, allComponentIds);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Build filtered components
|
|
154
|
+
const filteredComponents = {};
|
|
155
|
+
for (const componentId of allComponentIds) {
|
|
156
|
+
if (fullSpec.components?.schemas?.[componentId]) {
|
|
157
|
+
filteredComponents[componentId] = fullSpec.components.schemas[componentId];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Create app-specific spec
|
|
162
|
+
const appSpec = {
|
|
163
|
+
openapi: fullSpec.openapi,
|
|
164
|
+
info: {
|
|
165
|
+
...fullSpec.info,
|
|
166
|
+
title: `${fullSpec.info.title} - ${appName}`
|
|
167
|
+
},
|
|
168
|
+
paths: appData.paths,
|
|
169
|
+
components: {
|
|
170
|
+
schemas: filteredComponents
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// Determine version: use custom app version if provided, otherwise use OpenAPI spec version
|
|
175
|
+
const version = appVersions[appName] || fullSpec.info.version || 'v1';
|
|
176
|
+
let appDir, filename, serviceFilename;
|
|
177
|
+
|
|
178
|
+
if (['kos', 'ext'].includes(appName) || !appName.includes('.')) {
|
|
179
|
+
// For kos, ext, and simple names: utils/services/{appName}/{version}/
|
|
180
|
+
appDir = join(servicesDir, appName, version);
|
|
181
|
+
filename = 'openapi.d.ts';
|
|
182
|
+
serviceFilename = 'service.ts';
|
|
183
|
+
} else {
|
|
184
|
+
// For app names with dots: utils/services/{appName}/
|
|
185
|
+
// If custom version specified, use versioned folder structure
|
|
186
|
+
if (appVersions[appName]) {
|
|
187
|
+
appDir = join(servicesDir, appName, version);
|
|
188
|
+
} else {
|
|
189
|
+
appDir = join(servicesDir, appName);
|
|
190
|
+
}
|
|
191
|
+
filename = 'openapi.d.ts';
|
|
192
|
+
serviceFilename = 'service.ts';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
mkdirSync(appDir, { recursive: true });
|
|
196
|
+
const outFile = join(appDir, filename);
|
|
197
|
+
const relativeAppDir = appDir.replace(utilsDir + '/', '');
|
|
198
|
+
|
|
199
|
+
console.log(` - Generating ${relativeAppDir}/ (${Object.keys(appData.paths).length} paths, ${allComponentIds.size} components)`);
|
|
200
|
+
|
|
201
|
+
// Generate TypeScript types from the filtered spec
|
|
202
|
+
const ast = await openapiTS(appSpec);
|
|
203
|
+
const contents = astToString(ast);
|
|
204
|
+
|
|
205
|
+
writeFileSync(outFile, contents);
|
|
206
|
+
|
|
207
|
+
// Generate corresponding service file for this app
|
|
208
|
+
const serviceFile = join(appDir, serviceFilename);
|
|
209
|
+
const typeModule = 'openapi';
|
|
210
|
+
|
|
211
|
+
const serviceContent = `import {
|
|
212
|
+
kosServiceRequest as baseKosServiceRequest,
|
|
213
|
+
createClient,
|
|
214
|
+
type ClientResponse,
|
|
215
|
+
type HttpMethod,
|
|
216
|
+
type IKosServiceRequestParams,
|
|
217
|
+
type KosExecutionContext,
|
|
218
|
+
type PathsByMethod,
|
|
219
|
+
} from "@kosdev-code/kos-ui-sdk";
|
|
220
|
+
import type { paths } from "./${typeModule}";
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Type aliases for ${appName} API
|
|
224
|
+
*/
|
|
225
|
+
export type Api = paths;
|
|
226
|
+
export type ApiPath = keyof paths;
|
|
227
|
+
export type ValidPaths = PathsByMethod<paths>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get client response type for ${appName} API
|
|
231
|
+
*/
|
|
232
|
+
export type ApiResponse<
|
|
233
|
+
Path extends ApiPath,
|
|
234
|
+
Method extends "get" | "post" | "put" | "delete" = "get"
|
|
235
|
+
> = ClientResponse<paths, Path, Method>;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get execution context type for ${appName} API
|
|
239
|
+
*/
|
|
240
|
+
export type ExecutionContext<
|
|
241
|
+
Path extends ApiPath = ApiPath,
|
|
242
|
+
Method extends HttpMethod = "get"
|
|
243
|
+
> = KosExecutionContext<paths, Path, Method>;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Typed decorator factory for @kosServiceRequest with ${appName} API types
|
|
247
|
+
*
|
|
248
|
+
* Provides full IntelliSense and type safety for path, query params, and body
|
|
249
|
+
* based on the ${appName} OpenAPI schema.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* \`\`\`typescript
|
|
253
|
+
* import { kosServiceRequest } from '../../utils/services/${appDir.replace(servicesDir + '/', '')}/service';
|
|
254
|
+
* import { DependencyLifecycle } from '@kosdev-code/kos-ui-sdk';
|
|
255
|
+
*
|
|
256
|
+
* @kosServiceRequest({
|
|
257
|
+
* path: '/api/...',
|
|
258
|
+
* method: 'get',
|
|
259
|
+
* lifecycle: DependencyLifecycle.LOAD
|
|
260
|
+
* })
|
|
261
|
+
* private onDataLoaded(): void {
|
|
262
|
+
* // Fully typed based on ${appName} API
|
|
263
|
+
* }
|
|
264
|
+
* \`\`\`
|
|
265
|
+
*/
|
|
266
|
+
export function kosServiceRequest<
|
|
267
|
+
Path extends ApiPath,
|
|
268
|
+
Method extends HttpMethod = "get",
|
|
269
|
+
Response = any,
|
|
270
|
+
TransformedResponse = Response
|
|
271
|
+
>(
|
|
272
|
+
params: IKosServiceRequestParams<
|
|
273
|
+
paths,
|
|
274
|
+
Path,
|
|
275
|
+
Method,
|
|
276
|
+
Response,
|
|
277
|
+
TransformedResponse
|
|
278
|
+
>
|
|
279
|
+
) {
|
|
280
|
+
return baseKosServiceRequest<
|
|
281
|
+
paths,
|
|
282
|
+
Path,
|
|
283
|
+
Method,
|
|
284
|
+
Response,
|
|
285
|
+
TransformedResponse
|
|
286
|
+
>(params);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Create an API client for ${appName}
|
|
291
|
+
*/
|
|
292
|
+
export const api = createClient<paths>();
|
|
293
|
+
|
|
294
|
+
export default api;
|
|
295
|
+
`;
|
|
296
|
+
|
|
297
|
+
writeFileSync(serviceFile, serviceContent);
|
|
298
|
+
|
|
299
|
+
// Store version info if it's a core service (kos, ext) or has a custom version specified
|
|
300
|
+
const versionInfo =
|
|
301
|
+
['kos', 'ext'].includes(appName) || !appName.includes('.') || appVersions[appName]
|
|
302
|
+
? version
|
|
303
|
+
: null;
|
|
304
|
+
|
|
305
|
+
generatedFiles.push({
|
|
306
|
+
appName,
|
|
307
|
+
appDir: appDir.replace(servicesDir + '/', ''),
|
|
308
|
+
version: versionInfo,
|
|
309
|
+
pathCount: Object.keys(appData.paths).length
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Read existing index files to preserve manual entries
|
|
314
|
+
function mergeIndexFile(filePath, newEntries, comment) {
|
|
315
|
+
let existingContent = '';
|
|
316
|
+
try {
|
|
317
|
+
existingContent = readFileSync(filePath, 'utf-8');
|
|
318
|
+
} catch (error) {
|
|
319
|
+
// File doesn't exist yet, that's ok
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Parse existing exports
|
|
323
|
+
const existingExports = new Map();
|
|
324
|
+
const manualExports = [];
|
|
325
|
+
const lines = existingContent.split('\n');
|
|
326
|
+
|
|
327
|
+
for (const line of lines) {
|
|
328
|
+
const match = line.match(/^export \* as (\w+) from ['"](.+)['"]/);
|
|
329
|
+
if (match) {
|
|
330
|
+
const [, exportName, path] = match;
|
|
331
|
+
existingExports.set(exportName, { exportName, path, line });
|
|
332
|
+
} else if (line.trim() && !line.startsWith('//')) {
|
|
333
|
+
// Preserve non-export lines (imports, other statements)
|
|
334
|
+
manualExports.push(line);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Merge with new entries
|
|
339
|
+
for (const { exportName, path } of newEntries) {
|
|
340
|
+
existingExports.set(exportName, {
|
|
341
|
+
exportName,
|
|
342
|
+
path,
|
|
343
|
+
line: `export * as ${exportName} from '${path}';`
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Build final content
|
|
348
|
+
const header = comment ? `// ${comment}\n` : '';
|
|
349
|
+
const exportLines = Array.from(existingExports.values())
|
|
350
|
+
.sort((a, b) => a.exportName.localeCompare(b.exportName))
|
|
351
|
+
.map(e => e.line);
|
|
352
|
+
|
|
353
|
+
return header + exportLines.join('\n') + '\n' +
|
|
354
|
+
(manualExports.length > 0 ? '\n' + manualExports.join('\n') + '\n' : '');
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Generate index file that exports all apps (merge with existing)
|
|
358
|
+
const typeIndexEntries = generatedFiles.map(({ appName, appDir }) => ({
|
|
359
|
+
exportName: appName.replace(/[.-]/g, '_'),
|
|
360
|
+
path: `./services/${appDir}/openapi`
|
|
361
|
+
}));
|
|
362
|
+
|
|
363
|
+
const indexFile = join(utilsDir, 'openapi-index.ts');
|
|
364
|
+
const indexContent = mergeIndexFile(
|
|
365
|
+
indexFile,
|
|
366
|
+
typeIndexEntries,
|
|
367
|
+
'Auto-generated type exports - new entries added automatically'
|
|
368
|
+
);
|
|
369
|
+
writeFileSync(indexFile, indexContent);
|
|
370
|
+
|
|
371
|
+
// Generate service index that re-exports all app services (merge with existing)
|
|
372
|
+
const serviceIndexEntries = generatedFiles.map(({ appName, appDir, version }) => {
|
|
373
|
+
const baseAlias = serviceExportAliases[appName] || appName.replace(/[.-]/g, '_').toUpperCase();
|
|
374
|
+
|
|
375
|
+
// Check if this version is the default version
|
|
376
|
+
const isDefaultVersion = defaultVersion && version === defaultVersion;
|
|
377
|
+
|
|
378
|
+
// For default version, use base alias. For others, append version suffix
|
|
379
|
+
const exportName = isDefaultVersion
|
|
380
|
+
? baseAlias
|
|
381
|
+
: `${baseAlias}_${version.replace(/[.-]/g, '_').toUpperCase()}`;
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
exportName,
|
|
385
|
+
path: `./services/${appDir}/service`
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const serviceIndexFile = join(utilsDir, 'services-index.ts');
|
|
390
|
+
const serviceIndexContent = mergeIndexFile(
|
|
391
|
+
serviceIndexFile,
|
|
392
|
+
serviceIndexEntries,
|
|
393
|
+
'Auto-generated service exports - new entries added automatically'
|
|
394
|
+
);
|
|
395
|
+
writeFileSync(serviceIndexFile, serviceIndexContent);
|
|
396
|
+
|
|
397
|
+
console.log(`\nGenerated ${generatedFiles.length} app-specific type and service file pairs:`);
|
|
398
|
+
generatedFiles.forEach(({ appName, appDir, version, pathCount }) => {
|
|
399
|
+
const versionStr = version ? ` [${version}]` : '';
|
|
400
|
+
console.log(` ✓ ${appDir}/${versionStr} (${appName}: ${pathCount} paths)`);
|
|
401
|
+
});
|
|
402
|
+
console.log(` ✓ openapi-index.ts (aggregated type exports)`);
|
|
403
|
+
console.log(` ✓ services-index.ts (aggregated service exports)`);
|