-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (103 loc) · 2.74 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
118
119
120
121
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserify = require('browserify');
var del = require('del');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var stylish = require('jshint-stylish');
var buffer = require('vinyl-buffer');
var _ = require('lodash');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
require('babel/register');
var resync = require('./sync/resync');
var logalog = require('./utils/logalog');
gulp.task('clean', function(cb) {
del([
'app/tmp'
], cb);
});
gulp.task('html', function() {
return gulp.src('./src/index.html')
.pipe($.plumber())
.pipe(gulp.dest('./dist'));
});
gulp.task('styles', function() {
return gulp.src('./src/main.less')
.pipe($.less())
.pipe($.autoprefixer())
.pipe($.rename('bundle.css'))
.pipe($.cssmin())
.pipe(gulp.dest('./dist'))
.pipe(reload({ stream: true }));
});
var bundler = _.memoize(function() {
return watchify(browserify('./src/main.js', _.extend({ debug: true }, watchify.args)));
});
function bundle() {
return bundler().bundle()
.on('error', $.util.log)
.pipe(source('bundle.js'))
.pipe(buffer())
// not preserving source maps?
// .pipe($.uglify())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./dist'))
.pipe(reload({ stream: true }));
}
gulp.task('scripts', function() {
process.env.BROWSERIFYSWAP_ENV = 'dist';
return bundle();
});
gulp.task('jshint', function() {
return gulp.src(['./src/**/*.js', '!./src/depends/**/*', './test/**/*.js'])
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter(stylish));
});
var reporter = 'spec';
gulp.task('mocha', ['jshint'], function() {
return gulp.src([
'./test/setup/node.js',
'./test/setup/helpers.js',
'./test/unit/**/*.js'
], { read: false })
.pipe($.plumber())
.pipe($.mocha({ reporter: reporter }));
});
gulp.task('depends', function() {
return gulp.src(['./src/depends/**'])
.pipe(gulp.dest('./dist/depends'));
});
gulp.task('build', [
'clean',
'html',
'depends',
'styles',
'scripts',
'test'
]);
gulp.task('test', [
'jshint',
'mocha'
]);
gulp.task('watch', ['build'], function() {
browserSync({
server: {
baseDir: 'dist'
}
});
reporter = 'dot';
bundler().on('update', function() {
gulp.start('scripts');
gulp.start('test');
});
gulp.watch('./test/**/*.js', ['test']);
gulp.watch(['./src/main.less', './src/**/*.less'], ['styles']);
gulp.watch(['./src/**/*.html'], ['html']);
// Resync resources once an hour
logalog.debug('\n\n\tPrepared resync once an hour.\n\n');
setInterval(resync, 3.6e6);
});
gulp.task('default', ['watch']);