-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
117 lines (99 loc) · 2.62 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
var gulp = require('gulp')
var merge = require('event-stream').merge
var webpack = require('webpack-stream')
var $ = require('gulp-load-plugins')()
/**
* Public tasks
*/
gulp.task('clean', function () {
return pipe('./tmp', [$.clean()])
})
gulp.task('build', function (cb) {
$.runSequence('clean', 'css', 'templates', 'js', 'images', 'chrome', 'opera', 'firefox', cb)
})
gulp.task('default', ['build'], function () {
gulp.watch(['./src/**/*'], ['default'])
})
gulp.task('dist', ['build'], function (cb) {
$.runSequence('firefox:xpi', 'chrome:zip', 'opera:nex', cb)
})
/**
* Private tasks
*/
gulp.task('css', function () {
return pipe('./src/styles/munchdb.scss', [
$.sass({errLogToConsole: true}),
$.autoprefixer({cascade: true}),
$.concat('munchdb.css')
], './tmp')
})
gulp.task('templates', function () {
gulp.src('./src/templates/**/*.mustache')
.pipe($.hoganCompile('templates.js', {hoganModule: 'hogan.js'}))
.pipe(gulp.dest('./src'))
})
gulp.task('js', function () {
return pipe([
'./src/**/*.js',
'!./src/browsers/**/*'
], [
webpack(require('./webpack.config.js'))
], './tmp')
})
gulp.task('images', function () {
return pipe('./src/images/**/*', './tmp/images')
})
// Chrome
gulp.task('chrome', function () {
return merge(
pipe('./icons/**/*', './tmp/chrome/icons'),
pipe([
'./tmp/munchdb.css',
'./tmp/munchdb.js',
'./src/browsers/chrome/**/*'
], './tmp/chrome/')
)
})
gulp.task('chrome:zip', function () {
return pipe('./tmp/chrome/**/*', [$.zip('chrome.zip')], './dist')
})
// Opera
gulp.task('opera', ['chrome'], function () {
return pipe('./tmp/chrome/**/*', './tmp/opera')
})
gulp.task('opera:nex', function () {
return pipe('./dist/chrome.crx', [$.rename('opera.nex')], './dist')
})
// Firefox
gulp.task('firefox', function () {
return merge(
pipe('./icons/**/*', './tmp/firefox/data/icons'),
pipe([
'./tmp/munchdb.css',
'./tmp/munchdb.js'
], './tmp/firefox/data'),
pipe(['./src/browsers/firefox/firefox.js'], './tmp/firefox/lib'),
pipe('./src/browsers/firefox/package.json', './tmp/firefox')
)
})
gulp.task('firefox:xpi', function (cb) {
$.run('cd ./tmp/firefox && jpm xpi').exec(function () {
pipe('./tmp/firefox/@munchdb-*.xpi', './dist')
return cb()
})
})
/**
* Helpers
*/
function pipe (src, transforms, dest) {
if (typeof transforms === 'string') {
dest = transforms
transforms = null
}
var stream = gulp.src(src)
transforms && transforms.forEach(function (transform) {
stream = stream.pipe(transform)
})
if (dest) stream = stream.pipe(gulp.dest(dest))
return stream
}