Tahul / nuxt-edgedb

💽 Nuxt 3 integration for EdgeDB
70 stars 7 forks source link

Query builder generator gets stuck on prompt #12

Open juni0r opened 9 months ago

juni0r commented 9 months ago

The generateQueryBuilder method runs @edgedb/generate edgeql-js but if the generated folder doesn't exist will prompt the user to add it to .gitignore. Since by default generation is quiet, server startup gets stuck at this point. It will work subsequently as soon as the folder has been created.

To fix this, the command needs to be invoked with yes n, like so: yes n | @edgedb/generate edgeql-js [...] to dismiss the prompt. I think this should be easy with execa, similar to this example.

I'd also suggest that even in quiet mode, there should be one line per generator to give some status information, which isn't exactly verbose but still gives useful feedback. Like so:

Generating EdgeDb queries.
Generating EdgeDb query builder.
...

The quiet option could become 'verbose' and show the full output of the generators.

Tahul commented 9 months ago

Excellent suggestion, prompts while the Nuxt server is running is quite a tricky context, but seem to work.

I will apply the fix you suggest in next release, do you have any other suggestions over the generate commands?

juni0r commented 9 months ago

Since you asked, I like the batteries-included-approach with running generators etc. automatically and even installing / setting up EdgeDB if it isnt' configured yet.

It seems to me though, that doing this every time the module is loaded might not be the best place to do it. Sure, there's the possibility to disable generation with flags but the workflow is a bit cumbersome. Edit my schema, set generate-flags to true in nuxt.config.js, starting the server and setting them back to false again (same goes for projectInit and installCli).

But what would be a better place to put it? Maybe adding a bin script to the npm package might be an option, like nuxt-edgedb with sub-commands like generate and setup.

You could still perform some checks during module setup (like checking if the EdgeDB project has been initialized or if env variables are set and issue warnings and provide hints, like 'No EdgeDB installation found in current project. Run nuxt-edgedb setup.'