forked from jleppert/tesla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
81 lines (71 loc) · 2.21 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
var watchify = require('watchify'),
browserify = require('browserify'),
gulp = require('gulp'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
gutil = require('gulp-util'),
sourcemaps = require('gulp-sourcemaps'),
assign = require('lodash.assign'),
rev = require('gulp-rev'),
dustify = require('browserify-dustjs'),
uglify = require('gulp-uglify'),
dust = require('dustjs-linkedin'),
fs = require('fs'),
clean = require('gulp-clean'),
run = require('run-sequence'),
chokidar = require('chokidar'),
testem = require('testem');
var customOpts = {
entries: ['./browser.js'],
debug: true
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
b.transform(dustify);
gulp.task('dev', ['bundle'], function(done) {
var index = dust.compileFn(fs.readFileSync('./src/browser/index.dust', 'utf8'), 'index'),
manifest = JSON.parse(fs.readFileSync('./var/build/rev-manifest.json'));
Object.keys(manifest).forEach(function(key) {
manifest[key.replace('.', '-')] = manifest[key];
});
console.log("manifest!", manifest);
index(manifest, function(err, out) {
if(err) {
gutil.log(err);
done();
} else {
fs.writeFileSync('./var/build/index.html', out);
done();
}
});
});
gulp.task('test', function() {
var t = new testem();
return t.startCI(require('./.testem.json'));
});
b.on('update', function() {
run(['clean', 'dev']);
});
b.on('log', gutil.log);
chokidar.watch('./src/browser/index.dust').on('change', function() {
run('dev');
});
gulp.task('clean', function(done) {
return gulp.src('./var/build', {read:false})
.pipe(clean());
});
gulp.task('bundle', ['clean'], bundle);
function bundle() {
return b.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.on('error', gutil.log)
.pipe(rev())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./var/build'))
.pipe(rev.manifest())
.pipe(gulp.dest('./var/build'));
}