我正在创建一个 Angular 示意图。我想将规则应用于当前树,然后修改树。
如以下代码段所述,我想应用创建的规则,因此tree.exists("./file.txt")
返回true
export default function(options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
let tmpl = apply(url("./files"), [template(options),move(".")]);
let rule = chain([branchAndMerge(chain([mergeWith(tmpl)]))]);
//how to apply this rule to the current tree, so it contains the files from ./files
//assume ./files contain a file named myfile.txt
console.log(tree.exists("./myfile.txt"))
tree.create("hello.txt", "");
return tree;
};
}
笔记
return rule;
创建 /file.txt,但我想通过 tree.create() 函数创建两个文件 file.txt(通过应用规则)和 hello.txt。
在应用规则之前使用 tree.create() 创建两个文件,但tree.exists('./file.txt')
仍然返回 false。