context-mapper-mcp 1.0.1 → 1.1.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/dist/generators/builtin/plantuml-adapter.d.ts +60 -0
- package/dist/generators/builtin/plantuml-adapter.d.ts.map +1 -0
- package/dist/generators/builtin/plantuml-adapter.js +119 -0
- package/dist/generators/builtin/plantuml-adapter.js.map +1 -0
- package/dist/generators/cli/config.d.ts +105 -0
- package/dist/generators/cli/config.d.ts.map +1 -0
- package/dist/generators/cli/config.js +168 -0
- package/dist/generators/cli/config.js.map +1 -0
- package/dist/generators/cli/context-map.d.ts +26 -0
- package/dist/generators/cli/context-map.d.ts.map +1 -0
- package/dist/generators/cli/context-map.js +124 -0
- package/dist/generators/cli/context-map.js.map +1 -0
- package/dist/generators/cli/executor.d.ts +95 -0
- package/dist/generators/cli/executor.d.ts.map +1 -0
- package/dist/generators/cli/executor.js +277 -0
- package/dist/generators/cli/executor.js.map +1 -0
- package/dist/generators/cli/generic.d.ts +54 -0
- package/dist/generators/cli/generic.d.ts.map +1 -0
- package/dist/generators/cli/generic.js +224 -0
- package/dist/generators/cli/generic.js.map +1 -0
- package/dist/generators/cli/manager.d.ts +83 -0
- package/dist/generators/cli/manager.d.ts.map +1 -0
- package/dist/generators/cli/manager.js +281 -0
- package/dist/generators/cli/manager.js.map +1 -0
- package/dist/generators/cli/mdsl.d.ts +26 -0
- package/dist/generators/cli/mdsl.d.ts.map +1 -0
- package/dist/generators/cli/mdsl.js +118 -0
- package/dist/generators/cli/mdsl.js.map +1 -0
- package/dist/generators/interfaces.d.ts +144 -0
- package/dist/generators/interfaces.d.ts.map +1 -0
- package/dist/generators/interfaces.js +59 -0
- package/dist/generators/interfaces.js.map +1 -0
- package/dist/generators/registry.d.ts +100 -0
- package/dist/generators/registry.d.ts.map +1 -0
- package/dist/generators/registry.js +169 -0
- package/dist/generators/registry.js.map +1 -0
- package/dist/index.js +180 -3
- package/dist/index.js.map +1 -1
- package/dist/tools/cli-tools.d.ts +103 -0
- package/dist/tools/cli-tools.d.ts.map +1 -0
- package/dist/tools/cli-tools.js +220 -0
- package/dist/tools/cli-tools.js.map +1 -0
- package/dist/tools/generation-tools.d.ts +73 -1
- package/dist/tools/generation-tools.d.ts.map +1 -1
- package/dist/tools/generation-tools.js +160 -1
- package/dist/tools/generation-tools.js.map +1 -1
- package/dist/utils/temp-files.d.ts +77 -0
- package/dist/utils/temp-files.d.ts.map +1 -0
- package/dist/utils/temp-files.js +164 -0
- package/dist/utils/temp-files.js.map +1 -0
- package/package.json +4 -1
- package/src/templates/FullReportTemplate.md.ftl +297 -0
- package/src/templates/GlossaryTemplate.md.ftl +132 -0
- package/src/templates/JHipster-Microservices.jdl.ftl +139 -0
- package/src/templates/JHipster-Monolith.jdl.ftl +159 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Executor
|
|
3
|
+
* Handles Java detection and CLI process execution
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Java version info
|
|
7
|
+
*/
|
|
8
|
+
export interface JavaInfo {
|
|
9
|
+
available: boolean;
|
|
10
|
+
version?: string;
|
|
11
|
+
majorVersion?: number;
|
|
12
|
+
compatible?: boolean;
|
|
13
|
+
path?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* CLI execution result
|
|
18
|
+
*/
|
|
19
|
+
export interface CLIExecutionResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
exitCode?: number;
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
timedOut?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* CLI command options
|
|
29
|
+
*/
|
|
30
|
+
export interface CLICommandOptions {
|
|
31
|
+
/** Working directory */
|
|
32
|
+
cwd?: string;
|
|
33
|
+
/** Timeout in milliseconds */
|
|
34
|
+
timeout?: number;
|
|
35
|
+
/** Environment variables to add */
|
|
36
|
+
env?: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check Java availability and version
|
|
40
|
+
*/
|
|
41
|
+
export declare function checkJava(): Promise<JavaInfo>;
|
|
42
|
+
/**
|
|
43
|
+
* CLI Executor class
|
|
44
|
+
*/
|
|
45
|
+
export declare class CLIExecutor {
|
|
46
|
+
private cliPath;
|
|
47
|
+
/**
|
|
48
|
+
* Ensure CLI is available, downloading if necessary
|
|
49
|
+
*/
|
|
50
|
+
ensureCLI(): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Execute a CLI command
|
|
53
|
+
* @param args Command arguments (without the CLI path)
|
|
54
|
+
* @param options Execution options
|
|
55
|
+
*/
|
|
56
|
+
execute(args: string[], options?: CLICommandOptions): Promise<CLIExecutionResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Generate artifacts using the CLI
|
|
59
|
+
* @param inputPath Path to the CML file
|
|
60
|
+
* @param generatorName Name of the generator (e.g., 'context-map', 'mdsl', 'generic')
|
|
61
|
+
* @param outputDir Output directory
|
|
62
|
+
* @param extraArgs Additional arguments
|
|
63
|
+
*/
|
|
64
|
+
generate(inputPath: string, generatorName: string, outputDir: string, extraArgs?: string[], options?: CLICommandOptions): Promise<CLIExecutionResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Get CLI version
|
|
67
|
+
*/
|
|
68
|
+
getVersion(): Promise<string | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Validate a CML file using the CLI
|
|
71
|
+
*/
|
|
72
|
+
validate(inputPath: string): Promise<CLIExecutionResult>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the CLI executor instance
|
|
76
|
+
*/
|
|
77
|
+
export declare function getCLIExecutor(): CLIExecutor;
|
|
78
|
+
/**
|
|
79
|
+
* Full CLI status check
|
|
80
|
+
*/
|
|
81
|
+
export interface CLIStatus {
|
|
82
|
+
javaAvailable: boolean;
|
|
83
|
+
javaVersion?: string;
|
|
84
|
+
javaCompatible: boolean;
|
|
85
|
+
cliInstalled: boolean;
|
|
86
|
+
cliVersion?: string;
|
|
87
|
+
cliPath?: string;
|
|
88
|
+
ready: boolean;
|
|
89
|
+
issues: string[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get comprehensive CLI status
|
|
93
|
+
*/
|
|
94
|
+
export declare function getCLIStatus(): Promise<CLIStatus>;
|
|
95
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/generators/cli/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,wBAAwB;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAcD;;GAEG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,CAwEnD;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAuB;IAEtC;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAWlC;;;;OAIG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAsG3F;;;;;;OAMG;IACG,QAAQ,CACZ,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,GAAE,MAAM,EAAO,EACxB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,kBAAkB,CAAC;IAY9B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAU1C;;OAEG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAG/D;AAKD;;GAEG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC,CAiCvD"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Executor
|
|
3
|
+
* Handles Java detection and CLI process execution
|
|
4
|
+
*/
|
|
5
|
+
import { spawn } from 'child_process';
|
|
6
|
+
import { stat } from 'fs/promises';
|
|
7
|
+
import { getCLIConfig, getJavaExecutablePath, MIN_JAVA_VERSION, DEFAULT_CLI_TIMEOUT, isWindows, } from './config.js';
|
|
8
|
+
import { getCLIManager } from './manager.js';
|
|
9
|
+
/**
|
|
10
|
+
* Check if a file exists
|
|
11
|
+
*/
|
|
12
|
+
async function exists(path) {
|
|
13
|
+
try {
|
|
14
|
+
await stat(path);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check Java availability and version
|
|
23
|
+
*/
|
|
24
|
+
export async function checkJava() {
|
|
25
|
+
const javaPath = getJavaExecutablePath();
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const process = spawn(javaPath, ['-version'], {
|
|
28
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
29
|
+
});
|
|
30
|
+
let stdout = '';
|
|
31
|
+
let stderr = '';
|
|
32
|
+
process.stdout?.on('data', (data) => {
|
|
33
|
+
stdout += data.toString();
|
|
34
|
+
});
|
|
35
|
+
process.stderr?.on('data', (data) => {
|
|
36
|
+
stderr += data.toString();
|
|
37
|
+
});
|
|
38
|
+
process.on('error', (error) => {
|
|
39
|
+
resolve({
|
|
40
|
+
available: false,
|
|
41
|
+
error: `Java not found: ${error.message}`,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
process.on('close', (code) => {
|
|
45
|
+
if (code !== 0) {
|
|
46
|
+
resolve({
|
|
47
|
+
available: false,
|
|
48
|
+
error: `Java version check failed with code ${code}`,
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Java outputs version to stderr
|
|
53
|
+
const output = stderr || stdout;
|
|
54
|
+
// Parse version from output like:
|
|
55
|
+
// java version "17.0.1" or openjdk version "17.0.1"
|
|
56
|
+
const versionMatch = output.match(/version "(\d+)(?:\.(\d+))?(?:\.(\d+))?/);
|
|
57
|
+
if (!versionMatch) {
|
|
58
|
+
resolve({
|
|
59
|
+
available: true,
|
|
60
|
+
path: javaPath,
|
|
61
|
+
error: 'Could not parse Java version',
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const majorVersion = parseInt(versionMatch[1], 10);
|
|
66
|
+
const version = versionMatch[0].replace('version ', '').replace(/"/g, '');
|
|
67
|
+
resolve({
|
|
68
|
+
available: true,
|
|
69
|
+
version,
|
|
70
|
+
majorVersion,
|
|
71
|
+
compatible: majorVersion >= MIN_JAVA_VERSION,
|
|
72
|
+
path: javaPath,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
// Timeout for Java check
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
process.kill();
|
|
78
|
+
resolve({
|
|
79
|
+
available: false,
|
|
80
|
+
error: 'Java version check timed out',
|
|
81
|
+
});
|
|
82
|
+
}, 10000);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* CLI Executor class
|
|
87
|
+
*/
|
|
88
|
+
export class CLIExecutor {
|
|
89
|
+
cliPath = null;
|
|
90
|
+
/**
|
|
91
|
+
* Ensure CLI is available, downloading if necessary
|
|
92
|
+
*/
|
|
93
|
+
async ensureCLI() {
|
|
94
|
+
if (this.cliPath && await exists(this.cliPath)) {
|
|
95
|
+
return this.cliPath;
|
|
96
|
+
}
|
|
97
|
+
const manager = getCLIManager();
|
|
98
|
+
const { path } = await manager.ensureCLI();
|
|
99
|
+
this.cliPath = path;
|
|
100
|
+
return path;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Execute a CLI command
|
|
104
|
+
* @param args Command arguments (without the CLI path)
|
|
105
|
+
* @param options Execution options
|
|
106
|
+
*/
|
|
107
|
+
async execute(args, options = {}) {
|
|
108
|
+
const config = getCLIConfig();
|
|
109
|
+
const timeout = options.timeout ?? config.timeout ?? DEFAULT_CLI_TIMEOUT;
|
|
110
|
+
const cwd = options.cwd ?? process.cwd();
|
|
111
|
+
// Ensure CLI is available
|
|
112
|
+
let cliPath;
|
|
113
|
+
try {
|
|
114
|
+
cliPath = await this.ensureCLI();
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
stdout: '',
|
|
120
|
+
stderr: '',
|
|
121
|
+
error: error instanceof Error ? error.message : 'Failed to ensure CLI availability',
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// Build environment
|
|
125
|
+
const env = {
|
|
126
|
+
...process.env,
|
|
127
|
+
...options.env,
|
|
128
|
+
};
|
|
129
|
+
// Add JAVA_HOME if configured
|
|
130
|
+
if (config.javaHome) {
|
|
131
|
+
env.JAVA_HOME = config.javaHome;
|
|
132
|
+
}
|
|
133
|
+
return new Promise((resolve) => {
|
|
134
|
+
let timedOut = false;
|
|
135
|
+
// On Windows, use cmd.exe to run batch file
|
|
136
|
+
const spawnCommand = isWindows() ? 'cmd.exe' : cliPath;
|
|
137
|
+
const spawnArgs = isWindows() ? ['/c', cliPath, ...args] : args;
|
|
138
|
+
const proc = spawn(spawnCommand, spawnArgs, {
|
|
139
|
+
cwd,
|
|
140
|
+
env,
|
|
141
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
142
|
+
});
|
|
143
|
+
let stdout = '';
|
|
144
|
+
let stderr = '';
|
|
145
|
+
proc.stdout?.on('data', (data) => {
|
|
146
|
+
stdout += data.toString();
|
|
147
|
+
});
|
|
148
|
+
proc.stderr?.on('data', (data) => {
|
|
149
|
+
stderr += data.toString();
|
|
150
|
+
});
|
|
151
|
+
proc.on('error', (error) => {
|
|
152
|
+
resolve({
|
|
153
|
+
success: false,
|
|
154
|
+
stdout,
|
|
155
|
+
stderr,
|
|
156
|
+
error: `Process error: ${error.message}`,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
proc.on('close', (code) => {
|
|
160
|
+
if (timedOut) {
|
|
161
|
+
resolve({
|
|
162
|
+
success: false,
|
|
163
|
+
exitCode: code ?? undefined,
|
|
164
|
+
stdout,
|
|
165
|
+
stderr,
|
|
166
|
+
error: `Command timed out after ${timeout}ms`,
|
|
167
|
+
timedOut: true,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
resolve({
|
|
172
|
+
success: code === 0,
|
|
173
|
+
exitCode: code ?? undefined,
|
|
174
|
+
stdout,
|
|
175
|
+
stderr,
|
|
176
|
+
error: code !== 0 ? `Command exited with code ${code}` : undefined,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
// Set timeout
|
|
181
|
+
const timeoutId = setTimeout(() => {
|
|
182
|
+
timedOut = true;
|
|
183
|
+
proc.kill('SIGTERM');
|
|
184
|
+
// Force kill after 5 seconds if still running
|
|
185
|
+
setTimeout(() => {
|
|
186
|
+
if (!proc.killed) {
|
|
187
|
+
proc.kill('SIGKILL');
|
|
188
|
+
}
|
|
189
|
+
}, 5000);
|
|
190
|
+
}, timeout);
|
|
191
|
+
// Clear timeout on process end
|
|
192
|
+
proc.on('close', () => {
|
|
193
|
+
clearTimeout(timeoutId);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Generate artifacts using the CLI
|
|
199
|
+
* @param inputPath Path to the CML file
|
|
200
|
+
* @param generatorName Name of the generator (e.g., 'context-map', 'mdsl', 'generic')
|
|
201
|
+
* @param outputDir Output directory
|
|
202
|
+
* @param extraArgs Additional arguments
|
|
203
|
+
*/
|
|
204
|
+
async generate(inputPath, generatorName, outputDir, extraArgs = [], options = {}) {
|
|
205
|
+
const args = [
|
|
206
|
+
'generate',
|
|
207
|
+
'-i', inputPath,
|
|
208
|
+
'-g', generatorName,
|
|
209
|
+
'-o', outputDir,
|
|
210
|
+
...extraArgs,
|
|
211
|
+
];
|
|
212
|
+
return this.execute(args, options);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get CLI version
|
|
216
|
+
*/
|
|
217
|
+
async getVersion() {
|
|
218
|
+
const result = await this.execute(['--version']);
|
|
219
|
+
if (result.success) {
|
|
220
|
+
// Parse version from output
|
|
221
|
+
const versionMatch = result.stdout.match(/(\d+\.\d+\.\d+)/);
|
|
222
|
+
return versionMatch ? versionMatch[1] : null;
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Validate a CML file using the CLI
|
|
228
|
+
*/
|
|
229
|
+
async validate(inputPath) {
|
|
230
|
+
return this.execute(['validate', '-i', inputPath]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Singleton instance
|
|
234
|
+
let executorInstance = null;
|
|
235
|
+
/**
|
|
236
|
+
* Get the CLI executor instance
|
|
237
|
+
*/
|
|
238
|
+
export function getCLIExecutor() {
|
|
239
|
+
if (!executorInstance) {
|
|
240
|
+
executorInstance = new CLIExecutor();
|
|
241
|
+
}
|
|
242
|
+
return executorInstance;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get comprehensive CLI status
|
|
246
|
+
*/
|
|
247
|
+
export async function getCLIStatus() {
|
|
248
|
+
const issues = [];
|
|
249
|
+
const javaInfo = await checkJava();
|
|
250
|
+
const manager = getCLIManager();
|
|
251
|
+
const cliVerify = await manager.verify();
|
|
252
|
+
// Check Java
|
|
253
|
+
const javaAvailable = javaInfo.available;
|
|
254
|
+
const javaCompatible = javaInfo.compatible ?? false;
|
|
255
|
+
if (!javaAvailable) {
|
|
256
|
+
issues.push('Java runtime not found. Install JDK 17+ from https://adoptium.net');
|
|
257
|
+
}
|
|
258
|
+
else if (!javaCompatible) {
|
|
259
|
+
issues.push(`Java ${MIN_JAVA_VERSION}+ required, found ${javaInfo.version}`);
|
|
260
|
+
}
|
|
261
|
+
// Check CLI
|
|
262
|
+
const cliInstalled = cliVerify.installed;
|
|
263
|
+
if (!cliInstalled) {
|
|
264
|
+
issues.push('CLI not installed. Run cml_download_cli to install.');
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
javaAvailable,
|
|
268
|
+
javaVersion: javaInfo.version,
|
|
269
|
+
javaCompatible,
|
|
270
|
+
cliInstalled,
|
|
271
|
+
cliVersion: cliVerify.version,
|
|
272
|
+
cliPath: cliVerify.path,
|
|
273
|
+
ready: javaAvailable && javaCompatible && cliInstalled,
|
|
274
|
+
issues,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/generators/cli/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,YAAY,EACZ,qBAAqB,EAErB,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAsC7C;;GAEG;AACH,KAAK,UAAU,MAAM,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAC;IAEzC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE;YAC5C,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;SAClC,CAAC,CAAC;QAEH,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,OAAO,CAAC,MA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Generic Freemarker CLI Generator
|
|
3
|
+
* Generates outputs from Freemarker templates using the Context Mapper CLI
|
|
4
|
+
*/
|
|
5
|
+
import type { CMLModel } from '../../model/types.js';
|
|
6
|
+
import type { IGenerator, GeneratorResult, GeneratorOptions, GenericGeneratorOptions } from '../interfaces.js';
|
|
7
|
+
/**
|
|
8
|
+
* Generic Freemarker Generator
|
|
9
|
+
* Uses CLI to generate outputs from custom Freemarker templates
|
|
10
|
+
*/
|
|
11
|
+
export declare class GenericFreemarkerGenerator implements IGenerator {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
requiresCLI: boolean;
|
|
15
|
+
outputFormats: string[];
|
|
16
|
+
generate(model: CMLModel, options?: GenericGeneratorOptions): Promise<GeneratorResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Find generated files in the output directory
|
|
19
|
+
* Uses the template name to infer expected output extension
|
|
20
|
+
*/
|
|
21
|
+
private findGeneratedFiles;
|
|
22
|
+
/**
|
|
23
|
+
* Get expected output extension from template filename
|
|
24
|
+
* Templates are named like "Name.ext.ftl" where ext is the output extension
|
|
25
|
+
*/
|
|
26
|
+
private getExpectedExtension;
|
|
27
|
+
/**
|
|
28
|
+
* Get format string from file extension
|
|
29
|
+
*/
|
|
30
|
+
private getFormatFromExtension;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Bundled Template Generator
|
|
34
|
+
* Pre-configured generator for bundled templates
|
|
35
|
+
*/
|
|
36
|
+
export declare class BundledTemplateGenerator implements IGenerator {
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
requiresCLI: boolean;
|
|
40
|
+
outputFormats: string[];
|
|
41
|
+
private templateName;
|
|
42
|
+
private genericGenerator;
|
|
43
|
+
constructor(name: string, description: string, templateName: string, outputFormat: string);
|
|
44
|
+
generate(model: CMLModel, options?: GeneratorOptions): Promise<GeneratorResult>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create the Generic Freemarker generator
|
|
48
|
+
*/
|
|
49
|
+
export declare function createGenericFreemarkerGenerator(): IGenerator;
|
|
50
|
+
/**
|
|
51
|
+
* Create generators for bundled templates
|
|
52
|
+
*/
|
|
53
|
+
export declare function createBundledTemplateGenerators(): IGenerator[];
|
|
54
|
+
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/generators/cli/generic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AA2B1B;;;GAGG;AACH,qBAAa,0BAA2B,YAAW,UAAU;IAC3D,IAAI,SAAwB;IAC5B,WAAW,SAAuD;IAClE,WAAW,UAAQ;IACnB,aAAa,WAAS;IAEhB,QAAQ,CACZ,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,eAAe,CAAC;IAmH3B;;;OAGG;YACW,kBAAkB;IAkChC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAO5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;CAoB/B;AAED;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,UAAU;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,UAAQ;IACnB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,gBAAgB,CAA6B;gBAGnD,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM;IAShB,QAAQ,CACZ,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,eAAe,CAAC;CA0B5B;AAED;;GAEG;AACH,wBAAgB,gCAAgC,IAAI,UAAU,CAE7D;AAED;;GAEG;AACH,wBAAgB,+BAA+B,IAAI,UAAU,EAAE,CA2B9D"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Freemarker CLI Generator
|
|
3
|
+
* Generates outputs from Freemarker templates using the Context Mapper CLI
|
|
4
|
+
*/
|
|
5
|
+
import { readdir, readFile, stat, access } from 'fs/promises';
|
|
6
|
+
import { join, basename, extname } from 'path';
|
|
7
|
+
import { constants } from 'fs';
|
|
8
|
+
import { createSuccessResult, createErrorResult, cliNotFoundError, javaNotFoundError, javaVersionError, executionTimeoutError, templateNotFoundError, } from '../interfaces.js';
|
|
9
|
+
import { serializeCML } from '../../model/writer.js';
|
|
10
|
+
import { withTempFiles } from '../../utils/temp-files.js';
|
|
11
|
+
import { getCLIExecutor, getCLIStatus } from './executor.js';
|
|
12
|
+
import { getCLIConfig, getBundledTemplate } from './config.js';
|
|
13
|
+
/**
|
|
14
|
+
* Check if a file exists and is accessible
|
|
15
|
+
*/
|
|
16
|
+
async function fileExists(path) {
|
|
17
|
+
try {
|
|
18
|
+
await access(path, constants.R_OK);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generic Freemarker Generator
|
|
27
|
+
* Uses CLI to generate outputs from custom Freemarker templates
|
|
28
|
+
*/
|
|
29
|
+
export class GenericFreemarkerGenerator {
|
|
30
|
+
name = 'generic-freemarker';
|
|
31
|
+
description = 'Generate outputs from custom Freemarker templates';
|
|
32
|
+
requiresCLI = true;
|
|
33
|
+
outputFormats = ['*']; // Depends on template
|
|
34
|
+
async generate(model, options) {
|
|
35
|
+
if (!options?.templatePath) {
|
|
36
|
+
return createErrorResult('TEMPLATE_NOT_FOUND', 'templatePath is required', 'Provide the path to a Freemarker (.ftl) template file');
|
|
37
|
+
}
|
|
38
|
+
// Check if template exists
|
|
39
|
+
if (!(await fileExists(options.templatePath))) {
|
|
40
|
+
return templateNotFoundError(options.templatePath);
|
|
41
|
+
}
|
|
42
|
+
// Check prerequisites
|
|
43
|
+
const status = await getCLIStatus();
|
|
44
|
+
if (!status.javaAvailable) {
|
|
45
|
+
return javaNotFoundError();
|
|
46
|
+
}
|
|
47
|
+
if (!status.javaCompatible) {
|
|
48
|
+
return javaVersionError(status.javaVersion || 'unknown');
|
|
49
|
+
}
|
|
50
|
+
if (!status.cliInstalled) {
|
|
51
|
+
return cliNotFoundError();
|
|
52
|
+
}
|
|
53
|
+
// Use temp files with automatic cleanup
|
|
54
|
+
return withTempFiles(async (tempContext) => {
|
|
55
|
+
try {
|
|
56
|
+
// Serialize model to CML
|
|
57
|
+
const cmlContent = serializeCML(model);
|
|
58
|
+
const tempDir = await tempContext.createDir();
|
|
59
|
+
const cmlPath = await tempContext.createCMLFile(cmlContent, tempDir);
|
|
60
|
+
// Determine output directory
|
|
61
|
+
const config = getCLIConfig();
|
|
62
|
+
const outputDir = options?.outputDir ?? config.outputDir;
|
|
63
|
+
// Build extra arguments
|
|
64
|
+
const extraArgs = [
|
|
65
|
+
'-t', options.templatePath,
|
|
66
|
+
];
|
|
67
|
+
// Optional output file name
|
|
68
|
+
if (options.outputFileName) {
|
|
69
|
+
extraArgs.push('-f', options.outputFileName);
|
|
70
|
+
}
|
|
71
|
+
// Execute CLI
|
|
72
|
+
const executor = getCLIExecutor();
|
|
73
|
+
const result = await executor.generate(cmlPath, 'generic', outputDir, extraArgs, { timeout: options?.timeout });
|
|
74
|
+
if (result.timedOut) {
|
|
75
|
+
return executionTimeoutError(options?.timeout ?? config.timeout);
|
|
76
|
+
}
|
|
77
|
+
if (!result.success) {
|
|
78
|
+
return createErrorResult('EXECUTION_FAILED', result.error || 'CLI execution failed', 'Check the template syntax and CML model for errors', result.stderr);
|
|
79
|
+
}
|
|
80
|
+
// Find generated files
|
|
81
|
+
const generatedFiles = await this.findGeneratedFiles(outputDir, options.templatePath);
|
|
82
|
+
if (generatedFiles.length === 0) {
|
|
83
|
+
return createErrorResult('OUTPUT_NOT_FOUND', 'No output files were generated', 'Check the template for errors or ensure the model has content to process');
|
|
84
|
+
}
|
|
85
|
+
// Read file contents for output
|
|
86
|
+
const outputs = await Promise.all(generatedFiles.map(async (filePath) => {
|
|
87
|
+
const content = await readFile(filePath, 'utf-8');
|
|
88
|
+
const format = this.getFormatFromExtension(filePath);
|
|
89
|
+
return {
|
|
90
|
+
type: 'file',
|
|
91
|
+
path: filePath,
|
|
92
|
+
content,
|
|
93
|
+
format,
|
|
94
|
+
description: `Generated from template: ${basename(filePath)}`,
|
|
95
|
+
};
|
|
96
|
+
}));
|
|
97
|
+
// Include any warnings from stderr
|
|
98
|
+
const warnings = result.stderr
|
|
99
|
+
? result.stderr.split('\n').filter((line) => line.trim().length > 0)
|
|
100
|
+
: undefined;
|
|
101
|
+
return createSuccessResult(outputs, warnings);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return createErrorResult('INTERNAL_ERROR', error instanceof Error ? error.message : 'Unknown error during generation');
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Find generated files in the output directory
|
|
110
|
+
* Uses the template name to infer expected output extension
|
|
111
|
+
*/
|
|
112
|
+
async findGeneratedFiles(outputDir, templatePath) {
|
|
113
|
+
const files = [];
|
|
114
|
+
// Get expected extension from template name (e.g., "GlossaryTemplate.md.ftl" -> ".md")
|
|
115
|
+
const templateBase = basename(templatePath);
|
|
116
|
+
const expectedExt = this.getExpectedExtension(templateBase);
|
|
117
|
+
try {
|
|
118
|
+
const entries = await readdir(outputDir);
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
// Match files with expected extension or any recently created files
|
|
121
|
+
const entryPath = join(outputDir, entry);
|
|
122
|
+
const entryStat = await stat(entryPath);
|
|
123
|
+
if (entryStat.isFile()) {
|
|
124
|
+
if (expectedExt && entry.endsWith(expectedExt)) {
|
|
125
|
+
files.push(entryPath);
|
|
126
|
+
}
|
|
127
|
+
else if (!expectedExt && !entry.endsWith('.cml')) {
|
|
128
|
+
// If we can't determine extension, include non-CML files
|
|
129
|
+
files.push(entryPath);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Directory may not exist
|
|
136
|
+
}
|
|
137
|
+
return files;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get expected output extension from template filename
|
|
141
|
+
* Templates are named like "Name.ext.ftl" where ext is the output extension
|
|
142
|
+
*/
|
|
143
|
+
getExpectedExtension(templateName) {
|
|
144
|
+
// Remove .ftl extension
|
|
145
|
+
const withoutFtl = templateName.replace(/\.ftl$/i, '');
|
|
146
|
+
const ext = extname(withoutFtl);
|
|
147
|
+
return ext || null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get format string from file extension
|
|
151
|
+
*/
|
|
152
|
+
getFormatFromExtension(filePath) {
|
|
153
|
+
const ext = extname(filePath).toLowerCase();
|
|
154
|
+
switch (ext) {
|
|
155
|
+
case '.md':
|
|
156
|
+
return 'markdown';
|
|
157
|
+
case '.jdl':
|
|
158
|
+
return 'jdl';
|
|
159
|
+
case '.json':
|
|
160
|
+
return 'json';
|
|
161
|
+
case '.yaml':
|
|
162
|
+
case '.yml':
|
|
163
|
+
return 'yaml';
|
|
164
|
+
case '.xml':
|
|
165
|
+
return 'xml';
|
|
166
|
+
case '.html':
|
|
167
|
+
return 'html';
|
|
168
|
+
default:
|
|
169
|
+
return ext.replace('.', '') || 'text';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Bundled Template Generator
|
|
175
|
+
* Pre-configured generator for bundled templates
|
|
176
|
+
*/
|
|
177
|
+
export class BundledTemplateGenerator {
|
|
178
|
+
name;
|
|
179
|
+
description;
|
|
180
|
+
requiresCLI = true;
|
|
181
|
+
outputFormats;
|
|
182
|
+
templateName;
|
|
183
|
+
genericGenerator;
|
|
184
|
+
constructor(name, description, templateName, outputFormat) {
|
|
185
|
+
this.name = name;
|
|
186
|
+
this.description = description;
|
|
187
|
+
this.templateName = templateName;
|
|
188
|
+
this.outputFormats = [outputFormat];
|
|
189
|
+
this.genericGenerator = new GenericFreemarkerGenerator();
|
|
190
|
+
}
|
|
191
|
+
async generate(model, options) {
|
|
192
|
+
const templateInfo = getBundledTemplate(this.templateName);
|
|
193
|
+
if (!templateInfo) {
|
|
194
|
+
return createErrorResult('TEMPLATE_NOT_FOUND', `Bundled template '${this.templateName}' not found`, 'This is an internal error - the bundled templates may not be installed correctly');
|
|
195
|
+
}
|
|
196
|
+
// Check if template file exists
|
|
197
|
+
if (!(await fileExists(templateInfo.path))) {
|
|
198
|
+
return createErrorResult('TEMPLATE_NOT_FOUND', `Bundled template file not found: ${templateInfo.path}`, 'Reinstall the package to restore bundled templates');
|
|
199
|
+
}
|
|
200
|
+
// Use the generic generator with the bundled template
|
|
201
|
+
return this.genericGenerator.generate(model, {
|
|
202
|
+
...options,
|
|
203
|
+
templatePath: templateInfo.path,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Create the Generic Freemarker generator
|
|
209
|
+
*/
|
|
210
|
+
export function createGenericFreemarkerGenerator() {
|
|
211
|
+
return new GenericFreemarkerGenerator();
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Create generators for bundled templates
|
|
215
|
+
*/
|
|
216
|
+
export function createBundledTemplateGenerators() {
|
|
217
|
+
return [
|
|
218
|
+
new BundledTemplateGenerator('glossary', 'Generate ubiquitous language glossary from domain model', 'glossary', 'markdown'),
|
|
219
|
+
new BundledTemplateGenerator('jhipster-microservices', 'Generate JHipster JDL for microservices architecture', 'jhipster-microservices', 'jdl'),
|
|
220
|
+
new BundledTemplateGenerator('jhipster-monolith', 'Generate JHipster JDL for monolithic application', 'jhipster-monolith', 'jdl'),
|
|
221
|
+
new BundledTemplateGenerator('full-report', 'Generate comprehensive domain documentation', 'full-report', 'markdown'),
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=generic.js.map
|