twolfson / gulp.spritesmith

Convert a set of images into a spritesheet and CSS variables via gulp
The Unlicense
1.08k stars 81 forks source link

group normal and retina don't match #49

Closed mikeya closed 9 years ago

mikeya commented 9 years ago

My generate groups aren't matching. I think it might be due to file names but this shouldn't happen. filenames: search.png search-2x.png search-blue.png search-blue-2x.png search-purple.png search-purple-2x.png

$search-group: (
            name: 'search',
            normal: $search,
            retina: $search-purple-2x
            );
 $shield-blue-group: (
            name: 'shield-blue',
            normal: $shield-blue,
            retina: $shield-blue-2x
            );
twolfson commented 9 years ago

In node, . has a lower lexicagraphical rank than - (i.e. '.' < '-' when sorted):

> var a = ['search.png',
... 'search-2x.png',
... 'search-blue.png',
... 'search-blue-2x.png',
... 'search-purple.png',
... 'search-purple-2x.png']
[ 'search.png',
  'search-2x.png',
  'search-blue.png',
  'search-blue-2x.png',
  'search-purple.png',
  'search-purple-2x.png' ]
> a.sort()
[ 'search-2x.png',
  'search-blue-2x.png',
  'search-blue.png',
  'search-purple-2x.png',
  'search-purple.png',
  'search.png' ]
> a
[ 'search-2x.png',
  'search-blue-2x.png',
  'search-blue.png',
  'search-purple-2x.png',
  'search-purple.png',
  'search.png' ]

To remedy this, you have a few options:

gulp.src(['search.png', 'search-2x.png', 'search-blue.png', 'search-blue-2x.png', 'search-purple.png', 'search-purple-2x.png'])
  .pipe(spritesmith({
    // ...
  }))
mv search.png search-1x.png
mv search-blue.png search-blue-1x.png
mv search-purple.png search-purple-1x.png