I've been investigating the nrwl extensions and they look great. However, when I'm following their tutorial for Workspace Specific Schematics, the last step doesn't show me the command to run. Can you tell me how I run the schematic I created? I'm sure it's simple, but I can't find the command anywhere.
Install the angular material lib: yarn add @angular/material. To see the avaible commands from the nx console: nx list @angular/material. To add angular material to the default project: nx generate @angular/material:ng-add.
Nx Cloud is a free platform that unlocks the full potential of your Nx Workspace.
Nx Workspace is a tool suite designed to architect, build and manage monorepos at any scale. It has out-of-the-box support for multiple frontend frameworks like Angular and React as well as backend technologies including Nest, Next, and Express.
(edit: see Stefan's answer for the correct Nx way to do it. If you want to publish your schematics, you still need to follow this answer)
The Nx generator for schematics doesn't do everything it needs to do to have your schematic work. What I have learned below is from creating a blank schematic in another directory by following this blog post by the Angular Team, which I recommend following to understand Schematics in general.
The following rough steps should help get you on your way:
ng g workspace-schematic
Add a collection.json
file in the tools/schematics
directory, for example
{
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
"name": "myCustomCollection",
"version": "0.0.1",
"extends": ["@nrwl/schematics"],
"schematics": {
"data-access-lib": {
"factory": "./data-access-lib",
"schema": "./data-access-lib/schema.json",
"description": "Create a Data Access Library"
}
}
}
Note the extends
property, which means your collection, if it doesn't have a particular schematic, will look to the Nx schematics to try to find it before failing
schematics
field to your package.json
that points to the relative location of your collection.json
file (e.g. "schematics": "./tools/schematics/collection.json"
)package.json
script to run tsc -p tools/tsconfig.typescript.json
(you should modify your tsconfig file to leave the compiled js in place)angular.json
to point to your collection by default. cli > defaultCollection = "."
(it was @nrwl/schematics
for me initially)
ng g ../..:data-access-lib
ng g data-access-lib
(if you completed step 5) or ng g .:data-access-lib
The Nx schematic generator seems to have some major gaps, but hopefully this will help get you back on track.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With