forked from johannhof/emoji-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
52 lines (45 loc) · 1.45 KB
/
Gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var gulp = require('gulp'),
clean = require('gulp-clean'),
imageResize = require('gulp-image-resize'),
spritesmith = require('gulp.spritesmith');
var emojis = require('./shared/data/emojis.json');
var unicode = require('./shared/data/unicode.json');
gulp.task('emoji', function () {
return gulp.src('./shared/img/emoji/*')
.pipe(imageResize({
width : 46,
height : 46
}))
.pipe(gulp.dest("./tmp/"));
});
gulp.task('sprite', ['emoji'], function () {
var spriteData = gulp.src("./tmp/*.png").pipe(spritesmith({
imgName: 'sprite.png',
cssFormat : 'json',
cssTemplate : function (params) {
var coll = params.items.reduce(function (coll, item) {
coll[item.name] = {
name : item.name,
x : item.x,
y : item.y
};
return coll;
}, {});
Object.keys(emojis).forEach(function (k) {
Object.keys(emojis[k]).forEach(function(emoji){
coll[emoji].unicode = unicode[emoji];
emojis[k][emoji] = coll[emoji];
});
});
return JSON.stringify(emojis);
},
algorithm : 'binary-tree',
cssName: 'sprite.json'
}));
spriteData.img.pipe(gulp.dest("./shared/img/"));
return spriteData.css.pipe(gulp.dest("./shared/data"));
});
gulp.task('clean', ['emoji', 'sprite'], function () {
return gulp.src('./tmp', {read: false}).pipe(clean());
});
gulp.task('generate-sprite', ['emoji', 'sprite', 'clean']);