Skip to content

Commit

Permalink
chore(contented-processor): generate basic index.d.ts for `${type}I…
Browse files Browse the repository at this point in the history
…ndex` (#524)

#### What this PR does / why we need it:

Generate basic types for ${type}Index for better DX when working with
`contented build`.
  • Loading branch information
fuxingloh authored Jul 21, 2023
1 parent f7441f6 commit ba041ad
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/contented-processor/src/ContentedCodegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class ContentedCodegen {
async generateIndex() {
const types = this.config.pipelines.map((pipeline) => pipeline.type);
const ast = generateIndexAST([...new Set(types)]);
const outPath = join(this.outPath, `index.js`);
await fs.mkdir(this.outPath, { recursive: true });
await fs.writeFile(outPath, generate(ast).code);
await fs.writeFile(join(this.outPath, `index.js`), generate(ast).code);
await fs.writeFile(join(this.outPath, `index.d.ts`), generateTypes(types));
}

async generatePipeline(type: string, contents: FileIndex[]) {
Expand Down Expand Up @@ -204,3 +204,7 @@ function generate(ast: any) {
const gen = new CodeGenerator(ast);
return gen.generate();
}

function generateTypes(types: string[]): string {
return types.map((type) => `export declare const ${type}Index: FileIndex[];`).join('\n');
}

0 comments on commit ba041ad

Please sign in to comment.