I want to write a Rule that overwrites a file every time. In the following and have MergeStrategy set to Overwrite:
coll
Modifying chris' answer I was able to come up with the following solution:
export function applyWithOverwrite(source: Source, rules: Rule[]): Rule {
return (tree: Tree, _context: SchematicContext) => {
const rule = mergeWith(
apply(source, [
...rules,
forEach((fileEntry) => {
if (tree.exists(fileEntry.path)) {
tree.overwrite(fileEntry.path, fileEntry.content);
return null;
}
return fileEntry;
}),
]),
);
return rule(tree, _context);
};
}
Replace your usage of apply with calls to this function.
applyWithOverwrite(url('./files/stylelint'), [
template({
dot: '.',
}),
]),