-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathgulpfile.js
46 lines (40 loc) · 1.35 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var wrap = require("gulp-wrap");
var merge = require('gulp-merge');
var jsmin = require('gulp-jsmin');
var rename = require('gulp-rename');
var clean = require('gulp-clean');
var mocha = require('gulp-mocha');
gulp.task('objectify-json', function() {
return gulp.src('./src/emotions.json')
.pipe(wrap('window._qqWechatEmotionParser.emotion_map=<%= JSON.stringify(contents) %>;'))
.pipe(rename('emotions.js'))
.pipe(gulp.dest('./dist'));
});
gulp.task('clean-tmp', ['js'], function(){
return gulp.src('./dist/emotions.js', {read: false})
.pipe(clean());
});
gulp.task('js', ['objectify-json', 'test'], function() {
var srcs = ['./src/window.js', './dist/emotions.js', './src/trie.js',
'./src/index.js'
];
srcs = srcs
.map(src => gulp.src(src))
.map(src => src.pipe(wrap('\n!function(){<%= contents %>}();')));
return merge.apply(null, srcs)
.pipe(concat('qq-wechat-emotion-parser.js'))
.pipe(gulp.dest('./dist'))
.pipe(jsmin())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('test', function(){
return gulp.src('test/*', {read: false})
.pipe(mocha({reporter: 'nyan'}));
});
gulp.task('dist', ['js', 'clean-tmp']);
gulp.task('default', ['test']);