This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
102 lines (87 loc) · 2.06 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
'use strict';
const gulp = require('gulp');
const babel = require('babelify');
const browserify = require('browserify');
const concat = require('gulp-concat');
const eslint = require('gulp-eslint');
const gulpgo = require('gulp-go');
const source = require('vinyl-source-stream');
const del = require('del');
const project = 'lumo-example';
const paths = {
root: 'webapp/app.js',
index: 'webapp/index.html',
images: 'webapp/*.png',
scripts: [ 'webapp/**/*.js' ],
styles: [ 'webapp/**/*.css' ],
go: [ '**/*.go' ],
build: 'build'
};
function logError(err) {
if (err instanceof SyntaxError) {
console.error('Syntax Error:');
console.error(err.message);
console.error(err.codeFrame);
} else {
console.error(err.message);
}
}
function handleError(err) {
logError(err);
this.emit('end');
}
function clean() {
return del([ paths.build ]);
}
function lint() {
return gulp.src(paths.scripts)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function styles() {
return gulp.src(paths.styles)
.pipe(concat(`${project}.css`))
.pipe(gulp.dest(paths.build));
}
function scripts() {
return browserify(paths.root, {
debug: true,
standalone: project
}).transform(babel, {
presets: ['@babel/preset-env']
})
.bundle()
.on('error', handleError)
.pipe(source(`${project}.js`))
.pipe(gulp.dest(paths.build));
}
function copyIndex() {
return gulp.src(paths.index)
.pipe(gulp.dest(paths.build));
}
function copyImages() {
return gulp.src(paths.images)
.pipe(gulp.dest(paths.build));
}
let go;
function serve() {
go = gulpgo.run(paths.server, [], {
stdio: 'inherit'
});
}
function watch() {
gulp.watch(paths.scripts, scripts);
gulp.watch(paths.styles, styles);
gulp.watch(paths.images, copyImages);
gulp.watch(paths.index, copyIndex);
gulp.watch(paths.go, () => {
go.restart();
});
}
const build = gulp.series(clean, gulp.parallel(scripts, styles, copyIndex, copyImages));
exports.clean = clean;
exports.lint = lint;
exports.build = build;
exports.serve = serve;
exports.default = gulp.series(build, gulp.parallel(watch, serve));