forked from joypixels/emojify.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
166 lines (139 loc) · 5 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
path = require('path'),
minimatch = require('minimatch'),
through2 = require('through2'),
del = require('del'),
inquirer = require('inquirer');
var paths = {
dist: {
root: './dist'
}
};
paths.dist.scripts = path.join(paths.dist.root, 'js');
paths.dist.styles = { root: path.join(paths.dist.root, 'css') };
paths.dist.styles.dataURI = path.join(paths.dist.styles.root, 'data-uri');
paths.dist.styles.basic = path.join(paths.dist.styles.root, 'basic');
paths.dist.images = { root: path.join(paths.dist.root, 'images') };
paths.dist.images.separate = path.join(paths.dist.images.root, 'basic');
gulp.task('default', ['compile']);
gulp.task('compile', ['script', 'images-and-styles']);
gulp.task('release', ['update', 'compile', 'bump']);
gulp.task('script', function(){
var pkg = require('./package.json');
gulp.src('./src/emojify.js')
.pipe(gulp.dest(paths.dist.scripts))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.insert.prepend('/*! ' + pkg.name + ' - v' + pkg.version + ' - \n' +
' * Copyright (c) Hassan Khan ' + new Date().getFullYear() + '\n' +
' */'))
.pipe($.uglify({
preserveComments: 'some'
}))
.pipe($.rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.dist.scripts));
});
var getEmoticonFilter = function(){
var emoticons = [
'smile', 'scream', 'smirk', 'grinning', 'stuck_out_tongue_closed_eyes', 'stuck_out_tongue_winking_eye',
'rage', 'frowning', 'sob', 'kissing_heart', 'wink', 'pensive', 'confounded', 'flushed', 'relaxed', 'mask',
'heart', 'broken_heart'
];
return $.filter(function(file){
var index = emoticons.indexOf(path.basename(file.path, path.extname(file.path)));
if(index > -1){
emoticons.splice(index, 1);
return true;
}
})
};
gulp.task('images-and-styles', ['copy-styles', 'data-uri'], function(){
var emoticonFilter = getEmoticonFilter(),
cssFilter = $.filter('**.css'),
emoticonCssFilter = $.filter('**.css'),
emoticonPngFilter = $.filter('**.png');
return gulp.src('./src/images/emoji/*.png')
// copy images over as they are
.pipe(gulp.dest(paths.dist.images.separate))
});
gulp.task('data-uri', function(){
var emoticonFilter = getEmoticonFilter();
return gulp.src('./src/images/emoji/*.png')
.pipe($.imageDataUri({
customClass: function(className){
return 'emoji-' + className
}
}))
.pipe(emoticonFilter)
.pipe($.concat('emojify-emoticons.css'))
.pipe($.replace('.emoji-+1', '.emoji-plus1'))
.pipe(gulp.dest(paths.dist.styles.dataURI))
.pipe($.cleanCss())
.pipe($.rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.dist.styles.dataURI))
.pipe(emoticonFilter.restore())
// generate all data-URIs
.pipe($.concat('emojify.css'))
.pipe($.replace('.emoji-+1', '.emoji-plus1'))
.pipe(gulp.dest(paths.dist.styles.dataURI))
.pipe($.cleanCss())
.pipe($.rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.dist.styles.dataURI));
});
gulp.task('copy-styles', function(){
gulp.src('./src/css/basic/*.css')
.pipe(gulp.dest(paths.dist.styles.basic))
.pipe($.cleanCss())
.pipe($.rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.dist.styles.basic));
});
gulp.task('clean', function(done){
del(paths.dist.root, done);
});
gulp.task('bump', function(done){
inquirer.prompt({
type: 'list',
name: 'bump',
message: 'What type of bump would you like to do?',
choices: ['patch', 'minor', 'major', "don't bump"]
}, function(result){
if(result.bump === "don't bump"){
done();
return;
}
gulp.src(['./bower.json', './package.json'])
.pipe($.bump({type: result.bump}))
.pipe(gulp.dest('./'))
.on('end', done);
});
});
gulp.task('update', function(done){
var emoji = '';
del('./src/images/emoji');
$.download('https://github.com/arvida/emoji-cheat-sheet.com/archive/master.zip')
.pipe($.unzip())
.pipe($.filter(function(file){
return minimatch(file.path, '**/public/graphics/emojis/*.png');
}))
.pipe($.rename({ dirname: './' }))
.pipe(gulp.dest('./src/images/emoji'))
.pipe(through2({ objectMode: true }, function(file, enc, cb){
emoji += ',' + path.basename(file.path, path.extname(file.path));
this.push(file);
cb();
}, function(){
gulp.src('./src/emojify.js')
.pipe($.replace(/(\/\*##EMOJILIST\*\/).+$/m, '$1"' + emoji.substr(1) + '";'))
.pipe(gulp.dest('./src'))
.on('end', done);
}));
});