Skip to content

Commit 4d90457

Browse files
committed
Rework to @atomic-ehr/codegen, setup CI.
1 parent c74d01c commit 4d90457

52 files changed

Lines changed: 1931 additions & 1532 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/sdk-tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,31 @@ jobs:
107107

108108
- name: Run tests
109109
run: make test-typescript-ccda-example
110+
111+
test-mustache-java-r4-example:
112+
runs-on: ubuntu-latest
113+
114+
strategy:
115+
matrix:
116+
bun-version: [latest]
117+
java-version: [21, 25]
118+
119+
steps:
120+
- uses: actions/checkout@v4
121+
122+
- name: Setup Bun
123+
uses: oven-sh/setup-bun@v2
124+
with:
125+
bun-version: ${{ matrix.bun-version }}
126+
127+
- name: Setup Java
128+
uses: actions/setup-java@v4
129+
with:
130+
java-version: ${{ matrix.java-version }}
131+
distribution: "temurin"
132+
133+
- name: Install dependencies
134+
run: bun install --frozen-lockfile
135+
136+
- name: Run tests
137+
run: make test-mustache-java-r4-example

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ examples/typescript-ccda/fhir-types
5050
examples/typescript-ccda/tree.yaml
5151
examples/typescript-ccda/type-schemas
5252
examples/typescript-sql-on-fhir/fhir-types
53+
54+
examples/mustache-java-r4/type-tree.yaml
55+
examples/mustache-java-r4/test-project

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ AIDBOX_LICENSE_ID ?=
22

33
TYPECHECK = bunx tsc --noEmit
44
FORMAT = bunx biome format --write
5-
LINT = bunx biome lint --diagnostic-level=error --write --unsafe
5+
LINT = bunx biome lint --diagnostic-level=error --write
66
TEST = bun test
77

88
.PHONY: all typecheck test-typeschema test-register test-codegen test-typescript-r4-example
@@ -48,10 +48,14 @@ test-typescript-r4-example: typecheck format lint
4848
$(TYPECHECK) --project tsconfig.example-typescript-r4.json
4949
cd examples/typescript-r4 && bun run demo.ts > /dev/null
5050

51+
test-mustache-java-r4-example: typecheck format lint
52+
bun run examples/mustache-java-r4/mustache-java-r4-gen.ts
53+
$(TYPECHECK) --project tsconfig.examples-mustache-java-r4.json
54+
5155
test-typescript-ccda-example: typecheck format lint
5256
$(TEST) test/unit/typeschema/transformer/ccda.test.ts
5357
bun run examples/typescript-ccda/generate.ts
54-
$(TYPECHECK) --project tsconfig.example-ccda.json
58+
# $(TYPECHECK) --project tsconfig.example-ccda.json
5559
# cd examples/typescript-r4 && bun run demo.ts > /dev/null
5660

5761
test-csharp-sdk: typecheck format prepare-aidbox-runme lint

bun.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { APIBuilder } from "../../src/api/builder";
2+
3+
if (require.main === module) {
4+
console.log("📦 Generating FHIR R4 Core Types...");
5+
6+
const builder = new APIBuilder()
7+
.verbose()
8+
.throwException()
9+
.fromPackage("hl7.fhir.r4.core", "4.0.1")
10+
.mustache({ templatePath: "./mustache/languages/java", debug: "COMPACT" })
11+
.outputTo("./examples/mustache-java-r4/test-project")
12+
.writeTypeTree("./examples/mustache-java-r4/type-tree.yaml")
13+
.cleanOutput(true);
14+
15+
const report = await builder.generate();
16+
17+
console.log(report);
18+
19+
if (report.success) {
20+
console.log("✅ FHIR R4 types generated successfully!");
21+
} else {
22+
console.error("❌ FHIR R4 types generation failed.");
23+
process.exit(1);
24+
}
25+
}

mustache/languages/java/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@
180180
"id": "String",
181181
"xhtml": "String"
182182
}
183-
}
183+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"ajv": "^8.17.1",
6767
"glob": "^12.0.0",
6868
"handlebars": "^4.7.8",
69+
"mustache": "^4.2.0",
6970
"ora": "^8.2.0",
7071
"picocolors": "^1.1.1",
7172
"yaml": "^2.8.1",
@@ -78,6 +79,7 @@
7879
"@biomejs/biome": "^2.1.4",
7980
"@types/bun": "^1.2.23",
8081
"@types/handlebars": "^4.1.0",
82+
"@types/mustache": "^4.2.6",
8183
"@types/node": "^22.17.1",
8284
"@types/yargs": "^17.0.33",
8385
"ts-prune": "^0.10.3",

src/api/builder.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import type { GeneratorInput } from "./generators/base/BaseGenerator";
2121
import { TypeScriptGenerator as TypeScriptGeneratorDepricated } from "./generators/typescript";
2222
import * as TS2 from "./writer-generator/typescript";
2323
import type { Writer, WriterOptions } from "./writer-generator/writer";
24+
import type { MustacheGeneratorOptions } from "./writer-generator/mustache";
25+
import * as Mustache from "./writer-generator/mustache";
2426

2527
/**
2628
* Configuration options for the API builder
@@ -78,10 +80,14 @@ const writerToGenerator = (writerGen: Writer): Generator => {
7880
};
7981
return {
8082
generate: async ({ index: tsIndex }: GeneratorInput): Promise<GeneratedFile[]> => {
83+
console.log("generate111111", writerGen.opts.outputDir);
8184
await writerGen.generate(tsIndex);
8285
return getGeneratedFiles();
8386
},
84-
setOutputDir: (outputDir: string) => (writerGen.opts.outputDir = outputDir),
87+
setOutputDir: (outputDir: string) => {
88+
console.log("setOutputDir", outputDir);
89+
writerGen.opts.outputDir = outputDir;
90+
},
8591
build: async (_input: unknown) => getGeneratedFiles(),
8692
};
8793
};
@@ -325,6 +331,56 @@ export class APIBuilder {
325331
return this;
326332
}
327333

334+
mustache(userOpts: Partial<MustacheGeneratorOptions>) {
335+
const defaultWriterOpts: WriterOptions = {
336+
logger: this.logger,
337+
outputDir: this.options.outputDir,
338+
tabSize: 4,
339+
withDebugComment: false,
340+
commentLinePrefix: "//",
341+
generateProfile: false,
342+
};
343+
const defaultMustacheOpts: MustacheGeneratorOptions = {
344+
...defaultWriterOpts,
345+
templatePath: "./mustache/languages/java",
346+
debug: "COMPACT",
347+
hooks: { afterGenerate: [] },
348+
meta: {
349+
timestamp: new Date().toISOString(),
350+
generator: "atomic-codegen",
351+
},
352+
filters: {
353+
resource: undefined,
354+
complexType: undefined,
355+
},
356+
sources: {
357+
templateSource: "",
358+
staticSource: "",
359+
},
360+
typeMap: {},
361+
unsaveCharacterPattern: /[^a-zA-Z0-9]/g,
362+
nameTransformations: {
363+
common: [],
364+
enumValue: [],
365+
type: [],
366+
field: [],
367+
},
368+
renderings: {
369+
utility: [],
370+
resource: [],
371+
complexType: [],
372+
},
373+
};
374+
const opts = {
375+
...defaultMustacheOpts,
376+
...Object.fromEntries(Object.entries(userOpts).filter(([_, v]) => v !== undefined)),
377+
} as MustacheGeneratorOptions;
378+
const generator = writerToGenerator(Mustache.createGenerator(opts));
379+
this.generators.set(`mustache[${opts.templatePath}]`, generator);
380+
this.logger.debug(`Configured TypeScript generator (${JSON.stringify(opts, undefined, 2)})`);
381+
return this;
382+
}
383+
328384
csharp(namespace: string, staticSourceDir?: string | undefined): APIBuilder {
329385
const generator = writerToGenerator(
330386
new CSharp({
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1+
export type CapitalizeFirst<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
12

2-
export type CapitalizeFirst<S extends string> = S extends `${infer F}${infer R}`
3-
? `${Uppercase<F>}${R}`
4-
: S;
5-
6-
export type IsPrefixed<T extends string> = `is${CapitalizeFirst<T>}`;
3+
export type IsPrefixed<T extends string> = `is${CapitalizeFirst<T>}`;
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
1-
import {DebugMixin} from "@fscg/generators/mustache/types/DebugMixin";
2-
1+
import type { DebugMixin } from "@mustache/types/DebugMixin";
32

43
export class DebugMixinProvider {
4+
constructor(private readonly mode: "FORMATTED" | "COMPACT") {}
55

6-
constructor(private readonly mode: 'FORMATTED' | 'COMPACT') {
7-
}
8-
9-
public apply<T extends Record<string, unknown>> (target: T): T & DebugMixin {
6+
public apply<T extends Record<string, unknown>>(target: T): T & DebugMixin {
107
return this._addDebug(target) as T & DebugMixin;
118
}
129

1310
private _addDebug(value: unknown): unknown {
1411
if (Array.isArray(value)) {
15-
return value.map(v => this._addDebug(v));
12+
return value.map((v) => this._addDebug(v));
1613
}
1714

1815
if (value !== null && typeof value === "object") {
1916
const obj = value as Record<string, unknown>;
2017
const result: Record<string, unknown> = {};
21-
const debugString = JSON.stringify(
22-
obj,
23-
null,
24-
this.mode === 'FORMATTED' ? 2 : undefined
25-
);
18+
const debugString = JSON.stringify(obj, null, this.mode === "FORMATTED" ? 2 : undefined);
2619
for (const [key, val] of Object.entries(obj)) {
2720
result[key] = this._addDebug(val);
2821
}
29-
result["debug"] = debugString;
22+
result.debug = debugString;
3023
return result;
3124
}
3225

3326
return value;
3427
}
35-
}
28+
}

0 commit comments

Comments
 (0)