-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
65 lines (57 loc) · 1.58 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
var gulp = require('gulp')
var browserify = require('browserify')
var babelify = require('babelify')
var through = require('through2')
var mv = require('gulp-rename')
var exec = require('child_process').exec
var jsFiles = 'src/**/*.js'
var staticFiles = [
'manifest.json',
'background.js',
'options.html',
'styles.css',
'images/**/*'
]
var reactFiles = [
'bower_components/react/react.min.js'
]
gulp.task('default', [ 'static', 'scripts' ])
gulp.task('scripts', scriptsBuilder(true))
gulp.task('productionScripts', scriptsBuilder(false))
gulp.task('static', function() {
gulp.src(reactFiles, { base: './bower_components/react' })
.pipe(gulp.dest('dist'))
return gulp.src(staticFiles, { base: './' })
.pipe(gulp.dest('dist'))
})
gulp.task('watch', [ 'default' ], function() {
gulp.watch(jsFiles, [ 'scripts' ])
gulp.watch(staticFiles, [ 'static' ])
})
gulp.task('publish', [ 'static', 'productionScripts' ], function() {
exec('zip -r headers-middleman.zip dist', function(err) {
if (err !== null) {
throw err;
}
})
})
function scriptsBuilder(debug) {
return function() {
return gulp.src('src/index.js')
.pipe(through.obj(function (file, enc, next) {
browserify(file.path, { debug: debug })
.transform(babelify)
.bundle(function (err, res) {
if (err) return next(err)
file.contents = res
next(null, file)
})
}))
.on('error', function (error) {
console.log(error.stack)
this.emit('end')
})
.pipe(mv('app.js'))
.pipe(gulp.dest('dist'))
}
}