handlecollision callback
Closed this issue · 6 comments
If there's a file collision it'd be nice to be able to handle that by, for example, appending a number. Right now it just dies and there's nothing I can really do about it.
You could use an interim build directory, so your dir structure would look something like this:
/src
(all your js, icon, css/less/sass files go under here)
/build/source
(first gulp step copies anything from /src required for the build to here)
/build/target
(this is the target for any files compiled with gulp)
/static
(or whatever the directory where files are served from by your web server)
Gulp can clear the /build
directory before any build, which prevents collisions from existing files, and also allows it to make a wonderful mess well away from your source files.
I don't think that will solve the problem. The problem is where I have an icon set, where two SVGs have the same name, but are in different folders (ie, my/folder/icon.svg, my/folder2/icon.svg). I cannot control this, as I was using the distribution package for gameicons: http://game-icons.net/
My solution was to just do this: https://github.com/seiyria/gameicons-font/blob/master/gulpfile.js#L21-L32 but I still think gulp-iconfont should have some sort of collision resolution in it, because without that, it just barfs on a duplicate glyph error.
@seiyria you can deal with it by creating your own metadata provider https://github.com/nfroidure/gulp-svgicons2svgfont#optionsmetadataprovider or by patchin the existing one
https://github.com/nfroidure/svgicons2svgfont/blob/master/src/metadata.js
https://github.com/nfroidure/svgicons2svgfont/blob/master/tests/metadata.mocha.js
All that just to change the file name in case there's a collision? That seems like a lot of work.
Sounds a pain, I think solving the issue with the gulpfile is the best solution. I'm not sure gulp-iconfont should be resolving this edge case, as having two SVGs with the same name is far from sensible (not that it's your fault!).
Yeah, I definitely agree that it's unorthodox - I opened this issue before I resolved it in the hopes that I was overlooking something. Either way, I do have a working solution, so I don't really mind. Thanks guys!
For anyone who comes across here, my solution is as follows:
.pipe(rename(path => {
if(fileCounts[path.basename]) {
fileCounts[path.basename] += 1;
path.basename = `${path.basename}-${fileCounts[path.basename]}`;
} else {
fileCounts[path.basename] = 1;
}
return path;
}))
Essentially, use gulp-rename
to rename files, and use a hash to track what files have been seen already.