Skip to content

Commit

Permalink
feat(fhir-ts-codegen): generate barrel
Browse files Browse the repository at this point in the history
Generates a barrel for the generated types to expose a single entry
point.
  • Loading branch information
tangdrew committed Feb 20, 2019
1 parent 6f46af6 commit cafcd26
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/fhir-ts-codegen/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface File {

export class Generator {
public configuration = {
barrel: true,
fromDifferential: true,
singleFile: false
};
Expand Down Expand Up @@ -66,7 +67,11 @@ export class Generator {
* Generates code from StructureDefinitions based on configuration
*/
private generate = (structureDefinitions: StructureDefinition[]): File[] => {
return structureDefinitions.map(this.renderModule);
const code = structureDefinitions.map(this.renderModule);
if (this.configuration.barrel) {
return [...code, this.generateBarrel(structureDefinitions)];
}
return code;
};

/**
Expand Down Expand Up @@ -196,4 +201,19 @@ export class Generator {
${propertyName}: ${typeName}`;
});
};

/**
* Generates TypeScript barrel code for the module
*/
private generateBarrel = (
structureDefinitions: StructureDefinition[]
): File => {
const code = structureDefinitions
.map(({ name }) => `export { ${name} } from "./${name}";`)
.join("\n");
return {
code,
name: "index"
};
};
}

0 comments on commit cafcd26

Please sign in to comment.