Skip to content

BrianMikinski/ngSchematicsPlayground

Repository files navigation

ngSchematics Playground

Angular 2+ schematics playground. This repository is a basic Schematic implementation that serves as a starting point to create and publish Schematics to NPM.

Commands

Schematics Dev Kit Installation

npm i -g @angular-devkit/schematics-cli

Creating new Schematic

schematics blank --name=hello-world-component

Building Schematic

npm run build

Running Schematic

schematics .:hello-world-component

Debugging

Configured in .vscode folder and can but iniated run command (F5).

  • collection.json
  • setting the schema.json is not working as expected. If you remove it you are able to debug, if you leave it in there you are not.
  • NOTE:
    • YOU MUST IN INCLUDE DEFAULTS / OR PASS IN VARIABLE DEFINITIONS FOR ALL OF YOUR SCHEMA PROPERTIES, OTHERWISE YOU WILL NOT BE ABLE TO DEBUG!
    • There is a bug in the debugging of schematics and only strings will be parsed from the command line. Your code will not run and will fail silently before hitting the schematic index.ts file. See github issues to track the fixing of this.

Testing

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

Unit Testing

npm run test will run the unit tests using jasmine as a runner and test framework.

Local Publishing

npm pack will pack the project.

Note: MAKE SURE YOU HAVE BUILT THE PROJECT AND ARE NOT EXCLUDING THE .JS .d.ts AND ALL OTHER FILES REQUIRED FOR THE SCHEMATIC TO RUN IN YOUR .GITIGNORE FILE. THIS WILL CAUSE IT ALL TO NOT WORK.

  • ng new my-test-app --routing --style css
  • cd my-test-app
  • npm install ../hello-world-component- tgz
  • ng g hello-world-component

This will install your package locally and then you can use it in the current project.

NPM Publishing

To publish, simply do:

npm run build
npm publish

Resources

Notable Github Issues

About

Angular 9+ schematics playground

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published