Browse Source

feat: add chainAndMerge utility rule creator

pull/5222/head
Arman Ozak 6 years ago
parent
commit
722145cf07
  1. 10
      npm/ng-packs/packages/schematics/src/utils/rule.ts

10
npm/ng-packs/packages/schematics/src/utils/rule.ts

@ -1,6 +1,8 @@
import { import {
apply, apply,
chain,
forEach, forEach,
MergeStrategy,
mergeWith, mergeWith,
Rule, Rule,
SchematicContext, SchematicContext,
@ -16,6 +18,14 @@ export function applyWithOverwrite(source: Source, rules: Rule[]): Rule {
}; };
} }
export function chainAndMerge(rules: Rule[]) {
return (host: Tree) => async (tree: Tree, context: SchematicContext) =>
host.merge(
(await (chain(rules)(tree, context) as any).toPromise()) as Tree,
MergeStrategy.AllowDeleteConflict,
);
}
export function overwriteFileIfExists(tree: Tree): Rule { export function overwriteFileIfExists(tree: Tree): Rule {
return forEach(fileEntry => { return forEach(fileEntry => {
if (!tree.exists(fileEntry.path)) return fileEntry; if (!tree.exists(fileEntry.path)) return fileEntry;

Loading…
Cancel
Save