Angular 2+ schematics playground. This repository is a basic Schematic implementation that serves as a starting point to create and publish Schematics to NPM.
npm i -g @angular-devkit/schematics-cli
schematics blank --name=hello-world-component
npm run build
schematics .:hello-world-component
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.
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.
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.
To publish, simply do:
npm run build
npm publish
-
Authoring schematics
- Templates and how to build them https://angular.io/guide/schematics-for-libraries
- Dasherize, classify, etc -
- Note, you must pass the template files onto a rule in order to use them, otherwise they will come back as null references.
- Authoring Schematics
- Templates and how to build them https://angular.io/guide/schematics-for-libraries
-
Tomas Trajan
-
Mike Hartington
- Examples of schematic template if statements, string manipulations, etc.
-
import { Component, OnInit } from '@angular/core'; <% if(routePath) { %>import { ActivatedRoute, Params } from '@angular/router';<% } %> @Component({ selector: '<%= selector %>', templateUrl: './<%= kebabCase(name) %>.page.html', styleUrls: ['./<%= kebabCase(name) %>.page.<%= styleext %>'], }) export class <%= upperFirst(camelCase(name)) %>Page implements OnInit { <% if(routePath) { %>public params: Params;<% } %> constructor(<% if(routePath) { %>private route: ActivatedRoute <% } %>) { } ngOnInit() { <% if(routePath) { %>this.params = this.route.snapshot.params;<% } %> } }
-
Template Loops, might be done this way. This is to be determined
- https://scotch.io/tutorials/use-ejs-to-template-your-node-application
-
<% drinks.forEach(function(drink) { %> <li><%= drink.name %> - <%= drink.drunkness %></li> <% }); %>
-
Angular Api for classify can be found here
-
Schematics - An Introduction
-
Michael Ericksen
- Debugging and Testing Angular Schematics in VS Code
- https://medium.com/@michaelericksen_12434/debugging-and-testing-angular-schematics-in-vs-code-8e697b73ad8c
-
Matt Vaughn
- How to debug an Angular Schematic
- https://medium.com/@angularlicious/how-to-debug-an-angular-schematic-using-visual-studio-3bbe4fde8fd8
-
Matt Raible
-
Schematics Starter
-
Jonathan Campos
- Angular Schematics: Simple Schematic
- https://medium.com/rocket-fuel/angular-schematics-simple-schematic-76be2aa72850
-
Chris Noring
- Angular Schematics - the unknown hero
- https://www.youtube.com/watch?v=_LPzY9GrNwY
-
Nitay Neeman
- Making an Addable Angular Package Using Schematics
- https://nitayneeman.com/posts/making-an-addable-angular-package-using-schematics/
-
DZone
- Create Your First Angular Schematics
- https://dzone.com/articles/create-your-first-angular-schematics
-
Okta
- Building your first PWA with Angular
- https://developer.okta.com/blog/2019/01/30/first-angular-pwa
- How to overwrite file with angular schematics
- MigrationStrategy error
- MergeStrategy seems to be completely broken (mergeWith failure)
- [error] ng/schematics - Data path "" should have required property 'name'
- Data path "" should have required property 'name'. #47
- Angular toolkit ionic-team/angular-toolkit#47
- Boolean options not parsed correctly on schematics cli
- An unhandled exception occurred: Cannot find module '@angular-devkit/core'