Skip to content

Commit

Permalink
update codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOlias committed Nov 9, 2023
1 parent 2ecf2f7 commit c2eb371
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 107 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/Ponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ export class Ponder {
// using the initial config, register service dependencies.
this.registerServiceDependencies();

// Regenerate the `ponder-env.d.ts` file in case it was deleted.
this.codegenService.generateDeclarationFile();

// One-time setup for some services.
await this.syncStore.migrateUp();
await this.serverService.start();
Expand Down Expand Up @@ -236,6 +239,8 @@ export class Ponder {
}

async codegen() {
this.codegenService.generateDeclarationFile();

const result = await this.buildService.loadSchema();
if (result) {
const { graphqlSchema } = result;
Expand Down
44 changes: 0 additions & 44 deletions packages/core/src/codegen/event.ts

This file was deleted.

25 changes: 0 additions & 25 deletions packages/core/src/codegen/prettier.ts

This file was deleted.

33 changes: 0 additions & 33 deletions packages/core/src/codegen/service.test.ts

This file was deleted.

33 changes: 33 additions & 0 deletions packages/core/src/codegen/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,39 @@ export class CodegenService extends Emittery {
this.common = common;
}

generateDeclarationFile() {
const getImportPath = (file: string) => {
let relative = path.relative(this.common.options.rootDir, file);

// If the file is in the same directory, prepend with "./"
if (!relative.startsWith("..") && !path.isAbsolute(relative))
relative = `./${relative}`;

return relative;
};

const configPath = getImportPath(this.common.options.configFile);
const schemaPath = getImportPath(this.common.options.schemaFile);

const contents = `declare module "@/generated" {
import type { PonderApp } from "@ponder/core";
export const ponder: PonderApp<
typeof import("${configPath}").config,
typeof import("${schemaPath}").schema
>;
}
`;

const filePath = path.join(this.common.options.rootDir, "ponder-env.d.ts");
writeFileSync(filePath, contents, "utf8");

this.common.logger.debug({
service: "codegen",
msg: `Generated ponder-env.d.ts`,
});
}

generateGraphqlSchemaFile({
graphqlSchema,
}: {
Expand Down
27 changes: 22 additions & 5 deletions packages/create-ponder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ export const run = async (
"resolveJsonModule": true,
"esModuleInterop": true,
"strict": true,
"rootDir": ".",
"paths": {
"@/generated": ["./generated/index.ts"]
}
"rootDir": "."
},
"include": ["./**/*.ts"],
"exclude": ["node_modules"]
Expand All @@ -241,7 +238,27 @@ export const run = async (
// Write the .gitignore file.
writeFileSync(
path.join(rootDir, ".gitignore"),
`node_modules/\n.DS_Store\n\n.env.local\n.ponder/\ngenerated/`
`# Dependencies
/node_modules
# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# Misc
.DS_Store
# Env files
.env*.local
# Ponder
/.next/
/generated/
# TypeScript
ponder-env.d.ts`
);

const packageManager = await getPackageManager();
Expand Down

0 comments on commit c2eb371

Please sign in to comment.