@atomic-ehr/codegen 0.0.2-canary.20251114095108.8d8e927 → 0.0.2-canary.20251114125643.cb2d5e2
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 +17 -17
- package/dist/index.js +14 -13
- 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 {
|
|
@@ -5944,7 +5945,7 @@ var TypeScript = class extends Writer {
|
|
|
5944
5945
|
const tsName2 = tsFieldName(fieldName);
|
|
5945
5946
|
let tsType;
|
|
5946
5947
|
if (field.enum) {
|
|
5947
|
-
tsType = field.enum.map((e) => `'${e}'`).join(" | ")
|
|
5948
|
+
tsType = `(${field.enum.map((e) => `'${e}'`).join(" | ")})`;
|
|
5948
5949
|
} else if (field.reference && field.reference.length > 0) {
|
|
5949
5950
|
const specialization = tsIndex.findLastSpecialization(flatProfile);
|
|
5950
5951
|
if (!isSpecializationTypeSchema(specialization))
|
|
@@ -6126,7 +6127,7 @@ var writerToGenerator = (writerGen) => {
|
|
|
6126
6127
|
const getGeneratedFiles = () => {
|
|
6127
6128
|
return writerGen.writtenFiles().map((fn) => {
|
|
6128
6129
|
return {
|
|
6129
|
-
path:
|
|
6130
|
+
path: Path4.normalize(Path4.join(writerGen.opts.outputDir, fn)),
|
|
6130
6131
|
filename: fn.replace(/^.*[\\/]/, ""),
|
|
6131
6132
|
content: "",
|
|
6132
6133
|
exports: [],
|
|
@@ -6184,7 +6185,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6184
6185
|
const pkgPath = normalizeFileName(packageMetaToFhir(pkg));
|
|
6185
6186
|
const name = normalizeFileName(`${ts.identifier.name}(${extractNameFromCanonical(ts.identifier.url)})`);
|
|
6186
6187
|
const json = JSON.stringify(ts, null, 2);
|
|
6187
|
-
const baseName =
|
|
6188
|
+
const baseName = Path4.join(outputDir, pkgPath, name);
|
|
6188
6189
|
if (!files[baseName]) files[baseName] = [];
|
|
6189
6190
|
if (!files[baseName]?.some((e) => e === json)) {
|
|
6190
6191
|
files[baseName].push(json);
|
|
@@ -6199,7 +6200,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6199
6200
|
} else {
|
|
6200
6201
|
fullName = `${baseName}-${index}.typeschema.json`;
|
|
6201
6202
|
}
|
|
6202
|
-
await afs2.mkdir(
|
|
6203
|
+
await afs2.mkdir(Path4.dirname(fullName), { recursive: true });
|
|
6203
6204
|
await afs2.writeFile(fullName, json);
|
|
6204
6205
|
})
|
|
6205
6206
|
);
|
|
@@ -6207,7 +6208,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6207
6208
|
};
|
|
6208
6209
|
var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
|
|
6209
6210
|
logger.info(`Writing TypeSchema files to: ${outputFile}`);
|
|
6210
|
-
await afs2.mkdir(
|
|
6211
|
+
await afs2.mkdir(Path4.dirname(outputFile), { recursive: true });
|
|
6211
6212
|
logger.info(`Writing TypeSchemas to one file ${outputFile}...`);
|
|
6212
6213
|
for (const ts of typeSchemas) {
|
|
6213
6214
|
const json = JSON.stringify(ts, null, 2);
|
|
@@ -6218,7 +6219,7 @@ var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
|
|
|
6218
6219
|
var tryWriteTypeSchema = async (typeSchemas, opts, logger) => {
|
|
6219
6220
|
if (!opts.typeSchemaOutputDir) return;
|
|
6220
6221
|
try {
|
|
6221
|
-
if (
|
|
6222
|
+
if (Path4.extname(opts.typeSchemaOutputDir) === ".ndjson") {
|
|
6222
6223
|
await writeTypeSchemasToSingleFile(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
6223
6224
|
} else {
|
|
6224
6225
|
await writeTypeSchemasToSeparateFiles(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
@@ -6310,7 +6311,7 @@ var APIBuilder = class {
|
|
|
6310
6311
|
}
|
|
6311
6312
|
typescript(opts) {
|
|
6312
6313
|
const writerOpts = {
|
|
6313
|
-
outputDir:
|
|
6314
|
+
outputDir: Path4.join(this.options.outputDir, "/types"),
|
|
6314
6315
|
tabSize: 4,
|
|
6315
6316
|
withDebugComment: false,
|
|
6316
6317
|
commentLinePrefix: "//",
|
|
@@ -6326,7 +6327,7 @@ var APIBuilder = class {
|
|
|
6326
6327
|
csharp(namespace, staticSourceDir) {
|
|
6327
6328
|
const generator = writerToGenerator(
|
|
6328
6329
|
new CSharp({
|
|
6329
|
-
outputDir:
|
|
6330
|
+
outputDir: Path4.join(this.options.outputDir, "/types"),
|
|
6330
6331
|
staticSourceDir: staticSourceDir ?? void 0,
|
|
6331
6332
|
targetNamespace: namespace,
|
|
6332
6333
|
logger: new CodegenLogger({
|