-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
95 lines (74 loc) · 2.11 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
var gulp = require('gulp');
var notify = require('gulp-notify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var livereload = require('gulp-livereload');
var browserify = require('browserify');
var cachingCoffeeify = require('caching-coffeeify');
var transform = require('vinyl-transform');
var del = require('del');
var paths = {
entry: './src/index.coffee',
scripts: './src/**/*.coffee',
testEntry: './test/unit/src/index.coffee',
tests: './test/unit/src/**/*.coffee',
output: './dist'
};
var reloader = null;
var getBundleName = function () {
var name = require('./package.json').name;
return name + '.' + 'min.js';
};
var coffeeBrowserify = function(standalone){
return transform(function(filename){
var b = browserify(filename, {
extensions: ['.coffee'],
paths: ['.'],
standalone: standalone || null
});
b.transform(cachingCoffeeify)
return b.bundle()
.on('error', coffeeError);
});
};
var coffeeError = function(error){
notify.onError({
title: "Build error",
message: error.toString()
})(error);
this.emit('end');
}
gulp.task('clean', function(cb) {
del([paths.output], cb);
});
gulp.task('build', function() {
var stream = gulp.src(paths.entry)
.pipe(plumber())
.pipe(coffeeBrowserify('FluxPlus'))
.pipe(uglify())
.pipe(rename(getBundleName()))
.pipe(gulp.dest(paths.output));
if(reloader){
stream.on('end', livereload.changed);
}
return stream;
});
gulp.task('build-tests', function() {
var stream = gulp.src(paths.testEntry)
.pipe(plumber())
.pipe(coffeeBrowserify())
.pipe(rename('tests.js'))
.pipe(gulp.dest(paths.output));
if(reloader){
stream.on('end', livereload.changed);
}
return stream;
});
gulp.task('watch', function() {
reloader = livereload.listen();
gulp.watch([paths.entry, paths.scripts], ['build']);
gulp.watch([paths.testEntry, paths.tests], ['build-tests']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['build', 'build-tests', 'watch']);