@atomic-ehr/codegen 0.0.1-canary.20251110160104.576d657 → 0.0.1-canary.20251112173503.8beba25
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 +15 -15
- package/dist/index.js +23 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import fs__default, { existsSync, mkdirSync } from 'fs';
|
|
3
|
-
import * as
|
|
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 Path3 from 'path';
|
|
6
|
+
import Path3__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';
|
|
@@ -2327,13 +2327,8 @@ new CodegenLogger();
|
|
|
2327
2327
|
function createLogger(options = {}) {
|
|
2328
2328
|
return new CodegenLogger(options);
|
|
2329
2329
|
}
|
|
2330
|
-
var
|
|
2331
|
-
const
|
|
2332
|
-
const packageJSON = JSON.parse(await afs3.readFile(packageJSONFileName, "utf8"));
|
|
2333
|
-
return packageJSON;
|
|
2334
|
-
};
|
|
2335
|
-
var readPackageDependencies = async (workDir, packageMeta) => {
|
|
2336
|
-
const packageJSON = await readPackageJSON(workDir, packageMeta);
|
|
2330
|
+
var readPackageDependencies = async (manager, packageMeta) => {
|
|
2331
|
+
const packageJSON = await manager.packageJson(packageMeta.name);
|
|
2337
2332
|
const dependencies = packageJSON.dependencies;
|
|
2338
2333
|
if (dependencies !== void 0) {
|
|
2339
2334
|
return Object.entries(dependencies).map(([name, version]) => {
|
|
@@ -2363,7 +2358,7 @@ var mkPackageAwareResolver = async (manager, pkg, deep, acc, logger) => {
|
|
|
2363
2358
|
if (index.canonicalResolution[url]) logger?.dry_warn(`Duplicate canonical URL: ${url} at ${pkgId}.`);
|
|
2364
2359
|
index.canonicalResolution[url] = [{ deep, pkg, pkgId, resource }];
|
|
2365
2360
|
}
|
|
2366
|
-
const deps = await readPackageDependencies(
|
|
2361
|
+
const deps = await readPackageDependencies(manager, pkg);
|
|
2367
2362
|
for (const depPkg of deps) {
|
|
2368
2363
|
const { canonicalResolution } = await mkPackageAwareResolver(manager, depPkg, deep + 1, acc, logger);
|
|
2369
2364
|
for (const [surl, resolutions] of Object.entries(canonicalResolution)) {
|
|
@@ -3042,7 +3037,7 @@ var FileSystemWriter = class {
|
|
|
3042
3037
|
}
|
|
3043
3038
|
cd(path, gen) {
|
|
3044
3039
|
const prev = this.currentDir;
|
|
3045
|
-
this.currentDir = path.startsWith("/") ?
|
|
3040
|
+
this.currentDir = path.startsWith("/") ? Path3.join(this.opts.outputDir, path) : Path3.join(this.currentDir, path);
|
|
3046
3041
|
if (!fs.existsSync(this.currentDir)) {
|
|
3047
3042
|
fs.mkdirSync(this.currentDir, { recursive: true });
|
|
3048
3043
|
}
|
|
@@ -3467,12 +3462,12 @@ var CSharp = class extends Writer {
|
|
|
3467
3462
|
}
|
|
3468
3463
|
copyStaticFiles() {
|
|
3469
3464
|
if (!this.staticSourceDir) return;
|
|
3470
|
-
const sourcePath =
|
|
3465
|
+
const sourcePath = Path3__default.resolve(this.staticSourceDir);
|
|
3471
3466
|
fs__default.cpSync(sourcePath, this.opts.outputDir, { recursive: true });
|
|
3472
3467
|
}
|
|
3473
3468
|
generateHelperFile() {
|
|
3474
3469
|
const sourceFile = "src/api/writer-generator/csharp/Helper.cs";
|
|
3475
|
-
const destFile =
|
|
3470
|
+
const destFile = Path3__default.join(this.opts.outputDir, "Helper.cs");
|
|
3476
3471
|
fs__default.copyFileSync(sourceFile, destFile);
|
|
3477
3472
|
}
|
|
3478
3473
|
};
|
|
@@ -3691,7 +3686,7 @@ var mkTypeSchemaIndex = (schemas, logger) => {
|
|
|
3691
3686
|
}
|
|
3692
3687
|
}
|
|
3693
3688
|
const raw = filename.endsWith(".yaml") ? YAML.stringify(tree) : JSON.stringify(tree, void 0, 2);
|
|
3694
|
-
await
|
|
3689
|
+
await afs2.writeFile(filename, raw);
|
|
3695
3690
|
};
|
|
3696
3691
|
return {
|
|
3697
3692
|
_schemaIndex: index,
|
|
@@ -6132,7 +6127,7 @@ var writerToGenerator = (writerGen) => {
|
|
|
6132
6127
|
const getGeneratedFiles = () => {
|
|
6133
6128
|
return writerGen.writtenFiles().map((fn) => {
|
|
6134
6129
|
return {
|
|
6135
|
-
path:
|
|
6130
|
+
path: Path3.normalize(Path3.join(writerGen.opts.outputDir, fn)),
|
|
6136
6131
|
filename: fn.replace(/^.*[\\/]/, ""),
|
|
6137
6132
|
content: "",
|
|
6138
6133
|
exports: [],
|
|
@@ -6179,7 +6174,7 @@ var cleanup = async (opts, logger) => {
|
|
|
6179
6174
|
}
|
|
6180
6175
|
};
|
|
6181
6176
|
var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) => {
|
|
6182
|
-
await
|
|
6177
|
+
await afs2.mkdir(outputDir, { recursive: true });
|
|
6183
6178
|
logger.info(`Writing TypeSchema files to ${outputDir}/...`);
|
|
6184
6179
|
const files = {};
|
|
6185
6180
|
for (const ts of typeSchemas) {
|
|
@@ -6190,7 +6185,7 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6190
6185
|
const pkgPath = normalizeFileName(packageMetaToFhir(pkg));
|
|
6191
6186
|
const name = normalizeFileName(`${ts.identifier.name}(${extractNameFromCanonical(ts.identifier.url)})`);
|
|
6192
6187
|
const json = JSON.stringify(ts, null, 2);
|
|
6193
|
-
const baseName =
|
|
6188
|
+
const baseName = Path3.join(outputDir, pkgPath, name);
|
|
6194
6189
|
if (!files[baseName]) files[baseName] = [];
|
|
6195
6190
|
if (!files[baseName]?.some((e) => e === json)) {
|
|
6196
6191
|
files[baseName].push(json);
|
|
@@ -6205,26 +6200,26 @@ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) =>
|
|
|
6205
6200
|
} else {
|
|
6206
6201
|
fullName = `${baseName}-${index}.typeschema.json`;
|
|
6207
6202
|
}
|
|
6208
|
-
await
|
|
6209
|
-
await
|
|
6203
|
+
await afs2.mkdir(Path3.dirname(fullName), { recursive: true });
|
|
6204
|
+
await afs2.writeFile(fullName, json);
|
|
6210
6205
|
})
|
|
6211
6206
|
);
|
|
6212
6207
|
}
|
|
6213
6208
|
};
|
|
6214
6209
|
var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
|
|
6215
6210
|
logger.info(`Writing TypeSchema files to: ${outputFile}`);
|
|
6216
|
-
await
|
|
6211
|
+
await afs2.mkdir(Path3.dirname(outputFile), { recursive: true });
|
|
6217
6212
|
logger.info(`Writing TypeSchemas to one file ${outputFile}...`);
|
|
6218
6213
|
for (const ts of typeSchemas) {
|
|
6219
6214
|
const json = JSON.stringify(ts, null, 2);
|
|
6220
|
-
await
|
|
6215
|
+
await afs2.appendFile(outputFile, `${json}
|
|
6221
6216
|
`);
|
|
6222
6217
|
}
|
|
6223
6218
|
};
|
|
6224
6219
|
var tryWriteTypeSchema = async (typeSchemas, opts, logger) => {
|
|
6225
6220
|
if (!opts.typeSchemaOutputDir) return;
|
|
6226
6221
|
try {
|
|
6227
|
-
if (
|
|
6222
|
+
if (Path3.extname(opts.typeSchemaOutputDir) === ".ndjson") {
|
|
6228
6223
|
await writeTypeSchemasToSingleFile(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
6229
6224
|
} else {
|
|
6230
6225
|
await writeTypeSchemasToSeparateFiles(typeSchemas, opts.typeSchemaOutputDir, logger);
|
|
@@ -6312,7 +6307,7 @@ var APIBuilder = class {
|
|
|
6312
6307
|
}
|
|
6313
6308
|
typescript(opts) {
|
|
6314
6309
|
const writerOpts = {
|
|
6315
|
-
outputDir:
|
|
6310
|
+
outputDir: Path3.join(this.options.outputDir, "/types"),
|
|
6316
6311
|
tabSize: 4,
|
|
6317
6312
|
withDebugComment: false,
|
|
6318
6313
|
commentLinePrefix: "//",
|
|
@@ -6320,14 +6315,14 @@ var APIBuilder = class {
|
|
|
6320
6315
|
};
|
|
6321
6316
|
const effectiveOpts = { logger: this.logger, ...writerOpts, ...opts };
|
|
6322
6317
|
const generator = writerToGenerator(new TypeScript(effectiveOpts));
|
|
6323
|
-
this.generators.set("
|
|
6324
|
-
this.logger.debug(`Configured
|
|
6318
|
+
this.generators.set("typescript", generator);
|
|
6319
|
+
this.logger.debug(`Configured TypeScript generator (${JSON.stringify(effectiveOpts, void 0, 2)})`);
|
|
6325
6320
|
return this;
|
|
6326
6321
|
}
|
|
6327
6322
|
csharp(namespace, staticSourceDir) {
|
|
6328
6323
|
const generator = writerToGenerator(
|
|
6329
6324
|
new CSharp({
|
|
6330
|
-
outputDir:
|
|
6325
|
+
outputDir: Path3.join(this.options.outputDir, "/types"),
|
|
6331
6326
|
staticSourceDir: staticSourceDir ?? void 0,
|
|
6332
6327
|
targetNamespace: namespace,
|
|
6333
6328
|
logger: new CodegenLogger({
|
|
@@ -6403,7 +6398,7 @@ var APIBuilder = class {
|
|
|
6403
6398
|
this.logger.info("Initialize Canonical Manager");
|
|
6404
6399
|
const manager = CanonicalManager({
|
|
6405
6400
|
packages: this.packages,
|
|
6406
|
-
workingDir: "
|
|
6401
|
+
workingDir: ".codegen-cache/canonical-manager-cache"
|
|
6407
6402
|
});
|
|
6408
6403
|
await manager.init();
|
|
6409
6404
|
const register = await registerFromManager(manager, {
|