我创建了一个角度示意图,用于使用 ng generate 命令创建样板代码,但是尽管我已经阅读了所有文章并搞砸了,但我无法创建文件。
我的原理图工厂中有以下代码:
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);
};
}
在与此相同的目录中是包含我的“__name@dasherize__.component.ts”模板的文件目录,我希望将其作为 url('./files') 函数的一部分拉入,但我不确定这正在发生。
我的模板文件如下:
import { Component } from '@angular/core';
@Component({
selector: 'wx-<%= dasherize(componentName) %>'
})
export class <%= classify(componentName) %>Component {
}
我希望在运行原理图时会出现“CREATE”,但我得到的只是“无事可做”。
奇怪的是,使用 tree.create() 成功运行以创建文件,所以我想知道 url() 或 apply() 函数是否未按预期运行。