How to overwrite file with angular schematics?

前端 未结 5 405
难免孤独
难免孤独 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 06:47

    Thanks @cgatian for that hint!
    Unfortunately it didn't worked to move the templates to some location, so I had to add:

    forEach(fileEntry => {
      const destPath = join(options.output, fileEntry.path);
      if (tree.exists(destPath)) {
        tree.overwrite(destPath, fileEntry.content);
      } else {
        tree.create(destPath, fileEntry.content);
      }
      return null;
    })
    

    Until the MergeStrategy works as expected,
    this will do the trick passing the destination path in options.output!

    Thanks again!

提交回复
热议问题