Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwriting on a per-file basis? #68

Closed
troch opened this issue May 18, 2015 · 3 comments
Closed

Overwriting on a per-file basis? #68

troch opened this issue May 18, 2015 · 3 comments

Comments

@troch
Copy link

troch commented May 18, 2015

I have been working on a peculiar case: a client has developers working on different editors, and no-one bothered setting their editors / IDEs for tabs and spaces. That client also doesn't really care about style guides and as a result they introduced jsbeautify in their building process: source files are overwritten with their prettified contents. This is of course not editor friendly (causes files to be reloaded, or editors to prompt for reloads) but this is how that client does it.

The build process has been recently converted to Gulp (using Gulp 4), and to try to make the process more editor-friendly, I introduced a piece of pipeline which prettifies file contents, compare the prettified version with its original and only copy if different.

The issue I have is that I bypass gulp.dest() and use fs.writeFile() instead inside that piece of pipeline. I would prefer if I had a piece of pipeline which would prettify and set an overwrite flag to true if different, and then pass it to gulp.dest().

https://github.com/wearefractal/vinyl-fs/blob/master/lib/prepareWrite.js#L15 could become:

var overwrite = (file.overwrite !== undefined ? file.overwrite : options.overwrite);
options.flag = (overwrite ? 'w' : 'wx');

Should I go ahead with a pull request?

@troch troch changed the title Overwriting on a file basis? Overwriting on a per-file basis? May 18, 2015
@yocontra
Copy link
Member

Not 100% sure on this one. Early in the AM let me chew on it for a bit.

@phated @sindresorhus ?

@phated
Copy link
Member

phated commented Aug 20, 2015

Seems strange to have a file determine the flag behavior, especially because you would need some custom plugin to attach the overwrite property. Can't this be achieved through use of gulp-if or gulp-filter?

@yocontra
Copy link
Member

maybe all of the options on dest should be either value or function just to normalize it, then you can do whatever you want in your function

ie

gulp.dest(folder, {overwrite: function(file){ }}

will take a PR for this, most of the options already function this way

@phated phated closed this as completed in 13c853a Sep 27, 2015
yocontra pushed a commit that referenced this issue Sep 27, 2015
allow a function to be used as value for the overwrite option - closes #68
phated pushed a commit that referenced this issue Dec 5, 2017
allow a function to be used as value for the overwrite option - closes #68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants