sailscastshq / boring-stack

Ship JavaScript products with battle-tested technologies in days not weeks.
https://docs.sailscasts.com/boring-stack/getting-started
MIT License
390 stars 19 forks source link

Add create-sails-generator #95

Closed DominusKelvin closed 5 months ago

DominusKelvin commented 5 months ago

As I continue to work on Sails.js projects within The Boring JavaScript Stack, I've encountered challenges in maintaining development efficiency and consistency across our codebase. In an effort to address these issues, I am proposing the introduction of create-sails-generator, a tool tailored specifically for development in The Boring JavaScript Stack.

With the introduction of create-sails-generator you should be able to run:

sails generate page dashboard

And a file will be created in assets/js/pages for you. If you are using React it should create a dashboard.js, and if you are using Vue, it should create dashboard.vue, etc.

Also for things like the responses/inertia.js response we can evolve these responses by letting create-sails-generator expose commands for you to get the latest changes by running sails generate response inertia for example.

The sky is the limit to the codegen we can do with this generator in order to improve the DX of working with TBJS.

Let me know what you all think.

lennyAiko commented 5 months ago

I love the idea of generators, been craving it for a while because I have tons of similar pages.

We also have to look at generators for actions.

sails generate controller create-dashboard

I just mentioned 'controller' since action is being used already

To get something like this in the exits:

exits: {
     success: {
          responseType: 'inertia' or 'inertiaRedirect',
          description: 'this is description'
     },
}

I have a few questions in mind:

These are just a few things are the top of my head, more to come as we proceed.

@DominusKelvin

DominusKelvin commented 5 months ago

Hey @lennyAiko for the name I chose create-sails-generator because we already have create-sails which is the master of ceremony to scaffold a new Boring Stack project.

And for the how create-sails-generator will detect what UI you are using its quite simple: we can check package.json

sails generate api Products sound like fun but I think I can do one better.

And yes the generator can put in the response type as that's one of the reason why I'm working on it, it will also smartly try to guess the page you want to point to. Should be fun.

lennyAiko commented 5 months ago

Indeed, this is fun. @DominusKelvin

DominusKelvin commented 5 months ago

I had to pause working on this for a day or two to give myself that fallowing time to think of the API I want. So far I want the command to be page-centric even when you want to create an action. Let me know what you think @lennyAiko

CleanShot 2024-03-29 at 09 51 27@2x

DominusKelvin commented 5 months ago

CleanShot 2024-03-29 at 11 44 51@2x Started off with the generators to evolve the responses so you don't have to copy and paste all the time.

lennyAiko commented 5 months ago

I had to pause working on this for a day or two to give myself that fallowing time to think of the API I want. So far I want the command to be page-centric even when you want to create an action. Let me know what you think @lennyAiko

CleanShot 2024-03-29 at 09 51 27@2x

So basically, even the actions will be generated based on the page? It makes things more straightforward, and it will reduce the number of commands to run.

However, will there be a separate API to generate actions separately? Say I need to generate an action for delete or other similar actions that do not necessarily require a page.

DominusKelvin commented 5 months ago

I had to pause working on this for a day or two to give myself that fallowing time to think of the API I want. So far I want the command to be page-centric even when you want to create an action. Let me know what you think @lennyAiko CleanShot 2024-03-29 at 09 51 27@2x

So basically, even the actions will be generated based on the page? It makes things more straightforward, and it will reduce the number of commands to run.

However, will there be a separate API to generate actions separately? Say I need to generate an action for delete or other similar actions that do not necessarily require a page.

Yeah so for that you can rely on the sails generate action. For this version of create-sails-generator. I am assuming creating page with accompanying action.

lennyAiko commented 5 months ago

I had to pause working on this for a day or two to give myself that fallowing time to think of the API I want. So far I want the command to be page-centric even when you want to create an action. Let me know what you think @lennyAiko CleanShot 2024-03-29 at 09 51 27@2x

So basically, even the actions will be generated based on the page? It makes things more straightforward, and it will reduce the number of commands to run. However, will there be a separate API to generate actions separately? Say I need to generate an action for delete or other similar actions that do not necessarily require a page.

Yeah so for that you can rely on the sails generate action. For this version of create-sails-generator. I am assuming creating page with accompanying action.

That's really nice!

That means we if we are still going to rely on sails generate action we will need to generate those responses and manually add them to exit.

DominusKelvin commented 5 months ago

Yes @lennyAiko it's a trade off.