angularbuildangular-schematics

How to use Angular Schematics not published but in project direclty


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 :


Solution

  • 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>