@atomic-ehr/codegen 0.0.2-canary.20251114095108.8d8e927 → 0.0.2-canary.20251114133113.0a35a8a
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 +20 -20
- package/dist/index.js +25 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import * as fs from 'fs';
|
|
|
2
2
|
import fs__default, { existsSync, mkdirSync } from 'fs';
|
|
3
3
|
import * as afs2 from 'fs/promises';
|
|
4
4
|
import { readdir, stat, unlink, readFile, writeFile, access, mkdir, rm } from 'fs/promises';
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
5
|
+
import * as Path4 from 'path';
|
|
6
|
+
import Path4__default, { join, resolve, dirname, relative } from 'path';
|
|
7
7
|
import { CanonicalManager } from '@atomic-ehr/fhir-canonical-manager';
|
|
8
8
|
import * as fhirschema from '@atomic-ehr/fhirschema';
|
|
9
9
|
import { isStructureDefinition } from '@atomic-ehr/fhirschema';
|
|
@@ -3036,7 +3036,7 @@ var FileSystemWriter = class {
|
|
|
3036
3036
|
}
|
|
3037
3037
|
cd(path, gen) {
|
|
3038
3038
|
const prev = this.currentDir;
|
|
3039
|
-
this.currentDir = path.startsWith("/") ?
|
|
3039
|
+
this.currentDir = path.startsWith("/") ? Path4.join(this.opts.outputDir, path) : Path4.join(this.currentDir, path);
|
|
3040
3040
|
if (!fs.existsSync(this.currentDir)) {
|
|
3041
3041
|
fs.mkdirSync(this.currentDir, { recursive: true });
|
|
3042
3042
|
}
|
|
@@ -3461,12 +3461,12 @@ var CSharp = class extends Writer {
|
|
|
3461
3461
|
}
|
|
3462
3462
|
copyStaticFiles() {
|
|
3463
3463
|
if (!this.staticSourceDir) return;
|
|
3464
|
-
const sourcePath =
|
|
3464
|
+
const sourcePath = Path4__default.resolve(this.staticSourceDir);
|
|
3465
3465
|
fs__default.cpSync(sourcePath, this.opts.outputDir, { recursive: true });
|
|
3466
3466
|
}
|
|
3467
3467
|
generateHelperFile() {
|
|
3468
3468
|
const sourceFile = "src/api/writer-generator/csharp/Helper.cs";
|
|
3469
|
-
const destFile =
|
|
3469
|
+
const destFile = Path4__default.join(this.opts.outputDir, "Helper.cs");
|
|
3470
3470
|
fs__default.copyFileSync(sourceFile, destFile);
|
|
3471
3471
|
}
|
|
3472
3472
|
};
|
|
@@ -3685,6 +3685,7 @@ var mkTypeSchemaIndex = (schemas, logger) => {
|
|
|
3685
3685
|
}
|
|
3686
3686
|
}
|
|
3687
3687
|
const raw = filename.endsWith(".yaml") ? YAML.stringify(tree) : JSON.stringify(tree, void 0, 2);
|
|
3688
|
+
await afs2.mkdir(Path4.dirname(filename), { recursive: true });
|
|
3688
3689
|
await afs2.writeFile(filename, raw);
|
|
3689
3690
|
};
|
|
3690
3691
|
return {
|
|
@@ -5807,17 +5808,22 @@ var TypeScript = class extends Writer {
|
|
|
5807
5808
|
}
|
|
5808
5809
|
generateFhirPackageIndexFile(schemas) {
|
|
5809
5810
|
this.cat("index.ts", () => {
|
|
5810
|
-
let exports = schemas.
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5811
|
+
let exports = schemas.flatMap((schema) => [
|
|
5812
|
+
{
|
|
5813
|
+
identifier: schema.identifier,
|
|
5814
|
+
tsPackageName: tsModuleName(schema.identifier),
|
|
5815
|
+
resourceName: tsResourceName(schema.identifier),
|
|
5816
|
+
nestedTypes: isResourceTypeSchema(schema) && schema.nested ? schema.nested.map((n) => tsResourceName(n.identifier)) : []
|
|
5817
|
+
}
|
|
5818
|
+
]).sort((a, b) => a.resourceName.localeCompare(b.resourceName));
|
|
5815
5819
|
exports = Array.from(new Map(exports.map((exp) => [exp.resourceName.toLowerCase(), exp])).values()).sort(
|
|
5816
5820
|
(a, b) => a.resourceName.localeCompare(b.resourceName)
|
|
5817
5821
|
);
|
|
5818
5822
|
for (const exp of exports) {
|
|
5819
5823
|
this.debugComment(exp.identifier);
|
|
5820
|
-
this.lineSM(
|
|
5824
|
+
this.lineSM(
|
|
5825
|
+
`export type { ${[exp.resourceName, ...exp.nestedTypes].join(", ")} } from "./${exp.tsPackageName}"`
|
|
5826
|
+
);
|
|
5821
5827
|
}
|
|
5822
5828
|
});
|
|
5823
5829
|
}
|
|
@@ -5944,7 +5950,7 @@ var TypeScript = class extends Writer {
|
|
|
5944
5950
|
const tsName2 = tsFieldName(fieldName);
|
|
5945
5951
|
let tsType;
|
|
5946
5952
|
if (field.enum) {
|
|
5947
|
-
tsType = field.enum.map((e) => `'${e}'`).join(" | ")
|
|
5953
|
+
tsType = `(${field.enum.map((e) => `'${e}'`).join(" | ")})`;
|
|
5948
5954
|
} else if (field.reference && field.reference.length > 0) {
|
|
5949
5955
|
const specialization = tsIndex.findLastSpecialization(flatProfile);
|
|
5950
5956
|
if (!isSpecializationTypeSchema(specialization))
|
|
@@ -6126,7 +6132,7 @@ var writerToGenerator = (writerGen) => {
|
|
|
6126
6132
|
const getGeneratedFiles = () => {
|
|
6127
6133
|
return writerGen.writtenFiles().map((fn) => {
|
|
6128
6134
|
return {
|
|
6129
|
-
path:
|
|
6135
|
+
path: Path4.normalize(Path4.join(writerGen.opts.outputDir, fn)),
|
|
6130
6136
|
filename: fn.replace(/^.*[\\/]/, ""),
|
|
6131
6137
|
content: "",
|
|
6132
6138
|
exports: [],
|
|
@@ -6184,7 +6190,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6184
6190
|
const pkgPath = normalizeFileName(packageMetaToFhir(pkg));
|
|
6185
6191
|
const name = normalizeFileName(`${ts.identifier.name}(${extractNameFromCanonical(ts.identifier.url)})`);
|
|
6186
6192
|
const json = JSON.stringify(ts, null, 2);
|
|
6187
|
-
const baseName =
|
|
6193
|
+
const baseName = Path4.join(outputDir, pkgPath, name);
|
|
6188
6194
|
if (!files[baseName]) files[baseName] = [];
|
|
6189
6195
|
if (!files[baseName]?.some((e) => e === json)) {
|
|
6190
6196
|
files[baseName].push(json);
|
|
@@ -6199,7 +6205,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6199
6205
|
} else {
|
|
6200
6206
|
fullName = `${baseName}-${index}.typeschema.json`;
|
|
6201
6207
|
}
|
|
6202
|
-
await afs2.mkdir(
|
|
6208
|
+
await afs2.mkdir(Path4.dirname(fullName), { recursive: true });
|
|
6203
6209
|
await afs2.writeFile(fullName, json);
|
|
6204
6210
|
})
|
|
6205
6211
|
);
|
|
@@ -6207,7 +6213,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6207
6213
|
};
|
|
6208
6214
|
var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
|
|
6209
6215
|
logger.info(`Writing TypeSchema files to: ${outputFile}`);
|
|
6210
|
-
await afs2.mkdir(
|
|
6216
|
+
await afs2.mkdir(Path4.dirname(outputFile), { recursive: true });
|
|
6211
6217
|
logger.info(`Writing TypeSchemas to one file ${outputFile}...`);
|
|
6212
6218
|
for (const ts of typeSchemas) {
|
|
6213
6219
|
const json = JSON.stringify(ts, null, 2);
|
|
@@ -6218,7 +6224,7 @@ var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
|
|
|
6218
6224
|
var tryWriteTypeSchema = async (typeSchemas, opts, logger) => {
|
|
6219
6225
|
if (!opts.typeSchemaOutputDir) return;
|
|
6220
6226
|
try {
|
|
6221
|
-
if (
|
|
6227
|
+
if (Path4.extname(opts.typeSchemaOutputDir) === ".ndjson") {
|
|
6222
6228
|
await writeTypeSchemasToSingleFile(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
6223
6229
|
} else {
|
|
6224
6230
|
await writeTypeSchemasToSeparateFiles(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
@@ -6310,7 +6316,7 @@ var APIBuilder = class {
|
|
|
6310
6316
|
}
|
|
6311
6317
|
typescript(opts) {
|
|
6312
6318
|
const writerOpts = {
|
|
6313
|
-
outputDir:
|
|
6319
|
+
outputDir: Path4.join(this.options.outputDir, "/types"),
|
|
6314
6320
|
tabSize: 4,
|
|
6315
6321
|
withDebugComment: false,
|
|
6316
6322
|
commentLinePrefix: "//",
|
|
@@ -6326,7 +6332,7 @@ var APIBuilder = class {
|
|
|
6326
6332
|
csharp(namespace, staticSourceDir) {
|
|
6327
6333
|
const generator = writerToGenerator(
|
|
6328
6334
|
new CSharp({
|
|
6329
|
-
outputDir:
|
|
6335
|
+
outputDir: Path4.join(this.options.outputDir, "/types"),
|
|
6330
6336
|
staticSourceDir: staticSourceDir ?? void 0,
|
|
6331
6337
|
targetNamespace: namespace,
|
|
6332
6338
|
logger: new CodegenLogger({
|