forked from DeMaCS-UNICAL/LoIDE
/
gulpfile.js
135 lines (114 loc) · 3.2 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const { series, src, dest, parallel } = require('gulp');
const csso = require('gulp-csso');
const clean = require('gulp-clean');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify-es').default;
const imagemin = require('gulp-imagemin');
const nodemon = require('gulp-nodemon')
var browserSync = require('browser-sync').create();
var babel = require("gulp-babel");
const path = {
dist: 'dist/',
src: 'resources/'
}
const environment = {
dev: 'development',
prod: 'production'
}
// System config loading
var properties = require('./config/app-config.json');
var httpPort = properties.port.http;
function cleanDir(){
return src( path.dist + '*', {read: false})
.pipe(clean());
}
function css() {
return src(path.src + 'css/*.css')
.pipe(autoprefixer({
cascade: false
}))
.pipe(csso())
.pipe(dest(path.dist + 'css/'))
}
function faviconImage() {
return src(path.src + 'favicon/*.{png,svg}')
.pipe(imagemin())
.pipe(dest(path.dist + 'favicon/'))
}
function faviconFiles() {
return src(path.src + 'favicon/*.{ico,xml,webmanifest}')
.pipe(dest(path.dist + 'favicon/'))
}
function img() {
return src(path.src + 'img/*.*')
.pipe(imagemin())
.pipe(dest(path.dist + 'img/'))
}
function js() {
return src(path.src + 'js/**/*.js')
.pipe(babel())
.pipe(uglify())
.pipe(dest(path.dist + 'js/'))
}
function pug() {
return src(path.src + '**/*.pug')
.pipe(dest(path.dist))
}
function serveProd(done) {
const server = nodemon({
script: 'app.js'
, ext: 'js json'
, ignore: ['node_modules/', 'dist/', 'resources/', 'gulpfile.js']
, env: { 'NODE_ENV': environment.prod }
});
server.on('start', () => {
done();
});
}
function serveDev(done) {
const STARTUP_TIMEOUT = 5000;
const server = nodemon({
script: 'app.js'
, stdout: false
, ext: 'js json'
, ignore: ['node_modules/', 'dist/', 'resources/', 'gulpfile.js']
, env: { 'NODE_ENV': environment.dev }
});
let starting, restarting, crashed = false;
const onReady = () => {
starting = false;
if(restarting && !crashed) browserSync.reload();
restarting = false;
crashed = false;
done();
};
server.on('start', () => {
starting = true;
setTimeout(onReady, STARTUP_TIMEOUT);
});
server.on('stdout', (stdout) => {
process.stdout.write(stdout); // pass the stdout through
if (starting || restarting) {
onReady();
}
});
server.on('restart', () => {
browserSync.notify("Reastarting LoIDE, please wait!");
restarting = true;
});
server.on('crash', () => {
browserSync.notify("LoIDE crashed!", 5000);
crashed = true;
});
}
function startBrowserSync(done){
browserSync.init({
proxy: "http://localhost:" + httpPort,
files: [path.src + "/**/*.*"],
port: 7000,
}, done);
}
const build = parallel(css,faviconImage,faviconFiles,img,js,pug);
exports.default = series(cleanDir, build, serveProd)
exports.dev = series(cleanDir, serveDev, startBrowserSync)
exports.clean = series(cleanDir)