-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathgulpfile.js
96 lines (80 loc) · 2.57 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
var gulp = require('gulp')
var _ = require('underscore')
var browserify = require('browserify')
var watchify = require('watchify')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var gutil = require('gulp-util')
var del = require('del')
var mergeStream = require('merge-stream')
var dir = {
dev: './src/',
prod: './dist/'
}
gulp.task('build', ['clean'], function () {
gulp.start('scripts', 'styles', 'data', 'html', 'cname')
})
gulp.task('watch', ['clean'], function () {
gulp.start('scripts-watch', 'styles', 'data', 'html', 'cname')
gulp.watch(dir.dev + 'styles/*css', ['styles'])
gulp.watch(dir.dev + '*.html', ['html'])
})
gulp.task('scripts', function () {
return mergeStream(
scripts(dir.dev + 'scripts/vizwit-loader.js', 'vizwit-loader.js'),
scripts(dir.dev + 'scripts/vizwit-embed.js', 'vizwit-embed.js'),
scripts(dir.dev + 'scripts/vizwit-editor.js', 'vizwit-editor.js')
)
})
gulp.task('scripts-watch', function () {
return mergeStream(
scripts(dir.dev + 'scripts/vizwit-loader.js', 'vizwit-loader.js', true),
scripts(dir.dev + 'scripts/vizwit-embed.js', 'vizwit-embed.js', true),
scripts(dir.dev + 'scripts/vizwit-editor.js', 'vizwit-editor.js', true)
)
})
gulp.task('cname', function () {
return gulp.src('CNAME')
.pipe(gulp.dest(dir.prod))
})
gulp.task('html', function () {
return gulp.src(dir.dev + '*.html')
.pipe(gulp.dest(dir.prod))
})
gulp.task('styles', function () {
return gulp.src(dir.dev + 'styles/*.css')
.pipe(gulp.dest(dir.prod + 'styles/'))
})
gulp.task('data', function () {
return gulp.src(dir.dev + 'data/*.json')
.pipe(gulp.dest(dir.prod + 'data/'))
})
gulp.task('clean', function (cb) {
return del(dir.prod, cb)
})
/**
* Build scripts and optionally watch for changes
*/
function scripts (src, dest, watch) {
var bundleOpts = _.extend({}, watchify.args)
if (watch) bundleOpts.debug = true
var bundle = browserify(src, bundleOpts)
if (watch) {
bundle = watchify(bundle)
bundle.on('update', function () { compileBundle(bundle, dest) }) // when a dependency changes, recompile
bundle.on('log', gutil.log) // output build logs to terminal
} else {
bundle.transform({ global: true }, 'uglifyify')
}
return compileBundle(bundle, dest)
}
/**
* Compile a browserify bundle (used by multiple tasks)
*/
function compileBundle (bundle, dest) {
return bundle.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source(dest))
.pipe(buffer()) // buffer file contents (is this necessary?)
.pipe(gulp.dest(dir.prod + 'scripts/'))
}