This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
gulpfile.js
83 lines (78 loc) · 2.91 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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var lazypipe = require('lazypipe');
var fs = require('fs');
var pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
var filename = 'BilibiliHelper-V' + pkg.version + '.' + (process.env.TRAVIS_BUILD_NUMBER || 0);
var path = 'release';
var mainTask = ['html', 'style', 'copy', 'manifest'];
$.jshintChannel = lazypipe()
.pipe($.jshint)
.pipe($.jshint.reporter, 'jshint-stylish')
.pipe($.jshint.reporter, 'fail');
gulp.task('debug', $.sequence('set:d', ['script', 'live'], mainTask));
gulp.task('release', $.sequence('set:r', ['script', 'live'], mainTask, 'zip'));
gulp.task('default', function() {
console.log('Please use `release` or `debug` task!');
});
gulp.task('set:r', function() {
path = 'release';
return;
});
gulp.task('set:d', function() {
path = 'debug';
return;
});
gulp.task('live', function() {
return gulp.src('src/live/*.js')
.pipe($.order(['Helper.js', 'Module*.js', 'Func*.js', '!Core.js', 'Core.js']))
.pipe($.jshintChannel())
.pipe($.concat('live.js'))
.pipe($.if(path == 'release', $.babel({presets: ['env', 'minify']})))
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(path + '/src/'));
});
gulp.task('script', function() {
return gulp.src(['src/**/!(*.min).js', '!src/live/*.js'])
.pipe($.jshintChannel())
.pipe($.if(path == 'release', $.babel({presets: ['env', 'minify']})))
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(path + '/src/'));
});
gulp.task('html', function() {
return gulp.src('src/**/*.html')
.pipe($.if(path == 'release', $.htmlmin({
collapseBooleanAttributes: true,
minifyCSS: true,
minifyJS: true,
removeComments: true,
quoteCharacter: '"'
})))
.pipe(gulp.dest(path + '/src/'));
});
gulp.task('style', function() {
return gulp.src('src/**/!(*.min).css')
.pipe($.if(path == 'release', $.cleanCss()))
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(path + '/src/'));
});
gulp.task('copy', function() {
return gulp.src(['**/*.*', '!**/*.html', '!**/!(*.min).js', '!**/!(*.min).css', '!live/**', '!manifest.json'], {cwd: './src'})
.pipe(gulp.dest(path + '/src/'));
});
gulp.task('manifest', function() {
var manifest = JSON.parse(fs.readFileSync('./src/manifest.json', 'utf8'));
manifest.version = pkg.version + '.' + (path == 'release' ? process.env.TRAVIS_BUILD_NUMBER : '0');
manifest.description = pkg.description;
if (!fs.existsSync(path + '/src')) {
fs.mkdirSync(path);
fs.mkdirSync(path + '/src');
}
fs.writeFileSync(path + '/src/manifest.json', JSON.stringify(manifest, null, ' '), {flag: 'w+'});
return;
});
gulp.task('zip', function() {
return gulp.src(path + '/src/**')
.pipe($.zip(filename + '.zip'))
.pipe(gulp.dest(path + '/'));
});