I'm creating an Angular schematics. I want to apply a rule to the current tree, and then modify the tree.
as explained in the following snippet, I want to apply the rule created, so tree.exists("./file.txt")
returns 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;
};
}
notes
return rule;
creates /file.txt, but I want to create both files file.txt (through applying rules) and hello.txt by tree.create() function.
using tree.create() before applying rules, creates both files, but tree.exists('./file.txt')
still returns false.