I created a simple new schematic using the angular schematics cli. This schematic takes as input a name, and generates a file in the tree. My files/
directory looks like:
src/
app/
__name@dasherize__.ts
I've built it, and then created a new angular project:
ng new test-app --routing --style css
I then cd into the test-app directory and link to my sample schematic:
npm link ../schematics/sample-schematic
I then run my schematic:
ng g sample-schematic:sample
however I get the following error when I do so:
Pipe "dasherize" is not defined.
If I change the file name in my files
directory to test.ts
it works fine, and the file is created. I am guessing i am missing some import to use the various schematic functions in my test-app project. My dependancies and dev-dependancies for test-app
looks like:
"dependencies": {
"@angular/animations": "~7.2.0",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
...
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.13.0",
"@angular-devkit/core": "^7.3.9",
"@angular-devkit/schematics": "^7.3.9",
"@angular-devkit/schematics-cli": "^0.13.9",
"@angular/cli": "~7.3.9",
"@angular/compiler-cli": "~7.2.0",
"@angular/language-service": "~7.2.0",
"@schematics/angular": "^7.3.9",
...
}
Please check this. It might probably help you.
Be sure to import strings
import { strings } from '@angular-devkit/core';
and then, pass strings
to template engine, as below :
const sourceParametrizedTemplates = apply(sourceTemplates, [
template({
...options,
...strings,
})
]);
No need to assign functions to options
. (and it all the case, it won't be good practice to change options
variable).
With this, dasherize
function will be available inside name and also template code.
Hope it will help you.
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