Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(codegen): Add indexes and generate on create app (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored May 25, 2022
1 parent 5a8141e commit a55cb92
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/commands/create-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { zipObject } from 'lodash';

import { AppAction } from '../../src/app/app.interface';
import { generateAppDefinition } from '../generators/generate-app-definition';
import { generateAppIndex } from '../generators/generate-app-index';
import { generateAppModule } from '../generators/generate-app-module';
import {
promptAppDescription,
Expand Down Expand Up @@ -40,6 +41,7 @@ export default class CreateApp extends Command {
}

await generateAppModule(appId);
await generateAppIndex(appId);
await generateAppDefinition({
id: appId,
name: appName,
Expand Down
21 changes: 21 additions & 0 deletions cli/generators/generate-app-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import dedent from 'dedent';
import * as recast from 'recast';

import { strings } from '../strings';

import { formatAndWrite } from './utils';

export async function generateAppIndex(appId: string) {
const appDefinitionName = `${strings.upperCase(appId)}_DEFINITION`;
const appClassName = strings.titleCase(appId);

const content = dedent`
export { ${appDefinitionName}, ${appClassName}AppDefinition } from './${appId}.definition';
export { ${appClassName}AppModule } from './${appId}.module';
export { ${appClassName}ContractFactory } from './contracts';
`;

const ast = recast.parse(content, { parser: require('recast/parsers/typescript') });
const prettyContent = recast.prettyPrint(ast).code;
await formatAndWrite(`./src/apps/${appId}/index.ts`, prettyContent);
}
2 changes: 2 additions & 0 deletions src/apps/rari-fuse/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { RARI_FUSE_DEFINITION, RariFuseAppDefinition } from './rari-fuse.definition';
export { RariFuseContractFactory } from './contracts';
2 changes: 2 additions & 0 deletions src/apps/saddle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { SADDLE_DEFINITION, SaddleAppDefinition } from './saddle.definition';
export { SaddleContractFactory } from './contracts';

0 comments on commit a55cb92

Please sign in to comment.