Skip to content

Commit

Permalink
Don't try to copy RPC API endpoint in templates that don't have it (#…
Browse files Browse the repository at this point in the history
…3545)

* Don't try to copy RPC API endpoint in templates that don't have it
  • Loading branch information
Zeko369 authored Jul 17, 2022
1 parent 8f166a5 commit ab4d9de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-seas-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/generator": patch
---

Don't try to copy RPC API endpoint in templates that don't have it
14 changes: 10 additions & 4 deletions packages/generator/src/generators/app-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface AppGeneratorOptions extends GeneratorOptions {
form?: "React Final Form" | "React Hook Form" | "Formik"
onPostInstall?: () => Promise<void>
}

type PkgManager = "npm" | "yarn" | "pnpm"

export class AppGenerator extends Generator<AppGeneratorOptions> {
Expand Down Expand Up @@ -76,10 +77,14 @@ export class AppGenerator extends Generator<AppGeneratorOptions> {
this.destinationPath(this.options.useTs ? "package.ts.json" : "package.js.json"),
this.destinationPath("package.json"),
)
this.fs.move(
this.destinationPath(`pages/api/rpc/blitzrpcroute.${this.options.useTs ? "ts" : "js"}`),
this.destinationPath(`pages/api/rpc/[[...blitz]].${this.options.useTs ? "ts" : "js"}`),
)

const rpcEndpointPath = `pages/api/rpc/blitzrpcroute.${this.options.useTs ? "ts" : "js"}`
if (this.fs.exists(rpcEndpointPath)) {
this.fs.move(
this.destinationPath(rpcEndpointPath),
this.destinationPath(`pages/api/rpc/[[...blitz]].${this.options.useTs ? "ts" : "js"}`),
)
}

if (!this.options.template.skipForms) {
this.updateForms()
Expand Down Expand Up @@ -286,6 +291,7 @@ export class AppGenerator extends Generator<AppGeneratorOptions> {
}
commitSpinner.succeed()
}

private updateForms() {
const pkg = this.fs.readJSON(this.destinationPath("package.json")) as
| Record<string, any>
Expand Down

0 comments on commit ab4d9de

Please sign in to comment.