-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
91 lines (78 loc) · 2.3 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
'use strict';
var gulp = require('gulp');
var cssMin = require('gulp-cssnano');
var htmlMin = require('gulp-htmlmin');
var rename = require('gulp-rename');
var jspm = require('gulp-jspm');
var jshint = require('gulp-jshint');
var runSeq = require('run-sequence');
var stylish = require('jshint-stylish');
var jscs = require('gulp-jscs');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var mocha = require('gulp-mocha');
gulp.task('css', function () {
return gulp.src(['client/css/layout.css'])
.pipe(cssMin())
.pipe(rename({ suffix: '.bundle' }))
.pipe(gulp.dest('build/css/'));
});
gulp.task('html', function () {
return gulp.src(['client/index.html'])
.pipe(htmlMin({ collapseWhitespace: true }))
.pipe(gulp.dest('build/'));
});
gulp.task('js', function () {
return gulp.src(['client/js/main.js'])
.pipe(sourcemaps.init())
.pipe(jspm({ selfExecutingBundle: true }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build/js/'));
});
gulp.task('server', function () {
browserSync.init({
port: 8080,
notify: false,
open: false,
server: {
baseDir: './build',
middleware: function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
},
},
});
});
gulp.task('build', function (callback) {
return runSeq(['css', 'html', 'js'], callback);
});
gulp.task('watch', function () {
gulp.watch('client/css/**', ['css']);
gulp.watch('client/js/**', ['js']);
gulp.watch('client/index.html', ['html']);
});
gulp.task('dev', function () {
runSeq('build', 'server', 'watch');
});
gulp.task('jshint', function () {
return gulp.src(['./client/js/*.js', './test/*.js', './gulpfile.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('jscs', function () {
return gulp.src(['./client/js/*.js', './test/*.js', './gulpfile.js'])
.pipe(jscs())
.pipe(jscs.reporter())
.pipe(jscs.reporter('fail'));
});
gulp.task('lint', function (callback) {
return runSeq('jshint', 'jscs', callback);
});
gulp.task('test', function () {
return gulp.src(['./test/*.js'])
.pipe(mocha());
});
gulp.task('default', function () {
runSeq('lint', 'test', 'build');
});