Skip to content

Commit 56a1d09

Browse files
committed
Add pretty for GenerationReport
1 parent 0f4a406 commit 56a1d09

8 files changed

Lines changed: 44 additions & 45 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ yarn add @atomic-ehr/codegen
6262
1. Write SDK generation script (`generate-types.ts`):
6363

6464
```typescript
65-
import { APIBuilder } from '@atomic-ehr/codegen';
65+
import { APIBuilder, prettyReport } from '@atomic-ehr/codegen';
6666

6767
const builder = new APIBuilder()
6868
.fromPackage("hl7.fhir.r4.core", "4.0.1")
6969
.typescript({})
7070
.outputTo("./examples/typescript-r4/fhir-types");
7171

7272
const report = await builder.generate();
73-
console.log(report);
73+
console.log(prettyReport(report));
7474
```
7575

7676
2. Run the script with:

‎examples/csharp/generate.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { APIBuilder } from "../../src";
1+
import { APIBuilder, prettyReport } from "../../src";
22

33
if (require.main === module) {
44
console.log("📦 Generating FHIR R4 Core Types...");
@@ -14,12 +14,7 @@ if (require.main === module) {
1414

1515
const report = await builder.generate();
1616

17-
console.log(report);
17+
console.log(prettyReport(report));
1818

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-
}
19+
if (!report.success) process.exit(1);
2520
}

‎examples/local-package-folder/generate.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Path from "node:path";
22
import { fileURLToPath } from "node:url";
3-
import { APIBuilder, LogLevel } from "../../src/api";
3+
import { APIBuilder, LogLevel, prettyReport } from "../../src/api";
44

55
const __dirname = Path.dirname(fileURLToPath(import.meta.url));
66

@@ -9,7 +9,7 @@ async function generateFromLocalPackageFolder() {
99
logLevel: LogLevel.INFO,
1010
});
1111

12-
await builder
12+
const report = await builder
1313
.localStructureDefinitions({
1414
package: { name: "example.folder.structures", version: "0.0.1" },
1515
path: Path.join(__dirname, "structure-definitions"),
@@ -23,6 +23,9 @@ async function generateFromLocalPackageFolder() {
2323
})
2424
.outputTo("./examples/local-package-folder")
2525
.generate();
26+
27+
console.log(prettyReport(report));
28+
if (!report.success) process.exit(1);
2629
}
2730

2831
generateFromLocalPackageFolder().catch((error) => {

‎examples/python/generate.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { APIBuilder } from "../../src";
1+
import { APIBuilder, prettyReport } from "../../src";
22

33
if (require.main === module) {
44
console.log("📦 Generating FHIR R4 Core Types...");
@@ -16,12 +16,9 @@ if (require.main === module) {
1616

1717
const report = await builder.generate();
1818

19-
console.log(report);
19+
console.log(prettyReport(report));
2020

21-
if (report.success) {
22-
console.log("✅ FHIR R4 types generated successfully!");
23-
} else {
24-
console.error("❌ FHIR R4 types generation failed.");
21+
if (!report.success) {
2522
process.exit(1);
2623
}
2724
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Run this script using Bun CLI with:
22
// bun run scripts/generate-fhir-types.ts
33

4-
import { APIBuilder } from "../../src/api/builder";
4+
import { APIBuilder, prettyReport } from "../../src/api/builder";
55

66
if (require.main === module) {
77
console.log("📦 Generating FHIR R4 Core Types...");
@@ -16,12 +16,7 @@ if (require.main === module) {
1616
.cleanOutput(true);
1717

1818
const report = await builder.generate();
19-
console.log(report);
19+
console.log(prettyReport(report));
2020

21-
if (report.success) {
22-
console.log("✅ FHIR R4 types generated successfully!");
23-
} else {
24-
console.error("❌ FHIR R4 types generation failed.");
25-
process.exit(1);
26-
}
21+
if (!report.success) process.exit(1);
2722
}

‎examples/typescript-r4/generate.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Run this script using Bun CLI with:
22
// bun run scripts/generate-fhir-types.ts
33

4-
import { APIBuilder } from "../../src/api/builder";
4+
import { APIBuilder, prettyReport } from "../../src/api/builder";
55

66
if (require.main === module) {
77
console.log("📦 Generating FHIR R4 Core Types...");
@@ -37,13 +37,6 @@ if (require.main === module) {
3737
.cleanOutput(true);
3838

3939
const report = await builder.generate();
40-
41-
console.log(report);
42-
43-
if (report.success) {
44-
console.log("✅ FHIR R4 types generated successfully!");
45-
} else {
46-
console.error("❌ FHIR R4 types generation failed.");
47-
process.exit(1);
48-
}
40+
console.log(prettyReport(report));
41+
if (!report.success) process.exit(1);
4942
}

‎src/api/builder.ts‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,33 @@ export interface APIBuilderOptions {
5959
*/
6060
export type ProgressCallback = (phase: string, current: number, total: number, message?: string) => void;
6161

62-
/**
63-
* Generation result information
64-
*/
65-
export interface GenerationResult {
62+
export type GenerationReport = {
6663
success: boolean;
6764
outputDir: string;
6865
filesGenerated: Record<string, string>;
6966
errors: string[];
7067
warnings: string[];
7168
duration: number;
72-
}
69+
};
70+
71+
export const prettyReport = (report: GenerationReport): string => {
72+
const { success, filesGenerated, errors, warnings, duration } = report;
73+
const errorsStr = errors.length > 0 ? `Errors: ${errors.join(", ")}` : undefined;
74+
const warningsStr = warnings.length > 0 ? `Warnings: ${warnings.join(", ")}` : undefined;
75+
const files = Object.entries(filesGenerated)
76+
.map(([path, content]) => ` - ${path} (${content.split("\n").length} loc)`)
77+
.join("\n");
78+
return [
79+
"Generated files:",
80+
files,
81+
errorsStr,
82+
warningsStr,
83+
`Duration: ${Math.round(duration)}ms`,
84+
`Status: ${success ? "🟩 Success" : "🟥 Failure"}`,
85+
]
86+
.filter((e) => e)
87+
.join("\n");
88+
};
7389

7490
export interface GeneratedFile {
7591
fullFileName: string;
@@ -400,9 +416,9 @@ export class APIBuilder {
400416
return this;
401417
}
402418

403-
async generate(): Promise<GenerationResult> {
419+
async generate(): Promise<GenerationReport> {
404420
const startTime = performance.now();
405-
const result: GenerationResult = {
421+
const result: GenerationReport = {
406422
success: false,
407423
outputDir: this.options.outputDir,
408424
filesGenerated: {},
@@ -512,7 +528,7 @@ export class APIBuilder {
512528
return Array.from(this.generators.keys());
513529
}
514530

515-
private async executeGenerators(result: GenerationResult, tsIndex: TypeSchemaIndex): Promise<void> {
531+
private async executeGenerators(result: GenerationReport, tsIndex: TypeSchemaIndex): Promise<void> {
516532
for (const [type, generator] of this.generators.entries()) {
517533
this.logger.info(`Generating ${type}...`);
518534

‎src/api/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
export { LogLevel } from "../utils/codegen-logger";
1111
export type { APIBuilderOptions, LocalStructureDefinitionConfig } from "./builder";
12-
export { APIBuilder } from "./builder";
12+
export { APIBuilder, prettyReport } from "./builder";
1313
export type { CSharpGeneratorOptions } from "./writer-generator/csharp/csharp";
1414
export type { TypeScriptOptions } from "./writer-generator/typescript";

0 commit comments

Comments
 (0)