yeoman / yo

CLI tool for running Yeoman generators
http://yeoman.io
BSD 2-Clause "Simplified" License
3.85k stars 399 forks source link

Add command line option to skip existing files #599

Open splatteredbits opened 6 years ago

splatteredbits commented 6 years ago

We use Yo to generate content for new Git repositories. We have several in-house templates. Jobs to generate are run non-interactively through Jenkins. We'd like to be able to re-run our Yeoman templates on existing repositories without clearing their contents. In other words, if we have an updated template that adds a file, we'd like to add that file to our template and let our users re-run the Jenkins job and have that file added to the repository without overwriting any existing files.

Today, Yo prompts what you want to do when it finds a conflict. This doesn't work when running non-interactively. Yo has the --force switch, but that overwrites everything. This is not what we want. Users could easily have strayed from the defaults since the initially created their repository.

Because of this, we now have to write extra automation to add new files to repositories and we can't add them to the template. (Well, I guess we could, but then we'd have that file in two different places.)

Please add a --skip-existing or a --on-conflict <skip|overwrite|abort> switch to Yo so I can control what to do when handling conflicts.

splatteredbits commented 6 years ago

I wouldn't mind putting together a pull request for this feature. I just need help navigating to the right spot in the code. I looked in the yo module but couldn't find where the --force switch gets used.

SBoudrias commented 6 years ago

The options are all handled inside yeoman-generator. More specifically, conflicts resolution is handled over here: https://github.com/yeoman/generator/blob/master/lib/util/conflicter.js

I don't think adding this feature would cause issue - I think it might be quite handy for some use cases.