nxpm / stack

🥭 nxpm-stack lets you generate a complete and opinionated full-stack application in a Nx Workspace, ready to extend and deploy!

Home Page:https://npm.im/@nxpm/stack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The api generator should create a structure with a different name

johannesschobel opened this issue · comments

Dear @beeman ,

i would like to have multiple nestjs apis within my monorepository. However, this is currently not possible with @nxpm/stack, because the API is automatically generated and named api.

Can we have, similar to the angular generator an additional name field to provide respective api name?

Hi @johannesschobel ,

This makes total sense. As explained in the previous issue, this is one of the shortcuts.

Currently, you can add a new API project with a new name after creating the initial project. For instance, nx g @nxpm/stack:api worker will create the same structure with worker as a name. The main issue is that the word Api is still hardcoded in some place, that should be worker.

For example, ApiCoreFeatureService should be called WorkerCoreFeatureService, and a few more like these.

So with a bit of manual work it should be pretty simple to add a new api, though it's not as fluent as it should be.

Dear @beeman , yeah that was basically what i have done. But ran into different "hardcoded" Api strings and filenames ;) That is, when i decided to document the latter in an issue

@johannesschobel this is fixed in version 4.7.3.

You can now create a new workspace and add a second API that works (serve/build).

yarn global add @nxpm/cli@latest
cd stack-v473
nx g @nxpm/stack:api worker
yarn build:worker
yarn dev:worker

I think there might be some things to keep in mind.

  • Currently the top-level .env will be picked up by both projects.
  • Property of DATABASE_URL in .env and .env.example will be updated to the latest API project
  • In package.json the property of prisma.schema will point to the latest API project you added

Those last 2 points are probably pretty easy to get around, nxpm should check if the value exists, and only add it if it's not there.

I'm not sure if the .env file being shared by both projects is fixable or if it's really an issue.

There are probably more things that I didn't see yet. I'm currently not working on any projects that need 2 API's, but feel free to add issues with the most painful issues and I can see if it's something we can address.

Dear @beeman
thank you very much for adding this feature! Will report back, if i hit any major roadblocks 😆
All the best