Nx generators with advanced Schematics templates

Discussão em 'Angular' iniciado por zohan99, Outubro 17, 2024.

  1. zohan99

    zohan99 Guest

    I'm trying to get my NX generator to generate some files with the generateFiles function. I have a template file for which I want to dinamically assign part of their name. File name __name@dasherize__-details.component.ts.template. Inside of it I have some code which is also dinamically assigned eg. <%= dasherize(name) %>-details.component.html.

    According to docs this is the way to do substitutions (except for the use of functions - could not find anything on that).

    After running nx g components --name GeneratorTesting --project ui-project I get the following result:

    CREATE libs/mes/skill-matrix/ui/src/lib/generator-testings/__name@dasherize__-details/__name@dasherize__-details.component.ts

    Inside the file (strings.)dasherize function is executed as expected (I get generator-testing-details.component.html), but for the file name I can't get it to work. I am updating the generators as the project went up a couple of major angular and nx versions so I know for a fact this used to work. What am I missing.

    I am on @nx/devkit v19.8.2

    I have tried looking at docs and searching for similar problem but can't seem to find it. If nothing else will help I will pass additional substitions to generateFiles(tree, absoluteTemplatePath, targetPath, substitutions);, but that is my last resort as I want to make as few changes to templates as possible and keep everything as simple as possible

    Continue reading...

Compartilhe esta Página