-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
79 lines (66 loc) · 1.7 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
let gulp = require('gulp'),
rollup = require('rollup'),
rConfig = require('./rollup.config'),
chalk = require('chalk'),
nodemon = require('gulp-nodemon'),
livereload = require('gulp-livereload'),
execSync = require("child_process").execSync;
let nodemonStream;
gulp.task("compile", bundleClient);
gulp.task("server:start", ["compile"], startNodemonServer);
gulp.task("server:restart", restartNodemonServer);
// WATCH
// =====
gulp.task("default", ["server:start", "watch"]);
gulp.task("watch", () => {
gulp.watch(["client/**/*"], ["compile"]);
gulp.watch(["server/**"], ["server:restart"]);
// live reload
livereload.listen();
gulp.watch(["dist/**/*"], (file) => {
livereload.changed(file)
});
});
function bundleClient() {
updateDocumentation();
return rollup.rollup(rConfig)
.then(bundle => {
bundle.write({
format: 'iife',
file: 'dist/index.js',
name: 'UiZoo',
globals: rConfig.globals
});
})
.catch(handleError);
}
function startNodemonServer() {
nodemonStream = nodemon({
script: './lib/server/main.js',
ext: 'js html',
watch: false,
})
}
function restartNodemonServer() {
if (nodemonStream) {
nodemonStream.emit('restart', 0);
} else {
startNodemonServer();
}
}
function handleError(error) {
console.log(error);
console.error(chalk.red(error.message));
console.error(chalk.grey(error.formatted && err.formatted.replace('Error: ' + error.message + '\n', '')));
if (this && this.emit) {
this.emit('end');
}
}
function updateDocumentation() {
try {
execSync(`node lib/scripts/documentationMapper.js "./client/Components/UI/*/index.js" "./client/Components/UI/(.+)/index.js" "./client/documentation.js"`);
}
catch (err) {
console.error(err.message);
}
}