-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
116 lines (101 loc) · 3.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict';
let gulp = require('gulp'),
gutil = require('gulp-util'),
c = gutil.colors,
eslint = require('gulp-eslint'),
bs = require('browser-sync').create(),
less = require('gulp-less'),
mocha = require('gulp-mocha'),
shell = require('gulp-shell'),
join = require('path').join,
del = require('del')
const OUTDIR = './dist',
SERVER_PORT = 8888,
INDEX_HTML = join(__dirname,'assets/index.html'),
CLIENT_SRC = join(__dirname,'lib/renderer'),
CLIENT_MAIN = join(CLIENT_SRC,'index.js'),
CSS_GLOB = './assets/css/**/*.less',
LESS_INCLUDES = [
'node_modules/skeleton-less/less'
],
browserifyOpts = {
entries: [CLIENT_MAIN],
transform: ['babelify', 'mithrilify'],
debug: true
},
reloadOpts = {stream:true}
gulp.task('js', function() {
return gulp
.src(join(CLIENT_SRC,'**/*.js'))
.pipe(gulp.dest(OUTDIR))
.pipe(bs.reload(reloadOpts))
})
gulp.task('less', function() {
return gulp.src(CSS_GLOB)
.pipe(less({paths: LESS_INCLUDES}))
.on('error', function(err) {
gutil.log(c.red('[CSS]'), err.message)
bs.notify('CSS error', err)
this.emit('end')
})
.pipe(gulp.dest(OUTDIR))
.pipe(bs.reload(reloadOpts))
})
gulp.task('html', function() {
return gulp.src(INDEX_HTML)
.pipe(gulp.dest(OUTDIR))
.pipe(bs.reload(reloadOpts))
})
gulp.task('lint', function() {
return gulp.src([join(CLIENT_SRC,'**/*.js')])
.pipe(eslint())
.pipe(eslint.format())
//.pipe(eslint.failOnError())
})
gulp.task('clean', function(done) {
return del([OUTDIR], done)
})
// TODO Unfortunately this doesn't seem to reload the Electron shell properly.
// gulp will rebuild changes but you will still have to press Ctrl-R to see
// it in the app.
gulp.task('browser-sync', function() {
bs.init({
port: SERVER_PORT,
open: false,
server: { baseDir: OUTDIR }
})
})
// TODO build incremental changes like this:
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/incremental-builds-with-concatenate.md
gulp.task('watch', function() {
gulp.watch(`${CLIENT_SRC}/**/*.js`, ['js','lint'])
gulp.watch(CSS_GLOB, ['less'])
gulp.watch(INDEX_HTML, ['html'])
})
gulp.task('mocha', ['build','browser-sync'], function() {
process.env.NODE_ENV = process.env.NODE_ENV || "test"
require('babel/register')
return gulp.src('test/**/*.js', {read: false})
.pipe(mocha({
require: "babel/register",
ui: "bdd",
timeout: "6000",
reporter: "spec"
}))
.once('error', function(err) {
gutil.log(c.red('[mocha]'), err.message)
process.exit(1)
})
.once('end', function() { process.exit() })
})
// electron-prebuilt is installed as `node_modules/.bin/electron`
gulp.task('launch', ['build'], function() {
return gulp
.src('.')
.pipe(shell(['electron .' /* --proxy-server=http://localhost:${SERVER_PORT}`*/]))
.once('end', process.exit)
})
gulp.task('build', ['js','less','html'])
gulp.task('test', ['mocha'])
gulp.task('run', ['build','lint','watch','launch'])
gulp.task('default', ['run'])