blitz-js / blitz

⚡️ The Missing Fullstack Toolkit for Next.js
https://Blitzjs.com
MIT License
13.68k stars 798 forks source link

`blitz generate page …` creates file with raw comment #4223

Open tordans opened 1 year ago

tordans commented 1 year ago

What is the problem?

A newly generated template looks like this …

export function RegionForm<S extends z.ZodType<any, any>>(props: FormProps<S>) {
  return (
    <Form<S> {...props}>
      <LabeledTextField
        name="slug"
        label="Slug"
        placeholder="Slug"
        type="text"
      />
      {/* template: <__component__ name="__fieldName__" label="__Field_Name__" placeholder="__Field_Name__"  type="__inputType__" /> */}
    </Form>
  );
}

The part {/* template: <__component__ name="__fieldName__" label="__Field_Name__" placeholder="__Field_Name__" type="__inputType__" /> */} should either be transformed … or not be there.

It looks like this is the comment that is visible here https://github.com/blitz-js/blitz/blob/main/packages/generator/templates/form/__ModelName__Form.tsx#L11

Paste all your error logs here:

Paste all relevant code snippets here:

What are detailed steps to reproduce this?

  1. blitz generate all region slug:string:unique shortName:string name:string public:boolean=false
  2. Open the file src/regions/components/RegionForm.tsx

Run blitz -v and paste the output here:

Blitz version: 2.0.0-beta.33 (global)
Blitz version: 2.0.0-beta.33 (local)
macOS Ventura | darwin-arm64 | Node: v18.16.1

 Package manager: npm

  System:
    OS: macOS 13.6
    CPU: (8) arm64 Apple M1
    Memory: 106.03 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: Not Found
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
  npmPackages:
    @blitzjs/auth: 2.0.0-beta.33 => 2.0.0-beta.33
    @blitzjs/next: 2.0.0-beta.33 => 2.0.0-beta.33
    @blitzjs/rpc: 2.0.0-beta.33 => 2.0.0-beta.33
    @prisma/client: 5.2.0 => 5.2.0
    blitz: 2.0.0-beta.33 => 2.0.0-beta.33
    next: 13.4.5 => 13.4.5
    prisma: 5.2.0 => 5.2.0
    react: 18.2.0 => 18.2.0
    react-dom: 18.2.0 => 18.2.0
    typescript: ^4.8.4 => 4.9.5

Please include below any other applicable logs and screenshots that show your problem:

No response

tordans commented 1 year ago

Addition:

Same issue on the Schema (eg src/regions/schemas.ts), which says // template: __fieldName__: z.__zodType__(),

siddhsuresh commented 1 year ago

Hey @tordans it's meant to be there, the generator uses those comments to know where to update the file, if you choose to run the generate command again on the same modal with new fields.

tordans commented 1 year ago

@siddhsuresh oh, I see. Did not understand it as such. Can this be any text? Or could we prefix it with a more descriptive line? "Keep the following line so blitz generate can update the form later."

siddhsuresh commented 1 year ago

Hey @tordans We could improve this comment, we just use regex matching to find this and replace. Would you be interested in working on this?