Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular schematic is not creating files from templates

I've created an angular schematic for the purposes of creating boilerplate code with an ng generate command, however despite all the articles I've read through and messing about, I cannot get the files to create.

I've the following code in my schematic factory:

export function createComponent(_options: any): Rule {
    return (tree: Tree, _context: SchematicContext) => {
        setupOptions(tree, _options);

        const movePath = normalize(_options.path + '/' + strings.dasherize(_options.name));

        const templateSource = apply(url('./files'), [
            template({
                ...strings,
                ..._options,
            }),
            move(movePath)
        ]);

        return mergeWith(templateSource);
    };
}

In the same directory as this is a files directory containing my "__name@dasherize__.component.ts" template which I'm expecting to get pulled in as part of the url('./files') function but I'm not sure this is happening.

My template file is as follows:

import { Component } from '@angular/core';

@Component({
    selector: 'wx-<%= dasherize(componentName) %>'
})
export class <%= classify(componentName) %>Component {

}

I'd expect a 'CREATE' to appear when I run the schematic but all I get is 'Nothing to be done.'

Oddly enough using tree.create() is successfully running to create files so I wonder if the url() or apply() functions are not running as expected.

like image 279
alex.rayner Avatar asked May 10 '26 15:05

alex.rayner


1 Answers

Make sure that "./files" is a correct path relative to your schematic file inside the dist folder.

Maybe you need to change it to something like: "../../src/my-schematic/files".

like image 192
Sh eldeeb Avatar answered May 14 '26 10:05

Sh eldeeb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!