Install angular schematics globally
yarn global add @angular-devkit/schematics-cli
Install rubedo schematics to your project
yarn add -D @rubedo/schematics
From your project directory run
schematics @rubedo/devkit:devkit
You will get a CLI checklist, a multi-select from which you can check with Space
button tools that you want to be scaffolded.
You can select multiple tools to be scaffolded at once. After you've selected desired tools for scaffolding, hit Enter
.
Your package.json and / or project file structure will be updated depending on which tools you chose. You will get a console output
stating what was updated and how (package.json: scripts, dependencies, devDependencies / project file structure).
This repository is a basic Schematic implementation that serves as a starting point to create and publish Schematics to NPM.
To test locally, install @angular-devkit/schematics-cli
globally and use the schematics
command line tool. That tool acts the same as the generate
command of the Angular CLI, but also has a debug mode.
Check the documentation with
schematics --help
npm run test
will run the unit tests, using Jasmine as a runner and test framework.
To publish, simply do:
npm run build
npm publish
After cloning the project:
npm i --ignore-scripts
You can publish the schematic locally to test against any Nx workspace using verdaccio:
npm i -g verdaccio
verdaccio // to start the private local npm registry
verdaccio
with the following:npm run build
npm publish --registry http://localhost:4873
create-nx-workspace myworkspace
.npmrc
to root with the following:@nstudio:registry=http://localhost:4873
npm i @nstudio/schematics -D --registry http://localhost:4873 --force
Anytime you make further changes to the schematic just rebuild/republish:
npm run build
npm publish --registry http://localhost:4873
// then repeat Step #4 to install latest
If you get this error:
npm ERR! code EPUBLISHCONFLICT
npm ERR! publish fail Cannot publish over existing version.
npm ERR! publish fail Update the 'version' field in package.json and try again.
npm ERR! publish fail
npm ERR! publish fail To automatically increment version numbers, see:
npm ERR! publish fail npm help version
You can simply unpublish and publish like this:
npm unpublish --registry http://localhost:4873 --force
npm publish --registry http://localhost:4873
npm test
All tests must pass. Please add tests for any new functionality.
In order to test schematics locally in debug mode (without writing files) run
schematics .:schematicName
or in normal mode
schematics .:schematicName --debug=false