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

Pass Vinyl file object to the function 'to(iconFile)' in a new major version #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pzhlkj6612
Copy link

Hi, this plugin is great. After sprity/sprity is no longer maintained, gulp.spritesmith-multi keeps our work going. Thank you!

Summary

  • Merged Fix options function description #8.
  • Limited the version of Node.js in CI.
  • (Breaking change) Pass Vinyl file object to to(iconFile) in version 4.0.0.
  • Added doc and a test about split sprites generation.

Changes about to(iconFile)

For now, when to(iconFile) is a function, it will receive a Vinyl file object instead of a file path string. It allows users to obtain more useful information about the file (listed in Vinyl | gulp.js § Instance properties), such as parsing the relative path of a file based on the glob path passed to gulp.src().

Since the parameter passed to to(iconFile) has been changed, some old code related to it will be broken, so I marked it as a "breaking change". According to About semantic versioning | npm Docs § Incrementing semantic versions in published packages, when backward compatibility breaks, a new major version needs to be released.

Why I change the plugin itself

I really know that the split sprites generation can be done by another way without modifying the plugin:

gulp.task('split_by_myself', ['clean'], function () {
  var opts = {
    to: function (file) {
      return path.dirname(path.relative('split/', file))
          .replace(/[\/\\ ]/g, '-')
    },
  }
  return gulp.src('split/**/*.png')
    .pipe(spritesmith(opts))
    .pipe(gulp.dest('build'))
})

In the above code, I specified the path twice, because as far as I know, the glob path is difficult to compare with any ordinary path (without asterisk). After viewing the code from lib/tile.js#L18-L26 in sprity/sprity, I think using the APIs of Vinyl file object is a better way.

vdboor and others added 4 commits August 24, 2016 17:17
The options function doesn't receive `options.to`, but receives 2 extra parameters.
I've also added a sass example in there.
BREAKING CHANGE!

In order to support more functions, such as generating split sprites [1]
 , we need to get Vinyl file object to obtain more useful information in
 the function 'to(iconFile)'.

Since the parameter passed to 'to(iconFile)' has been changed, some old
 code related to it will be broken, so a new major version is also
 needed.

[1] Similar funtion to the 'split' option in https://github.com/sprity/sprity#how-to-use-split-option
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

Successfully merging this pull request may close these issues.

2 participants