How to overwrite file with angular schematics?

前端 未结 5 404
难免孤独
难免孤独 2020-12-31 06:31

I want to write a Rule that overwrites a file every time. In the following and have MergeStrategy set to Overwrite:

coll

5条回答
  •  误落风尘
    2020-12-31 07:00

    I experienced the same issue. By accident I found that adding a forEach into the apply allowed the files to be deleted and the new files created. This is with @angular-devkit/schematics-cli@0.6.8.

    export function indexPage(options: any): Rule {
        return (tree: Tree, _context: SchematicContext) => {
            const rule = mergeWith(
                apply(url('./files'), [
                    template({ ...options }),
                    forEach((fileEntry: FileEntry) => {
                        // Just by adding this is allows the file to be overwritten if it already exists
                        if (tree.exists(fileEntry.path)) return null;
                        return fileEntry;
                    })
    
                ])
            );
    
            return rule(tree, _context);
        };
    }
    

提交回复
热议问题