0

I want to create an Angular Schematics to create some components and make it easier to develop my application. The problem is that i don't want to publish it, i want to use it "as it is" in my project. Basically my project have this structure :

- dist
- nodes_modules
- projects 
        - lib-common
        - lib-user
        - lib-XXX
        - ...
- src
...

And i want to do that structure :

- dist
- nodes_modules
- projects 
        - lib-common
                - schematics
        - lib-user
        - lib-XXX
        - ...
- src
...

My goal is to develop in other libs (like lib-user for ex) and use the schematics created in lib-common > schematics.

For information the schematics i'm trying to create is a schematic that will create several components, kind of like what the command ng generate component XXX does.

I read a lot about schematics, and i understand how they work. But i can't understand how to build them (and if it is necessary ?) or how to use them. I very lost because the structure of my project is complex: The main application have package.json, the library also, do the schematic also need one ? What about nodes_modules ?

For now, every tutorial i read told me to build my application and schematics seperatly, and i managed to do that and export the built schematic to the dist folder, but i don't know how to user it because the tutorial told me to publish it and i don't want to do that.

Every information you have regarding that will be useful to me so thanks, if i have to sum up i'll ask :

  • Can i use a schematic without building it ? (i guess not but i ask anyway)
  • How do i use it ? (I guess i have to point at the built schematic but i don't know how)
A G
  • 86
  • 11

2 Answers2

1

Yes, you have to build schematics, actually you can compile it in place using tsc -p tsconfig.json.

Then you can run it using schematics <schematics project path>/src/collection.json:<name> --project <target project>

kemsky
  • 14,727
  • 3
  • 32
  • 51
  • When i try that it says Collection cannot be resolved .. (i typed the right path) – A G Mar 24 '23 at 16:33
  • If i am in the schematics dir i can type "schematics .:grid-list" and it works, but if i'm at the projects root and i type "schematics :grid-list" it doesn't work. How so ? what can i do ? – A G Mar 24 '23 at 16:43
  • yes i know. I made it work by doing "npm link" on my built schematic and into the nodes_modules of the application. And then i can do ng g : and it works. But there are so much more that i don't understand – A G Mar 29 '23 at 07:29
0

You can just build your library and npm install the output in your dist folder. This way, it gets declared as a dependency, and you can use the schematics associated with it.

MGX
  • 2,534
  • 2
  • 14
  • I'm sorry i don't understand, build which library ? the lib-common ? and just "npm install" or "npm install XXX" ? where do i npm install ? I see the point you make but i don't understand, please can you be more specific ? – A G Mar 24 '23 at 14:34