context-mapper-mcp 1.0.0 → 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/README.md +13 -14
- 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,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../../src/generators/cli/generic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAU/B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7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ACnD,kFAAkF,CACnF,CAAC;QACJ,CAAC;QAED,gCAAgC;QAChC,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAC3C,OAAO,iBAAiB,CACtB,oBAAoB,EACpB,oCAAoC,YAAY,CAAC,IAAI,EAAE,EACvD,oDAAoD,CACrD,CAAC;QACJ,CAAC;QAED,sDAAsD;QACtD,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,EAAE;YAC3C,GAAG,OAAO;YACV,YAAY,EAAE,YAAY,CAAC,IAAI;SAChC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gCAAgC;IAC9C,OAAO,IAAI,0BAA0B,EAAE,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,+BAA+B;IAC7C,OAAO;QACL,IAAI,wBAAwB,CAC1B,UAAU,EACV,yDAAyD,EACzD,UAAU,EACV,UAAU,CACX;QACD,IAAI,wBAAwB,CAC1B,wBAAwB,EACxB,sDAAsD,EACtD,wBAAwB,EACxB,KAAK,CACN;QACD,IAAI,wBAAwB,CAC1B,mBAAmB,EACnB,kDAAkD,EAClD,mBAAmB,EACnB,KAAK,CACN;QACD,IAAI,wBAAwB,CAC1B,aAAa,EACb,6CAA6C,EAC7C,aAAa,EACb,UAAU,CACX;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Manager
|
|
3
|
+
* Handles CLI download, extraction, and version management
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Result of CLI verification
|
|
7
|
+
*/
|
|
8
|
+
export interface CLIVerifyResult {
|
|
9
|
+
installed: boolean;
|
|
10
|
+
version?: string;
|
|
11
|
+
path?: string;
|
|
12
|
+
error?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Result of CLI download
|
|
16
|
+
*/
|
|
17
|
+
export interface CLIDownloadResult {
|
|
18
|
+
success: boolean;
|
|
19
|
+
version?: string;
|
|
20
|
+
path?: string;
|
|
21
|
+
error?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* CLI Manager class
|
|
25
|
+
*/
|
|
26
|
+
export declare class CLIManager {
|
|
27
|
+
private version;
|
|
28
|
+
constructor(version?: string);
|
|
29
|
+
/**
|
|
30
|
+
* Get CLI path, downloading if not present
|
|
31
|
+
* @returns Path to CLI and version info
|
|
32
|
+
*/
|
|
33
|
+
ensureCLI(): Promise<{
|
|
34
|
+
path: string;
|
|
35
|
+
version: string;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Check if CLI is installed and working
|
|
39
|
+
*/
|
|
40
|
+
verify(): Promise<CLIVerifyResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Download CLI from Maven Central
|
|
43
|
+
*/
|
|
44
|
+
downloadCLI(): Promise<CLIDownloadResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Download a file from URL
|
|
47
|
+
*/
|
|
48
|
+
private downloadFile;
|
|
49
|
+
/**
|
|
50
|
+
* Extract archive (TAR or ZIP)
|
|
51
|
+
*/
|
|
52
|
+
private extractArchive;
|
|
53
|
+
/**
|
|
54
|
+
* Extract TAR archive (for Unix)
|
|
55
|
+
*/
|
|
56
|
+
private extractTar;
|
|
57
|
+
/**
|
|
58
|
+
* Extract ZIP archive (for Windows)
|
|
59
|
+
* Using native unzip as Node.js doesn't have built-in ZIP support
|
|
60
|
+
*/
|
|
61
|
+
private extractZip;
|
|
62
|
+
/**
|
|
63
|
+
* Flatten extracted directory if CLI was extracted to a subdirectory
|
|
64
|
+
*/
|
|
65
|
+
private flattenExtractedDir;
|
|
66
|
+
/**
|
|
67
|
+
* Remove installed CLI
|
|
68
|
+
*/
|
|
69
|
+
uninstall(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Get installed CLI versions
|
|
72
|
+
*/
|
|
73
|
+
static getInstalledVersions(): Promise<string[]>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the CLI manager instance
|
|
77
|
+
*/
|
|
78
|
+
export declare function getCLIManager(): CLIManager;
|
|
79
|
+
/**
|
|
80
|
+
* Set the CLI version and recreate manager
|
|
81
|
+
*/
|
|
82
|
+
export declare function setCLIVersion(version: string): CLIManager;
|
|
83
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/generators/cli/manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAcD;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,GAAE,MAA4B;IAIjD;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAmB7D;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC;IAsBxC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAwD/C;;OAEG;YACW,YAAY;IAqC1B;;OAEG;YACW,cAAc;IAY5B;;OAEG;YACW,UAAU;IAQxB;;;OAGG;YACW,UAAU;IAsBxB;;OAEG;YACW,mBAAmB;IAkCjC;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAKhC;;OAEG;WACU,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAyBvD;AAKD;;GAEG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAK1C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAGzD"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Manager
|
|
3
|
+
* Handles CLI download, extraction, and version management
|
|
4
|
+
*/
|
|
5
|
+
import { createWriteStream } from 'fs';
|
|
6
|
+
import { mkdir, rm, stat, chmod, rename, readdir } from 'fs/promises';
|
|
7
|
+
import { join, dirname } from 'path';
|
|
8
|
+
import { extract as tarExtract } from 'tar';
|
|
9
|
+
import { getCLIConfig, getCLIVersionDir, getCLIExecutablePath, getCLIDownloadUrl, isWindows, DEFAULT_CLI_VERSION, } from './config.js';
|
|
10
|
+
/**
|
|
11
|
+
* Check if a file or directory exists
|
|
12
|
+
*/
|
|
13
|
+
async function exists(path) {
|
|
14
|
+
try {
|
|
15
|
+
await stat(path);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* CLI Manager class
|
|
24
|
+
*/
|
|
25
|
+
export class CLIManager {
|
|
26
|
+
version;
|
|
27
|
+
constructor(version = DEFAULT_CLI_VERSION) {
|
|
28
|
+
this.version = version;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get CLI path, downloading if not present
|
|
32
|
+
* @returns Path to CLI and version info
|
|
33
|
+
*/
|
|
34
|
+
async ensureCLI() {
|
|
35
|
+
const verification = await this.verify();
|
|
36
|
+
if (verification.installed && verification.path) {
|
|
37
|
+
return { path: verification.path, version: this.version };
|
|
38
|
+
}
|
|
39
|
+
// Download and install
|
|
40
|
+
const downloadResult = await this.downloadCLI();
|
|
41
|
+
if (!downloadResult.success) {
|
|
42
|
+
throw new Error(downloadResult.error || 'Failed to download CLI');
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
path: getCLIExecutablePath(this.version),
|
|
46
|
+
version: this.version,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if CLI is installed and working
|
|
51
|
+
*/
|
|
52
|
+
async verify() {
|
|
53
|
+
const cliPath = getCLIExecutablePath(this.version);
|
|
54
|
+
try {
|
|
55
|
+
const pathExists = await exists(cliPath);
|
|
56
|
+
if (!pathExists) {
|
|
57
|
+
return { installed: false, error: 'CLI not found' };
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
installed: true,
|
|
61
|
+
version: this.version,
|
|
62
|
+
path: cliPath,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return {
|
|
67
|
+
installed: false,
|
|
68
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Download CLI from Maven Central
|
|
74
|
+
*/
|
|
75
|
+
async downloadCLI() {
|
|
76
|
+
const config = getCLIConfig();
|
|
77
|
+
const versionDir = getCLIVersionDir(this.version);
|
|
78
|
+
const downloadUrl = getCLIDownloadUrl(this.version);
|
|
79
|
+
try {
|
|
80
|
+
// Create version directory
|
|
81
|
+
await mkdir(versionDir, { recursive: true });
|
|
82
|
+
// Determine archive type and temp path
|
|
83
|
+
const archiveExt = isWindows() ? 'zip' : 'tar';
|
|
84
|
+
const tempArchivePath = join(versionDir, `cli.${archiveExt}`);
|
|
85
|
+
// Download the archive
|
|
86
|
+
console.error(`Downloading Context Mapper CLI ${this.version} from Maven Central...`);
|
|
87
|
+
await this.downloadFile(downloadUrl, tempArchivePath);
|
|
88
|
+
// Extract the archive
|
|
89
|
+
console.error('Extracting CLI...');
|
|
90
|
+
await this.extractArchive(tempArchivePath, versionDir);
|
|
91
|
+
// Clean up archive
|
|
92
|
+
await rm(tempArchivePath, { force: true });
|
|
93
|
+
// Make executable on Unix
|
|
94
|
+
if (!isWindows()) {
|
|
95
|
+
const cliPath = getCLIExecutablePath(this.version);
|
|
96
|
+
try {
|
|
97
|
+
await chmod(cliPath, 0o755);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// May fail if file doesn't exist yet
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.error(`CLI ${this.version} installed successfully`);
|
|
104
|
+
return {
|
|
105
|
+
success: true,
|
|
106
|
+
version: this.version,
|
|
107
|
+
path: getCLIExecutablePath(this.version),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// Clean up on failure
|
|
112
|
+
try {
|
|
113
|
+
await rm(versionDir, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// Ignore cleanup errors
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
error: error instanceof Error ? error.message : 'Unknown download error',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Download a file from URL
|
|
126
|
+
*/
|
|
127
|
+
async downloadFile(url, destPath) {
|
|
128
|
+
const response = await fetch(url);
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
throw new Error(`Failed to download: ${response.status} ${response.statusText}`);
|
|
131
|
+
}
|
|
132
|
+
if (!response.body) {
|
|
133
|
+
throw new Error('No response body');
|
|
134
|
+
}
|
|
135
|
+
// Ensure parent directory exists
|
|
136
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
137
|
+
// Write to file using streams
|
|
138
|
+
const fileStream = createWriteStream(destPath);
|
|
139
|
+
// Convert ReadableStream to Node.js Readable
|
|
140
|
+
const reader = response.body.getReader();
|
|
141
|
+
const chunks = [];
|
|
142
|
+
while (true) {
|
|
143
|
+
const { done, value } = await reader.read();
|
|
144
|
+
if (done)
|
|
145
|
+
break;
|
|
146
|
+
chunks.push(value);
|
|
147
|
+
}
|
|
148
|
+
const buffer = Buffer.concat(chunks);
|
|
149
|
+
fileStream.write(buffer);
|
|
150
|
+
fileStream.end();
|
|
151
|
+
await new Promise((resolve, reject) => {
|
|
152
|
+
fileStream.on('finish', resolve);
|
|
153
|
+
fileStream.on('error', reject);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Extract archive (TAR or ZIP)
|
|
158
|
+
*/
|
|
159
|
+
async extractArchive(archivePath, destDir) {
|
|
160
|
+
if (isWindows()) {
|
|
161
|
+
await this.extractZip(archivePath, destDir);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
await this.extractTar(archivePath, destDir);
|
|
165
|
+
}
|
|
166
|
+
// Handle nested directory structure
|
|
167
|
+
// The CLI archive may extract to a subdirectory like context-mapper-cli-6.12.0/
|
|
168
|
+
await this.flattenExtractedDir(destDir);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Extract TAR archive (for Unix)
|
|
172
|
+
*/
|
|
173
|
+
async extractTar(archivePath, destDir) {
|
|
174
|
+
// The TAR from Maven is not gzipped
|
|
175
|
+
await tarExtract({
|
|
176
|
+
file: archivePath,
|
|
177
|
+
cwd: destDir,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Extract ZIP archive (for Windows)
|
|
182
|
+
* Using native unzip as Node.js doesn't have built-in ZIP support
|
|
183
|
+
*/
|
|
184
|
+
async extractZip(archivePath, destDir) {
|
|
185
|
+
// Use PowerShell to extract on Windows
|
|
186
|
+
const { spawn } = await import('child_process');
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
const ps = spawn('powershell', [
|
|
189
|
+
'-Command',
|
|
190
|
+
`Expand-Archive -Path "${archivePath}" -DestinationPath "${destDir}" -Force`,
|
|
191
|
+
]);
|
|
192
|
+
ps.on('close', (code) => {
|
|
193
|
+
if (code === 0) {
|
|
194
|
+
resolve();
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
reject(new Error(`ZIP extraction failed with code ${code}`));
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
ps.on('error', reject);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Flatten extracted directory if CLI was extracted to a subdirectory
|
|
205
|
+
*/
|
|
206
|
+
async flattenExtractedDir(destDir) {
|
|
207
|
+
const entries = await readdir(destDir);
|
|
208
|
+
// Look for the CLI directory pattern (context-mapper-cli-X.X.X)
|
|
209
|
+
const cliSubdir = entries.find((e) => e.startsWith('context-mapper-cli-') && !e.endsWith('.tar') && !e.endsWith('.zip'));
|
|
210
|
+
if (cliSubdir) {
|
|
211
|
+
const subdirPath = join(destDir, cliSubdir);
|
|
212
|
+
const subdirStat = await stat(subdirPath);
|
|
213
|
+
if (subdirStat.isDirectory()) {
|
|
214
|
+
// Move contents up
|
|
215
|
+
const subdirEntries = await readdir(subdirPath);
|
|
216
|
+
for (const entry of subdirEntries) {
|
|
217
|
+
const srcPath = join(subdirPath, entry);
|
|
218
|
+
const destPath = join(destDir, entry);
|
|
219
|
+
// Remove existing if present
|
|
220
|
+
if (await exists(destPath)) {
|
|
221
|
+
await rm(destPath, { recursive: true, force: true });
|
|
222
|
+
}
|
|
223
|
+
await rename(srcPath, destPath);
|
|
224
|
+
}
|
|
225
|
+
// Remove empty subdirectory
|
|
226
|
+
await rm(subdirPath, { recursive: true, force: true });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Remove installed CLI
|
|
232
|
+
*/
|
|
233
|
+
async uninstall() {
|
|
234
|
+
const versionDir = getCLIVersionDir(this.version);
|
|
235
|
+
await rm(versionDir, { recursive: true, force: true });
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get installed CLI versions
|
|
239
|
+
*/
|
|
240
|
+
static async getInstalledVersions() {
|
|
241
|
+
const config = getCLIConfig();
|
|
242
|
+
const cliDir = config.cliDir;
|
|
243
|
+
try {
|
|
244
|
+
const entries = await readdir(cliDir);
|
|
245
|
+
const versions = [];
|
|
246
|
+
for (const entry of entries) {
|
|
247
|
+
const entryPath = join(cliDir, entry);
|
|
248
|
+
const entryStat = await stat(entryPath);
|
|
249
|
+
if (entryStat.isDirectory()) {
|
|
250
|
+
// Check if it looks like a version directory
|
|
251
|
+
if (/^\d+\.\d+\.\d+/.test(entry)) {
|
|
252
|
+
versions.push(entry);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return versions.sort();
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return [];
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Singleton manager instance
|
|
264
|
+
let managerInstance = null;
|
|
265
|
+
/**
|
|
266
|
+
* Get the CLI manager instance
|
|
267
|
+
*/
|
|
268
|
+
export function getCLIManager() {
|
|
269
|
+
if (!managerInstance) {
|
|
270
|
+
managerInstance = new CLIManager();
|
|
271
|
+
}
|
|
272
|
+
return managerInstance;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Set the CLI version and recreate manager
|
|
276
|
+
*/
|
|
277
|
+
export function setCLIVersion(version) {
|
|
278
|
+
managerInstance = new CLIManager(version);
|
|
279
|
+
return managerInstance;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/generators/cli/manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAoB,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE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Aa,CAAC,OAAe;IAC3C,eAAe,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDSL CLI Generator
|
|
3
|
+
* Generates MDSL (Microservice Domain Specific Language) contracts using the Context Mapper CLI
|
|
4
|
+
*/
|
|
5
|
+
import type { CMLModel } from '../../model/types.js';
|
|
6
|
+
import type { IGenerator, GeneratorResult, MDSLGeneratorOptions } from '../interfaces.js';
|
|
7
|
+
/**
|
|
8
|
+
* MDSL Generator
|
|
9
|
+
* Uses CLI to generate MDSL microservice contracts from upstream-downstream relationships
|
|
10
|
+
*/
|
|
11
|
+
export declare class MDSLGenerator implements IGenerator {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
requiresCLI: boolean;
|
|
15
|
+
outputFormats: string[];
|
|
16
|
+
generate(model: CMLModel, options?: MDSLGeneratorOptions): Promise<GeneratorResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Find generated MDSL files in the output directory
|
|
19
|
+
*/
|
|
20
|
+
private findGeneratedFiles;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create the MDSL generator
|
|
24
|
+
*/
|
|
25
|
+
export declare function createMDSLGenerator(): IGenerator;
|
|
26
|
+
//# sourceMappingURL=mdsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdsl.d.ts","sourceRoot":"","sources":["../../../src/generators/cli/mdsl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,oBAAoB,EAErB,MAAM,kBAAkB,CAAC;AAc1B;;;GAGG;AACH,qBAAa,aAAc,YAAW,UAAU;IAC9C,IAAI,SAAU;IACd,WAAW,SAAyE;IACpF,WAAW,UAAQ;IACnB,aAAa,WAAY;IAEnB,QAAQ,CACZ,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAmH3B;;OAEG;YACW,kBAAkB;CAsBjC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,UAAU,CAEhD"}
|