-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (63 loc) · 1.36 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
require('shelljs/global');
const gulp = require('gulp4');
const developServer = require('gulp-develop-server');
const newer = require('gulp-newer');
const notifier = require('node-notifier');
const notify = message => {
notifier.notify({
title: 'URL-SHORT Notify!',
message
});
};
const distFolder = 'dist';
gulp.task('clean', done => {
rm('-rf', distFolder);
done();
});
gulp.task('clean.routes', done => {
rm('-rf', `${distFolder}/routes`);
done();
});
gulp.task('copy', () => {
return gulp.src([
'src/**/*',
'package.json'
])
.pipe(newer(distFolder))
.pipe(gulp.dest(distFolder));
});
gulp.task('serve', done => {
developServer.listen({ path: 'dist/index.js' }, err => {
err && console.error(err);
notify('Server started, begin watching...');
done();
});
});
gulp.task('restart', done => {
developServer.restart(err => {
err && console.error(err);
notify('Restart successfully.');
done();
});
});
gulp.task('watch', done => {
gulp.watch([
'src/**/*'
], { debounceDelay: 2000 }, gulp.series('clean.routes', 'copy', 'restart'));
done();
});
gulp.task('dev', gulp.series(
'clean',
'copy',
gulp.parallel('serve', 'watch')
));
gulp.task('installDeps', done => {
cd('dist');
exec('npm i --production');
done();
});
gulp.task('build', gulp.series(
'clean',
'copy',
'installDeps'
));