@atomic-ehr/codegen 0.0.1-canary.20250821160126.c552195 → 0.0.1-canary.20250822150706.c3b8669
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/api/builder.d.ts +3 -3
- package/dist/api/builder.d.ts.map +1 -1
- package/dist/api/builder.js +374 -0
- package/dist/api/generators/base/BaseGenerator.d.ts +4 -4
- package/dist/api/generators/base/BaseGenerator.d.ts.map +1 -1
- package/dist/api/generators/base/BaseGenerator.js +572 -0
- package/dist/api/generators/base/FileManager.d.ts +2 -2
- package/dist/api/generators/base/FileManager.d.ts.map +1 -1
- package/dist/api/generators/base/FileManager.js +204 -0
- package/dist/api/generators/base/PythonTypeMapper.d.ts +2 -2
- package/dist/api/generators/base/PythonTypeMapper.d.ts.map +1 -1
- package/dist/api/generators/base/PythonTypeMapper.js +71 -0
- package/dist/api/generators/base/TemplateEngine.d.ts +1 -1
- package/dist/api/generators/base/TemplateEngine.d.ts.map +1 -1
- package/dist/api/generators/base/TemplateEngine.js +133 -0
- package/dist/api/generators/base/TypeMapper.js +153 -0
- package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +1 -1
- package/dist/api/generators/base/TypeScriptTypeMapper.d.ts.map +1 -1
- package/dist/api/generators/base/TypeScriptTypeMapper.js +232 -0
- package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +4 -4
- package/dist/api/generators/base/builders/DirectoryBuilder.d.ts.map +1 -1
- package/dist/api/generators/base/builders/DirectoryBuilder.js +215 -0
- package/dist/api/generators/base/builders/FileBuilder.d.ts +2 -2
- package/dist/api/generators/base/builders/FileBuilder.d.ts.map +1 -1
- package/dist/api/generators/base/builders/FileBuilder.js +408 -0
- package/dist/api/generators/base/builders/IndexBuilder.d.ts +2 -2
- package/dist/api/generators/base/builders/IndexBuilder.d.ts.map +1 -1
- package/dist/api/generators/base/builders/IndexBuilder.js +290 -0
- package/dist/api/generators/base/enhanced-errors.d.ts +2 -2
- package/dist/api/generators/base/enhanced-errors.d.ts.map +1 -1
- package/dist/api/generators/base/enhanced-errors.js +259 -0
- package/dist/api/generators/base/error-handler.d.ts +1 -1
- package/dist/api/generators/base/error-handler.d.ts.map +1 -1
- package/dist/api/generators/base/error-handler.js +243 -0
- package/dist/api/generators/base/errors.d.ts +2 -2
- package/dist/api/generators/base/errors.d.ts.map +1 -1
- package/dist/api/generators/base/errors.js +694 -0
- package/dist/api/generators/base/index.d.ts +22 -22
- package/dist/api/generators/base/index.d.ts.map +1 -1
- package/dist/api/generators/base/index.js +161 -0
- package/dist/api/generators/base/types.d.ts +2 -2
- package/dist/api/generators/base/types.d.ts.map +1 -1
- package/dist/api/generators/base/types.js +12 -0
- package/dist/api/generators/rest-client.d.ts +2 -2
- package/dist/api/generators/rest-client.d.ts.map +1 -1
- package/dist/api/generators/rest-client.js +847 -0
- package/dist/api/generators/search-parameter-enhancer.d.ts +1 -1
- package/dist/api/generators/search-parameter-enhancer.d.ts.map +1 -1
- package/dist/api/generators/search-parameter-enhancer.js +801 -0
- package/dist/api/generators/types.js +4 -0
- package/dist/api/generators/typescript.d.ts +3 -3
- package/dist/api/generators/typescript.d.ts.map +1 -1
- package/dist/api/generators/typescript.js +537 -0
- package/dist/api/generators/validation-generator.js +632 -0
- package/dist/api/index.d.ts +10 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +51 -0
- package/dist/cli/commands/generate/typescript.d.ts +1 -1
- package/dist/cli/commands/generate/typescript.d.ts.map +1 -1
- package/dist/cli/commands/generate/typescript.js +52 -0
- package/dist/cli/commands/generate.d.ts +5 -12
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +158 -0
- package/dist/cli/commands/index.d.ts +2 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +100 -0
- package/dist/cli/commands/typeschema/generate.js +130 -0
- package/dist/cli/commands/typeschema.js +48 -0
- package/dist/cli/index.js +12 -8664
- package/dist/cli/utils/log.d.ts +2 -2
- package/dist/cli/utils/log.d.ts.map +1 -1
- package/dist/cli/utils/log.js +23 -0
- package/dist/cli/utils/prompts.js +224 -0
- package/dist/cli/utils/spinner.js +270 -0
- package/dist/config.d.ts +22 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +703 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +84 -38
- package/dist/logger.js +290 -0
- package/dist/typeschema/cache.d.ts +2 -2
- package/dist/typeschema/cache.d.ts.map +1 -1
- package/dist/typeschema/cache.js +285 -0
- package/dist/typeschema/core/binding.d.ts +1 -1
- package/dist/typeschema/core/binding.d.ts.map +1 -1
- package/dist/typeschema/core/binding.js +187 -0
- package/dist/typeschema/core/field-builder.d.ts +1 -1
- package/dist/typeschema/core/field-builder.d.ts.map +1 -1
- package/dist/typeschema/core/field-builder.js +259 -0
- package/dist/typeschema/core/identifier.js +117 -0
- package/dist/typeschema/core/nested-types.d.ts +1 -1
- package/dist/typeschema/core/nested-types.d.ts.map +1 -1
- package/dist/typeschema/core/nested-types.js +111 -0
- package/dist/typeschema/core/transformer.d.ts +2 -2
- package/dist/typeschema/core/transformer.d.ts.map +1 -1
- package/dist/typeschema/core/transformer.js +345 -0
- package/dist/typeschema/generator.d.ts +3 -3
- package/dist/typeschema/generator.d.ts.map +1 -1
- package/dist/typeschema/generator.js +352 -0
- package/dist/typeschema/index.d.ts +14 -14
- package/dist/typeschema/index.d.ts.map +1 -1
- package/dist/typeschema/index.js +92 -0
- package/dist/typeschema/parser.d.ts +2 -2
- package/dist/typeschema/parser.d.ts.map +1 -1
- package/dist/typeschema/parser.js +310 -0
- package/dist/typeschema/profile/processor.d.ts +1 -1
- package/dist/typeschema/profile/processor.d.ts.map +1 -1
- package/dist/typeschema/profile/processor.js +268 -0
- package/dist/typeschema/schema.js +456 -0
- package/dist/typeschema/type-schema.types.js +39 -0
- package/dist/typeschema/types.js +4 -0
- package/dist/typeschema/utils.d.ts +1 -1
- package/dist/typeschema/utils.d.ts.map +1 -1
- package/dist/typeschema/utils.js +13 -0
- package/dist/typeschema/value-set/processor.d.ts +1 -1
- package/dist/typeschema/value-set/processor.d.ts.map +1 -1
- package/dist/typeschema/value-set/processor.js +168 -0
- package/dist/utils/codegen-logger.js +204 -0
- package/dist/utils.js +42 -0
- package/package.json +15 -4
- package/dist/index-e7pfye24.js +0 -8532
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript-specific type mapper implementation
|
|
3
|
+
*/
|
|
4
|
+
import { TypeMapper, } from "./TypeMapper.js";
|
|
5
|
+
/**
|
|
6
|
+
* TypeScript type mapper
|
|
7
|
+
*/
|
|
8
|
+
export class TypeScriptTypeMapper extends TypeMapper {
|
|
9
|
+
tsOptions;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.tsOptions = {
|
|
13
|
+
...this.options,
|
|
14
|
+
preferUnknown: true,
|
|
15
|
+
useBrandedTypes: false,
|
|
16
|
+
preferUndefined: true,
|
|
17
|
+
moduleFormat: "esm",
|
|
18
|
+
...options,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
getLanguageName() {
|
|
22
|
+
return "TypeScript";
|
|
23
|
+
}
|
|
24
|
+
mapPrimitive(fhirType) {
|
|
25
|
+
const customMapping = this.getCustomMapping(fhirType);
|
|
26
|
+
if (customMapping) {
|
|
27
|
+
return {
|
|
28
|
+
name: customMapping,
|
|
29
|
+
isPrimitive: true,
|
|
30
|
+
nullable: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const primitiveMap = {
|
|
34
|
+
string: "string",
|
|
35
|
+
integer: "number",
|
|
36
|
+
decimal: "number",
|
|
37
|
+
boolean: "boolean",
|
|
38
|
+
dateTime: "string",
|
|
39
|
+
date: "string",
|
|
40
|
+
time: "string",
|
|
41
|
+
instant: "string",
|
|
42
|
+
uri: "string",
|
|
43
|
+
url: "string",
|
|
44
|
+
canonical: "string",
|
|
45
|
+
oid: "string",
|
|
46
|
+
uuid: "string",
|
|
47
|
+
base64Binary: "string",
|
|
48
|
+
code: "string",
|
|
49
|
+
id: "string",
|
|
50
|
+
markdown: "string",
|
|
51
|
+
unsignedInt: "number",
|
|
52
|
+
positiveInt: "number",
|
|
53
|
+
xhtml: "string",
|
|
54
|
+
json: "unknown",
|
|
55
|
+
};
|
|
56
|
+
const mappedType = primitiveMap[fhirType];
|
|
57
|
+
if (!mappedType) {
|
|
58
|
+
console.warn(`Unknown FHIR primitive type: ${fhirType}`);
|
|
59
|
+
return {
|
|
60
|
+
name: this.tsOptions.preferUnknown ? "unknown" : "any",
|
|
61
|
+
isPrimitive: true,
|
|
62
|
+
nullable: false,
|
|
63
|
+
metadata: { warning: "unmapped_primitive", originalType: fhirType },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (this.tsOptions.useBrandedTypes && fhirType !== mappedType) {
|
|
67
|
+
return {
|
|
68
|
+
name: `${mappedType} & { readonly __brand: '${fhirType}' }`,
|
|
69
|
+
isPrimitive: false,
|
|
70
|
+
importPath: "./brands",
|
|
71
|
+
nullable: false,
|
|
72
|
+
metadata: { isBranded: true, originalFhirType: fhirType },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
name: mappedType,
|
|
77
|
+
isPrimitive: true,
|
|
78
|
+
nullable: false,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
mapReference(targets) {
|
|
82
|
+
if (!targets || targets.length === 0) {
|
|
83
|
+
return {
|
|
84
|
+
name: "Reference",
|
|
85
|
+
isPrimitive: false,
|
|
86
|
+
importPath: "./Reference",
|
|
87
|
+
generics: ["unknown"],
|
|
88
|
+
nullable: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (targets.length === 1) {
|
|
92
|
+
const targetName = targets[0]?.name || "unknown";
|
|
93
|
+
const targetStringLiteral = targetName === "unknown" ? "unknown" : `'${targetName}'`;
|
|
94
|
+
return {
|
|
95
|
+
name: "Reference",
|
|
96
|
+
isPrimitive: false,
|
|
97
|
+
importPath: "./Reference",
|
|
98
|
+
generics: [targetStringLiteral],
|
|
99
|
+
nullable: false,
|
|
100
|
+
metadata: {
|
|
101
|
+
referencedType: targetName,
|
|
102
|
+
referencedSchema: targets[0],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const targetStringLiterals = targets.map((t) => {
|
|
107
|
+
const targetName = t.name || "unknown";
|
|
108
|
+
return targetName === "unknown" ? "unknown" : `'${targetName}'`;
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
name: "Reference",
|
|
112
|
+
isPrimitive: false,
|
|
113
|
+
importPath: "./Reference",
|
|
114
|
+
generics: [targetStringLiterals.join(" | ")],
|
|
115
|
+
nullable: false,
|
|
116
|
+
metadata: {
|
|
117
|
+
referencedTypes: targets.map((t) => t.name || "unknown"),
|
|
118
|
+
referencedSchemas: targets,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
mapArray(elementType) {
|
|
123
|
+
if (this.options.preferArraySyntax) {
|
|
124
|
+
return {
|
|
125
|
+
name: `${elementType.name}[]`,
|
|
126
|
+
isPrimitive: elementType.isPrimitive,
|
|
127
|
+
importPath: elementType.importPath,
|
|
128
|
+
isArray: true,
|
|
129
|
+
nullable: false,
|
|
130
|
+
metadata: {
|
|
131
|
+
elementType: elementType,
|
|
132
|
+
arrayStyle: "suffix",
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return {
|
|
138
|
+
name: "Array",
|
|
139
|
+
isPrimitive: false,
|
|
140
|
+
generics: [elementType.name],
|
|
141
|
+
isArray: true,
|
|
142
|
+
nullable: false,
|
|
143
|
+
metadata: {
|
|
144
|
+
elementType: elementType,
|
|
145
|
+
arrayStyle: "generic",
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
mapOptional(type, required) {
|
|
151
|
+
if (required || !this.shouldBeNullable(required)) {
|
|
152
|
+
return type;
|
|
153
|
+
}
|
|
154
|
+
const nullType = this.tsOptions.preferUndefined ? "undefined" : "null";
|
|
155
|
+
return {
|
|
156
|
+
...type,
|
|
157
|
+
name: `${type.name} | ${nullType}`,
|
|
158
|
+
nullable: true,
|
|
159
|
+
metadata: {
|
|
160
|
+
...type.metadata,
|
|
161
|
+
nullabilityType: nullType,
|
|
162
|
+
wasOptional: true,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
mapEnum(values, name) {
|
|
167
|
+
const enumName = name ? this.formatTypeName(name) : "CodedValue";
|
|
168
|
+
const unionType = values.map((v) => `'${v}'`).join(" | ");
|
|
169
|
+
return {
|
|
170
|
+
name: unionType,
|
|
171
|
+
isPrimitive: false,
|
|
172
|
+
nullable: false,
|
|
173
|
+
metadata: {
|
|
174
|
+
enumName,
|
|
175
|
+
values,
|
|
176
|
+
isUnionType: true,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
formatTypeName(name) {
|
|
181
|
+
return this.applyNamingConvention(name);
|
|
182
|
+
}
|
|
183
|
+
formatFieldName(name) {
|
|
184
|
+
return toCamelCase(name);
|
|
185
|
+
}
|
|
186
|
+
formatFileName(name) {
|
|
187
|
+
return this.applyNamingConvention(name);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate TypeScript interface field
|
|
191
|
+
* @param fieldName Field name
|
|
192
|
+
* @param fieldType Field type
|
|
193
|
+
* @param required Whether field is required
|
|
194
|
+
*/
|
|
195
|
+
generateInterfaceField(fieldName, fieldType, required) {
|
|
196
|
+
const formattedName = this.formatFieldName(fieldName);
|
|
197
|
+
const optionalMarker = required ? "" : "?";
|
|
198
|
+
return `${formattedName}${optionalMarker}: ${fieldType.name};`;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Generate import statement for a type
|
|
202
|
+
* @param type Language type with import info
|
|
203
|
+
*/
|
|
204
|
+
generateImportStatement(type) {
|
|
205
|
+
if (!type.importPath || type.isPrimitive) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
if (this.tsOptions.moduleFormat === "esm") {
|
|
209
|
+
return `import type { ${type.name} } from '${type.importPath}';`;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
return `const { ${type.name} } = require('${type.importPath}');`;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get all required imports for a set of types
|
|
217
|
+
* @param types Array of language types
|
|
218
|
+
*/
|
|
219
|
+
getRequiredImports(types) {
|
|
220
|
+
const imports = new Set();
|
|
221
|
+
for (const type of types) {
|
|
222
|
+
const importStatement = this.generateImportStatement(type);
|
|
223
|
+
if (importStatement) {
|
|
224
|
+
imports.add(importStatement);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return Array.from(imports).sort();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function toCamelCase(str) {
|
|
231
|
+
return str.replace(/[-_\s]+(.)?/g, (_, char) => char?.toUpperCase() || "");
|
|
232
|
+
}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* Provides a fluent API for managing entire directories of files,
|
|
5
5
|
* including subdirectories, index files, and batch operations.
|
|
6
6
|
*/
|
|
7
|
-
import type { CodegenLogger } from "../../../../utils/codegen-logger";
|
|
8
|
-
import type { FileManager } from "../FileManager";
|
|
9
|
-
import type { FileBuilder } from "./FileBuilder";
|
|
10
|
-
import type { IndexBuilder } from "./IndexBuilder";
|
|
7
|
+
import type { CodegenLogger } from "../../../../utils/codegen-logger.js";
|
|
8
|
+
import type { FileManager } from "../FileManager.js";
|
|
9
|
+
import type { FileBuilder } from "./FileBuilder.js";
|
|
10
|
+
import type { IndexBuilder } from "./IndexBuilder.js";
|
|
11
11
|
export interface DirectoryBuilderConfig {
|
|
12
12
|
path: string;
|
|
13
13
|
fileManager: FileManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectoryBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/api/generators/base/builders/DirectoryBuilder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"DirectoryBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/api/generators/base/builders/DirectoryBuilder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,aAAa,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkC;IACxD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuC;IACtE,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,sBAAsB;IAI1C;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB;IAYhD;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,gBAAgB;IAO/D;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,gBAAgB;IAKlE;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,gBAAgB;IAKlD;;OAEG;IACH,KAAK,IAAI,gBAAgB;IAKzB;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKzC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAgE/B;;OAEG;IACH,WAAW,IAAI,MAAM,EAAE;IAmBvB;;OAEG;IACH,QAAQ,IAAI;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,QAAQ,EAAE,OAAO,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;KACnB;IAmBD;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IA4BzC;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACH,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC;IAIpC;;OAEG;IACH,iBAAiB,IAAI,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAIlD;;OAEG;IACH,eAAe,IAAI,YAAY,GAAG,SAAS;CAG3C"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directory builder for batch file operations
|
|
3
|
+
*
|
|
4
|
+
* Provides a fluent API for managing entire directories of files,
|
|
5
|
+
* including subdirectories, index files, and batch operations.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Fluent builder for directory operations
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Subdirectory management
|
|
12
|
+
* - Batch file operations
|
|
13
|
+
* - Index file generation
|
|
14
|
+
* - Directory cleaning
|
|
15
|
+
* - File listing for preview
|
|
16
|
+
*/
|
|
17
|
+
export class DirectoryBuilder {
|
|
18
|
+
config;
|
|
19
|
+
files = new Map();
|
|
20
|
+
subdirectories = new Map();
|
|
21
|
+
indexBuilder;
|
|
22
|
+
shouldClean = false;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.config = config;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Add a subdirectory
|
|
28
|
+
* @param name Subdirectory name
|
|
29
|
+
*/
|
|
30
|
+
withSubdirectory(name) {
|
|
31
|
+
const subdirPath = `${this.config.path}/${name}`;
|
|
32
|
+
const subdir = new DirectoryBuilder({
|
|
33
|
+
path: subdirPath,
|
|
34
|
+
fileManager: this.config.fileManager,
|
|
35
|
+
logger: this.config.logger.child(`Dir:${name}`),
|
|
36
|
+
});
|
|
37
|
+
this.subdirectories.set(name, subdir);
|
|
38
|
+
return subdir;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Add files to this directory
|
|
42
|
+
* @param files Map of filename to FileBuilder
|
|
43
|
+
*/
|
|
44
|
+
withFiles(files) {
|
|
45
|
+
for (const [filename, builder] of Object.entries(files)) {
|
|
46
|
+
this.files.set(filename, builder);
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Add a single file
|
|
52
|
+
* @param filename File name
|
|
53
|
+
* @param builder File builder
|
|
54
|
+
*/
|
|
55
|
+
withFile(filename, builder) {
|
|
56
|
+
this.files.set(filename, builder);
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set index builder for this directory
|
|
61
|
+
* @param builder Index builder
|
|
62
|
+
*/
|
|
63
|
+
withIndex(builder) {
|
|
64
|
+
this.indexBuilder = builder;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Clean directory before creating files
|
|
69
|
+
*/
|
|
70
|
+
clean() {
|
|
71
|
+
this.shouldClean = true;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Ensure directory exists
|
|
76
|
+
*/
|
|
77
|
+
async ensure() {
|
|
78
|
+
await this.config.fileManager.ensureDirectory(this.config.path);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Save all files in this directory
|
|
83
|
+
*/
|
|
84
|
+
async save() {
|
|
85
|
+
const savedPaths = [];
|
|
86
|
+
// Clean directory if requested
|
|
87
|
+
if (this.shouldClean) {
|
|
88
|
+
await this.config.fileManager.cleanDirectory(this.config.path);
|
|
89
|
+
}
|
|
90
|
+
// Ensure directory exists
|
|
91
|
+
await this.ensure();
|
|
92
|
+
// Save all files in parallel for better performance
|
|
93
|
+
const filePromises = Array.from(this.files.entries()).map(async ([filename, builder]) => {
|
|
94
|
+
try {
|
|
95
|
+
const path = await builder.save();
|
|
96
|
+
savedPaths.push(path);
|
|
97
|
+
return path;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.config.logger.error(`Failed to save file ${filename}:`, error instanceof Error ? error : undefined);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
await Promise.all(filePromises);
|
|
105
|
+
// Save subdirectories recursively
|
|
106
|
+
for (const [name, subdir] of this.subdirectories) {
|
|
107
|
+
try {
|
|
108
|
+
const subdirPaths = await subdir.save();
|
|
109
|
+
savedPaths.push(...subdirPaths);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.config.logger.error(`Failed to save subdirectory ${name}:`, error instanceof Error ? error : undefined);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Generate index if provided
|
|
117
|
+
if (this.indexBuilder) {
|
|
118
|
+
try {
|
|
119
|
+
const indexPath = await this.indexBuilder.save();
|
|
120
|
+
savedPaths.push(indexPath);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
this.config.logger.error("Failed to save index file:", error instanceof Error ? error : undefined);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
this.config.logger.info(`Saved directory ${this.config.path} with ${savedPaths.length} files`);
|
|
128
|
+
return savedPaths;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get all files that would be generated (for preview)
|
|
132
|
+
*/
|
|
133
|
+
getFileList() {
|
|
134
|
+
const files = [];
|
|
135
|
+
for (const filename of this.files.keys()) {
|
|
136
|
+
files.push(`${this.config.path}/${filename}`);
|
|
137
|
+
}
|
|
138
|
+
for (const [_name, subdir] of this.subdirectories) {
|
|
139
|
+
const subdirFiles = subdir.getFileList();
|
|
140
|
+
files.push(...subdirFiles);
|
|
141
|
+
}
|
|
142
|
+
if (this.indexBuilder) {
|
|
143
|
+
files.push(`${this.config.path}/index.ts`); // Assuming TypeScript
|
|
144
|
+
}
|
|
145
|
+
return files.sort();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get statistics about this directory
|
|
149
|
+
*/
|
|
150
|
+
getStats() {
|
|
151
|
+
let totalFiles = this.files.size;
|
|
152
|
+
for (const subdir of this.subdirectories.values()) {
|
|
153
|
+
totalFiles += subdir.getStats().totalFiles;
|
|
154
|
+
}
|
|
155
|
+
if (this.indexBuilder) {
|
|
156
|
+
totalFiles += 1;
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
fileCount: this.files.size,
|
|
160
|
+
subdirectoryCount: this.subdirectories.size,
|
|
161
|
+
hasIndex: !!this.indexBuilder,
|
|
162
|
+
totalFiles,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if directory would overwrite existing files
|
|
167
|
+
*/
|
|
168
|
+
async wouldOverwrite() {
|
|
169
|
+
const conflicts = [];
|
|
170
|
+
// Check files in this directory
|
|
171
|
+
for (const filename of this.files.keys()) {
|
|
172
|
+
const filePath = `${this.config.path}/${filename}`;
|
|
173
|
+
if (await this.config.fileManager.wouldOverwrite(filePath)) {
|
|
174
|
+
conflicts.push(filePath);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Check subdirectories
|
|
178
|
+
for (const subdir of this.subdirectories.values()) {
|
|
179
|
+
const subdirConflicts = await subdir.wouldOverwrite();
|
|
180
|
+
conflicts.push(...subdirConflicts);
|
|
181
|
+
}
|
|
182
|
+
// Check index file
|
|
183
|
+
if (this.indexBuilder) {
|
|
184
|
+
const indexPath = `${this.config.path}/index.ts`;
|
|
185
|
+
if (await this.config.fileManager.wouldOverwrite(indexPath)) {
|
|
186
|
+
conflicts.push(indexPath);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return conflicts;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get the path of this directory
|
|
193
|
+
*/
|
|
194
|
+
getPath() {
|
|
195
|
+
return this.config.path;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get all file builders (for testing/debugging)
|
|
199
|
+
*/
|
|
200
|
+
getFiles() {
|
|
201
|
+
return new Map(this.files);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get all subdirectories (for testing/debugging)
|
|
205
|
+
*/
|
|
206
|
+
getSubdirectories() {
|
|
207
|
+
return new Map(this.subdirectories);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get index builder (for testing/debugging)
|
|
211
|
+
*/
|
|
212
|
+
getIndexBuilder() {
|
|
213
|
+
return this.indexBuilder;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This provides a clean, chainable API for building files with imports,
|
|
5
5
|
* exports, content generation, and lifecycle hooks for customization.
|
|
6
6
|
*/
|
|
7
|
-
import type { CodegenLogger } from "../../../../utils/codegen-logger";
|
|
8
|
-
import type { FileManager } from "../FileManager";
|
|
7
|
+
import type { CodegenLogger } from "../../../../utils/codegen-logger.js";
|
|
8
|
+
import type { FileManager } from "../FileManager.js";
|
|
9
9
|
import type { AfterSaveHook, BeforeSaveHook, ErrorHook, FileBuilderOptions, FileContext, TemplateEngine, TypeMapper } from "../types";
|
|
10
10
|
export interface FileBuilderConfig {
|
|
11
11
|
filename: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/api/generators/base/builders/FileBuilder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"FileBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/api/generators/base/builders/FileBuilder.ts"],"names":[],"mappings":"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"}
|