-
Notifications
You must be signed in to change notification settings - Fork 20
/
gulpfile.js
105 lines (87 loc) · 2.94 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
var fs = require('fs');
var path = require('path');
var crc = require('crc');
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var minifyCss = require('gulp-minify-css');
var zip = require('gulp-zip');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
var gzip = require('gulp-gzip');
var del = require('del');
var output = {
chrome: './out/chrome',
website: './out/web'
};
function getCRC(filename) {
return crc.crc32(fs.readFileSync(path.join(output.website, filename), {encoding: 'utf8'}));
}
gulp.task('watch', function() {
gulp.watch(['lib/**/*.{js,css}'], ['default']);
});
gulp.task('chrome-clean', function(cb) {
del.sync([output.chrome]);
cb();
});
gulp.task('chrome-css', ['chrome-clean'], function() {
return gulp.src('./ui/ui.css')
.pipe(minifyCss({processImport: true}))
.pipe(gulp.dest(output.chrome));
});
gulp.task('chrome-js', ['chrome-clean'], function() {
return gulp.src(['./lib/chrome/app.js', './lib/chrome/background.js'])
.pipe(browserify({
insertGlobals : false,
debug : false
}))
.pipe(gulp.dest(output.chrome));
});
gulp.task('chrome-misc', ['chrome-clean'], function() {
return gulp.src(['./lib/chrome/manifest.json', './lib/chrome/*.png'])
.pipe(gulp.dest(output.chrome));
});
gulp.task('chrome', ['chrome-clean', 'chrome-css', 'chrome-js', 'chrome-misc'], function() {
return gulp.src(['*.*'], {cwd: output.chrome})
.pipe(zip('chrome.zip'))
.pipe(gulp.dest(output.chrome));
});
gulp.task('website-clean', function(cb) {
del.sync([output.website]);
cb();
});
gulp.task('website-css', ['website-clean'], function() {
return gulp.src('./style.css')
.pipe(minifyCss({processImport: true}))
.pipe(gulp.dest(output.website));
});
gulp.task('website-js', ['website-clean'], function() {
return gulp.src(['./lib/online-app.js'])
.pipe(browserify({
insertGlobals : false,
debug : false
}))
.pipe(uglify())
.pipe(gulp.dest(output.website));
});
gulp.task('website-html', ['website-css', 'website-js'], function() {
var css = getCRC('style.css');
var js = getCRC('online-app.js');
return gulp.src('index.html')
.pipe(replace('<link rel="stylesheet" href="style.css" />', '<link rel="stylesheet" href="/-/' + css + '/style.css" />'))
.pipe(replace('<script src="./node_modules/requirejs/require.js" data-main="./lib/online-app"></script>', '<script src="/-/' + js + '/online-app.js"></script>'))
.pipe(gulp.dest(output.website));
});
gulp.task('website-static', function() {
return gulp.src(['favicon.ico'])
.pipe(gulp.dest(output.website));
});
gulp.task('website-example', function() {
return gulp.src(['example/**/*.*'])
.pipe(gulp.dest(path.join(output.website, 'example')));
});
gulp.task('website', ['website-clean', 'website-html', 'website-static', 'website-example'], function() {
return gulp.src(['*.{css,js,html,ico}'], {cwd: output.website})
.pipe(gzip())
.pipe(gulp.dest(output.website));
});
gulp.task('default', ['chrome', 'website']);