I received a task to see how to customize the folder structure for new apps, more precisely, nest apps. I'd a search and found that is possible to create a lib folder under the tools folder, and following patterns, I could populate a pre-created structure of files using generateFiles
from @nrwl/devkit
. The example below shows a simple structure that is used with a lib, where will change the variable names and populate the files with "__ __" in the name:
my-lib/
├── files/
├── mysql/
| ├── __originalName__.mwb
| └── schema.json
├── src/
├── index.ts__tmpl__
└── models.ts__tmpl__
Well, first of all, I would like to know if it is possible to change a new app structure while still on memory and only after that, write on the disk.
So using Nest as an example, a new nest app will look like this:
├── src/
├── app.controller.spec.ts
├── app.controller.ts
├── app.module.ts
├── app.service.ts
├── main.ts
But, let's imagine, I need to change the app.controller.ts
and app.controller.spec.ts
to a new folder and create a few other files to every new nest app. I don't have experience with nest yet.
├── src/
├── controllers/
├── app.controller.ts
├── app.controller.spec.ts
├── new.controller.ts
├── new.controller.spec.ts
├── app.module.ts
├── app.service.ts
├── main.ts
If yes for the first question, how can I achieve that? Right now I'm trying to work with generators. I run npx nx generate @nrwl/workspace:workspace-generator app-nest
which gives me a start point, but I have no idea how can I change the files.
My reference: https://nx.dev/latest/angular/generators/workspace-generators/
Yes, you are on the right track here. You can use a workspace generator to customize the files within the virtual tree. After generating your files, whether that is with an external schematic or using templates (or both) you can operate on them within the generator still acting on the virtual file system. You might try rename on the files in your tree that need to move, and you can write files from a string or Buffer.