This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
gulpfile.js
119 lines (103 loc) · 3.12 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
require('dotenv').load()
var gulp = require('gulp')
var plugins = require('gulp-load-plugins')()
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var browserify = require('browserify')
var watchify = require('watchify')
var bgTask
var manifest = require('./package.json')
process.env.VERSION = manifest.version
gulp.task('default', ['serve', 'watchify'], function () {
plugins.livereload.listen()
gulp.watch('./public/styles/*.scss', ['sass'])
})
gulp.task('serve', function () {
plugins.nodemon({
script: './index.js',
watch: ['./index.js', 'src']
})
})
gulp.task('start-bg', bgTask = plugins.bg('node', './index.js'))
gulp.task('pre-test', function () {
return gulp.src(['./test/**/*.js'])
.pipe(plugins.istanbul())
.pipe(plugins.istanbul.hookRequire())
})
gulp.task('coverage', ['start-bg', 'pre-test'], function () {
// make test
return gulp.src(['./test/**/*.js'], { read: false })
.pipe(plugins.wait(3000))
.pipe(plugins.mocha({reporter: 'spec', bail: true}))
.pipe(gulp.dest(''))
.pipe(plugins.istanbul.writeReports({ dir: './test/coverage' }))
.once('end', function () {
bgTask.setCallback(function () { process.exit(0) })
bgTask.stop(0)
})
.once('error', function () {
bgTask.setCallback(function () { process.exit(0) })
bgTask.stop(0)
})
})
gulp.task('test', ['start-bg'], function () {
// make test
return gulp.src(['./test/**/*.js'], { read: false })
.pipe(plugins.wait(3000))
.pipe(plugins.mocha({ reporter: 'spec', bail: true }))
.pipe(gulp.dest(''))
.once('end', function () {
bgTask.setCallback(function () { process.exit(0) })
bgTask.stop(0)
})
.once('error', function () {
bgTask.setCallback(function () { process.exit(0) })
bgTask.stop(0)
})
})
gulp.task('build', ['sass', 'browserify'])
gulp.task('sass', function () {
gulp.src('./public/styles/style.scss')
.pipe(plugins.plumber())
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass())
.pipe(plugins.autoprefixer())
.pipe(plugins.cssnano())
.pipe(plugins.sourcemaps.write('./'))
.pipe(gulp.dest('./public/dist'))
.pipe(plugins.livereload())
})
gulp.task('watchify', function () {
// set up the browserify instance on a task basis
var bundler = watchify(
browserify({
entries: './public/components/index.jsx',
debug: true
})
).transform('babelify', { presets: ['es2015', 'react'] })
.transform('envify')
bundler.on('update', function () { compile(bundler) })
return compile(bundler)
})
gulp.task('browserify', function () {
// set up the browserify instance on a task basis
var bundler = browserify({
entries: './public/components/index.jsx',
debug: true
}).transform('babelify', { presets: ['es2015', 'react'] })
.transform('envify')
return compile(bundler)
})
function compile (bundler) {
return bundler.bundle()
.on('error', function (err) {
console.error(err.message)
this.emit('end')
})
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(plugins.sourcemaps.init({ loadMaps: true }))
.pipe(plugins.sourcemaps.write('./'))
.pipe(gulp.dest('./public/dist'))
.pipe(plugins.livereload())
}