@atomic-ehr/codegen 0.0.4-canary.20251223082214.2093b82 → 0.0.4-canary.20251223085924.a5813d1
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/cli/index.js +8 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +46 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import * as fs from 'fs';
|
|
|
3
3
|
import fs__default, { existsSync } from 'fs';
|
|
4
4
|
import * as afs2 from 'fs/promises';
|
|
5
5
|
import { readFile } from 'fs/promises';
|
|
6
|
-
import * as
|
|
7
|
-
import
|
|
6
|
+
import * as Path from 'path';
|
|
7
|
+
import Path__default, { resolve } from 'path';
|
|
8
8
|
import { CanonicalManager } from '@atomic-ehr/fhir-canonical-manager';
|
|
9
9
|
import { fileURLToPath } from 'url';
|
|
10
10
|
import assert3 from 'assert';
|
|
@@ -244,7 +244,7 @@ var FileSystemWriter = class {
|
|
|
244
244
|
}
|
|
245
245
|
cd(path, gen) {
|
|
246
246
|
const prev = this.currentDir;
|
|
247
|
-
this.currentDir = path.startsWith("/") ?
|
|
247
|
+
this.currentDir = path.startsWith("/") ? Path.join(this.opts.outputDir, path) : Path.join(this.currentDir ?? this.opts.outputDir, path);
|
|
248
248
|
this.onDiskMkDir(this.currentDir);
|
|
249
249
|
this.logger()?.debug(`cd '${this.currentDir}'`);
|
|
250
250
|
gen();
|
|
@@ -253,12 +253,16 @@ var FileSystemWriter = class {
|
|
|
253
253
|
cat(fn, gen) {
|
|
254
254
|
if (this.currentFile) throw new Error("Can't open file when another file is open");
|
|
255
255
|
if (fn.includes("/")) throw new Error(`Change file path separatly: ${fn}`);
|
|
256
|
-
const relPath =
|
|
256
|
+
const relPath = Path.normalize(`${this.currentDir}/${fn}`);
|
|
257
257
|
try {
|
|
258
258
|
const descriptor = this.onDiskOpenFile(relPath);
|
|
259
259
|
this.logger()?.debug(`cat > '${relPath}'`);
|
|
260
260
|
this.currentFile = { descriptor, relPath };
|
|
261
|
-
this.writtenFilesBuffer[this.currentFile.relPath] = {
|
|
261
|
+
this.writtenFilesBuffer[this.currentFile.relPath] = {
|
|
262
|
+
relPath,
|
|
263
|
+
absPath: Path.resolve(relPath),
|
|
264
|
+
tokens: []
|
|
265
|
+
};
|
|
262
266
|
gen();
|
|
263
267
|
} finally {
|
|
264
268
|
if (this.currentFile) this.onDiskCloseFile(this.currentFile.descriptor);
|
|
@@ -272,9 +276,21 @@ var FileSystemWriter = class {
|
|
|
272
276
|
if (!buf) throw new Error("No buffer found");
|
|
273
277
|
buf.tokens.push(str);
|
|
274
278
|
}
|
|
279
|
+
cp(source, destination) {
|
|
280
|
+
if (!this.opts.resolveAssets) throw new Error("resolveAssets is not defined");
|
|
281
|
+
source = Path.resolve(this.opts.resolveAssets(source));
|
|
282
|
+
destination = Path.normalize(`${this.currentDir ?? this.opts.outputDir}/${destination}`);
|
|
283
|
+
const content = fs.readFileSync(source, "utf8");
|
|
284
|
+
this.writtenFilesBuffer[destination] = {
|
|
285
|
+
relPath: destination,
|
|
286
|
+
absPath: Path.resolve(destination),
|
|
287
|
+
tokens: [content]
|
|
288
|
+
};
|
|
289
|
+
fs.cpSync(source, destination);
|
|
290
|
+
}
|
|
275
291
|
writtenFiles() {
|
|
276
292
|
return Object.values(this.writtenFilesBuffer).map(({ relPath, absPath, tokens }) => {
|
|
277
|
-
return { relPath, absPath, content: tokens.join() };
|
|
293
|
+
return { relPath, absPath, content: tokens.join("") };
|
|
278
294
|
}).sort((a, b) => a.relPath.localeCompare(b.relPath));
|
|
279
295
|
}
|
|
280
296
|
};
|
|
@@ -490,11 +506,11 @@ function formatName(input) {
|
|
|
490
506
|
// src/api/writer-generator/csharp/csharp.ts
|
|
491
507
|
var resolveCSharpAssets = (fn) => {
|
|
492
508
|
const __filename2 = fileURLToPath(import.meta.url);
|
|
493
|
-
const __dirname =
|
|
509
|
+
const __dirname = Path__default.dirname(__filename2);
|
|
494
510
|
if (__filename2.endsWith("dist/index.js")) {
|
|
495
|
-
return
|
|
511
|
+
return Path__default.resolve(__dirname, "..", "assets", "api", "writer-generator", "csharp", fn);
|
|
496
512
|
} else {
|
|
497
|
-
return
|
|
513
|
+
return Path__default.resolve(__dirname, "../../../..", "assets", "api", "writer-generator", "csharp", fn);
|
|
498
514
|
}
|
|
499
515
|
};
|
|
500
516
|
var PRIMITIVE_TYPE_MAP = {
|
|
@@ -562,6 +578,7 @@ var CSharp = class extends Writer {
|
|
|
562
578
|
tabSize: 4,
|
|
563
579
|
withDebugComment: false,
|
|
564
580
|
commentLinePrefix: "//",
|
|
581
|
+
resolveAssets: options.resolveAssets ?? resolveCSharpAssets,
|
|
565
582
|
...options
|
|
566
583
|
});
|
|
567
584
|
}
|
|
@@ -758,14 +775,13 @@ var CSharp = class extends Writer {
|
|
|
758
775
|
});
|
|
759
776
|
}
|
|
760
777
|
copyStaticFiles() {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
fs__default.cpSync(sourceDir, this.opts.outputDir, { recursive: true });
|
|
778
|
+
this.cp("Client.cs", "Client.cs");
|
|
779
|
+
this.cp("Helper.cs", "Helper.cs");
|
|
764
780
|
}
|
|
765
781
|
generateHelperFile() {
|
|
766
782
|
if (this.opts.inMemoryOnly) return;
|
|
767
783
|
const sourceFile = resolveCSharpAssets("Helper.cs");
|
|
768
|
-
const destFile =
|
|
784
|
+
const destFile = Path__default.join(this.opts.outputDir, "Helper.cs");
|
|
769
785
|
fs__default.copyFileSync(sourceFile, destFile);
|
|
770
786
|
}
|
|
771
787
|
};
|
|
@@ -988,7 +1004,7 @@ var mkTypeSchemaIndex = (schemas, { resolutionTree, logger }) => {
|
|
|
988
1004
|
}
|
|
989
1005
|
}
|
|
990
1006
|
const raw = filename.endsWith(".yaml") ? YAML.stringify(tree) : JSON.stringify(tree, void 0, 2);
|
|
991
|
-
await afs2.mkdir(
|
|
1007
|
+
await afs2.mkdir(Path.dirname(filename), { recursive: true });
|
|
992
1008
|
await afs2.writeFile(filename, raw);
|
|
993
1009
|
};
|
|
994
1010
|
return {
|
|
@@ -1110,18 +1126,18 @@ var deriveResourceName = (id) => {
|
|
|
1110
1126
|
return pascalCase(id.name);
|
|
1111
1127
|
};
|
|
1112
1128
|
var resolvePyAssets = (fn) => {
|
|
1113
|
-
const __dirname =
|
|
1129
|
+
const __dirname = Path.dirname(fileURLToPath(import.meta.url));
|
|
1114
1130
|
if (__filename.endsWith("dist/index.js")) {
|
|
1115
|
-
return
|
|
1131
|
+
return Path.resolve(__dirname, "..", "assets", "api", "writer-generator", "python", fn);
|
|
1116
1132
|
} else {
|
|
1117
|
-
return
|
|
1133
|
+
return Path.resolve(__dirname, "../../..", "assets", "api", "writer-generator", "python", fn);
|
|
1118
1134
|
}
|
|
1119
1135
|
};
|
|
1120
1136
|
var Python = class extends Writer {
|
|
1121
1137
|
nameFormatFunction;
|
|
1122
1138
|
tsIndex;
|
|
1123
1139
|
constructor(options) {
|
|
1124
|
-
super(options);
|
|
1140
|
+
super({ ...options, resolveAssets: options.resolveAssets ?? resolvePyAssets });
|
|
1125
1141
|
this.nameFormatFunction = this.getFieldFormatFunction(options.fieldFormat);
|
|
1126
1142
|
}
|
|
1127
1143
|
async generate(tsIndex) {
|
|
@@ -1135,7 +1151,7 @@ var Python = class extends Writer {
|
|
|
1135
1151
|
}
|
|
1136
1152
|
generateRootPackages(groups) {
|
|
1137
1153
|
this.generateRootInitFile(groups);
|
|
1138
|
-
|
|
1154
|
+
this.cp(resolvePyAssets("requirements.txt"), "requirements.txt");
|
|
1139
1155
|
}
|
|
1140
1156
|
generateSDKPackages(groups) {
|
|
1141
1157
|
this.generateComplexTypesPackages(groups.groupedComplexTypes);
|
|
@@ -2885,7 +2901,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
2885
2901
|
const pkgPath = normalizeFileName(packageMetaToFhir(pkg));
|
|
2886
2902
|
const name = normalizeFileName(`${ts.identifier.name}(${extractNameFromCanonical(ts.identifier.url)})`);
|
|
2887
2903
|
const json = JSON.stringify(ts, null, 2);
|
|
2888
|
-
const baseName =
|
|
2904
|
+
const baseName = Path.join(outputDir, pkgPath, name);
|
|
2889
2905
|
if (!files[baseName]) files[baseName] = [];
|
|
2890
2906
|
if (!files[baseName]?.some((e) => e === json)) {
|
|
2891
2907
|
files[baseName].push(json);
|
|
@@ -2900,7 +2916,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
2900
2916
|
} else {
|
|
2901
2917
|
fullName = `${baseName}-${index}.typeschema.json`;
|
|
2902
2918
|
}
|
|
2903
|
-
await afs2.mkdir(
|
|
2919
|
+
await afs2.mkdir(Path.dirname(fullName), { recursive: true });
|
|
2904
2920
|
await afs2.writeFile(fullName, json);
|
|
2905
2921
|
})
|
|
2906
2922
|
);
|
|
@@ -2908,7 +2924,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
2908
2924
|
};
|
|
2909
2925
|
var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
|
|
2910
2926
|
logger.info(`Writing TypeSchema files to: ${outputFile}`);
|
|
2911
|
-
await afs2.mkdir(
|
|
2927
|
+
await afs2.mkdir(Path.dirname(outputFile), { recursive: true });
|
|
2912
2928
|
logger.info(`Writing TypeSchemas to one file ${outputFile}...`);
|
|
2913
2929
|
for (const ts of typeSchemas) {
|
|
2914
2930
|
const json = JSON.stringify(ts, null, 2);
|
|
@@ -2919,7 +2935,7 @@ var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
|
|
|
2919
2935
|
var tryWriteTypeSchema = async (typeSchemas, opts, logger) => {
|
|
2920
2936
|
if (!opts.typeSchemaOutputDir) return;
|
|
2921
2937
|
try {
|
|
2922
|
-
if (
|
|
2938
|
+
if (Path.extname(opts.typeSchemaOutputDir) === ".ndjson") {
|
|
2923
2939
|
await writeTypeSchemasToSingleFile(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
2924
2940
|
} else {
|
|
2925
2941
|
await writeTypeSchemasToSeparateFiles(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
@@ -2982,7 +2998,7 @@ var APIBuilder = class {
|
|
|
2982
2998
|
return this;
|
|
2983
2999
|
}
|
|
2984
3000
|
localTgzPackage(archivePath) {
|
|
2985
|
-
this.localTgzArchives.push(
|
|
3001
|
+
this.localTgzArchives.push(Path.resolve(archivePath));
|
|
2986
3002
|
return this;
|
|
2987
3003
|
}
|
|
2988
3004
|
fromSchemas(schemas) {
|
|
@@ -2993,7 +3009,7 @@ var APIBuilder = class {
|
|
|
2993
3009
|
typescript(userOpts) {
|
|
2994
3010
|
const defaultWriterOpts = {
|
|
2995
3011
|
logger: this.logger,
|
|
2996
|
-
outputDir:
|
|
3012
|
+
outputDir: Path.join(this.options.outputDir, "/types"),
|
|
2997
3013
|
tabSize: 4,
|
|
2998
3014
|
withDebugComment: false,
|
|
2999
3015
|
commentLinePrefix: "//",
|
|
@@ -3038,7 +3054,7 @@ var APIBuilder = class {
|
|
|
3038
3054
|
csharp(userOptions) {
|
|
3039
3055
|
const defaultWriterOpts = {
|
|
3040
3056
|
logger: this.logger,
|
|
3041
|
-
outputDir:
|
|
3057
|
+
outputDir: Path.join(this.options.outputDir, "/types"),
|
|
3042
3058
|
tabSize: 4,
|
|
3043
3059
|
withDebugComment: false,
|
|
3044
3060
|
commentLinePrefix: "//"
|
|
@@ -3103,7 +3119,7 @@ var APIBuilder = class {
|
|
|
3103
3119
|
const result = {
|
|
3104
3120
|
success: false,
|
|
3105
3121
|
outputDir: this.options.outputDir,
|
|
3106
|
-
filesGenerated:
|
|
3122
|
+
filesGenerated: {},
|
|
3107
3123
|
errors: [],
|
|
3108
3124
|
warnings: [],
|
|
3109
3125
|
duration: 0
|
|
@@ -3195,7 +3211,9 @@ var APIBuilder = class {
|
|
|
3195
3211
|
try {
|
|
3196
3212
|
await generator.generate(tsIndex);
|
|
3197
3213
|
const fileBuffer = generator.writtenFiles();
|
|
3198
|
-
|
|
3214
|
+
fileBuffer.forEach((buf) => {
|
|
3215
|
+
result.filesGenerated[buf.relPath] = buf.content;
|
|
3216
|
+
});
|
|
3199
3217
|
this.logger.info(`Generating ${type} finished successfully`);
|
|
3200
3218
|
} catch (error) {
|
|
3201
3219
|
result.errors.push(
|