-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·131 lines (114 loc) · 3.29 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
//Modules
const gulp = require('gulp');
const reference = require('undertaker-forward-reference');
const docker = require('dockerode')();
//Config
const config = require('./config.js');
gulp.registry(reference());
//! Tasks
require('./tasks/app.js');
require('./tasks/build.js');
require('./tasks/database.js');
require('./tasks/setup.js');
require('./tasks/dist.js');
require('./tasks/docs.js');
require('./tasks/test.js');
//Client
require('./tasks/client/build.js');
require('./tasks/client/lint.js');
require('./tasks/client/test.js');
require('./tasks/client/watch.js');
//Server
require('./tasks/server/build.js');
require('./tasks/server/lint.js');
require('./tasks/server/test.js');
require('./tasks/server/watch.js');
//! Main Task
gulp.task('default', gulp.series('dev'));
//! Setup
gulp.task('setup', gulp.series(
'stop',
gulp.parallel('setup.dependant', 'setup.docker', 'setup.certs'),
'build.semantic',
'database.reset'
));
//! Development
gulp.task('dev', gulp.series(
'env.dev',
'stop',
'clean',
'build',
'start',
gulp.parallel('watch', 'app.attach')
));
//! Testing
gulp.task('test', gulp.series('server.test'));
//! Mocking
gulp.task('mock', gulp.series(
'env.test',
'stop',
'clean',
gulp.parallel('server.build', 'build.config'),
'database.test',
'database.reset.config',
'database.mock',
'server.watch'
));
//! Distribution
gulp.task('dist', gulp.series(
'env.dist',
'stop',
'clean',
'semantic',
'build',
'dist.copy',
'dist.build'
));
//! Database & App
gulp.task('start', gulp.series('database.start', 'app.start'));
gulp.task('stop', gulp.series('app.stop', 'database.stop'));
gulp.task('restart', gulp.series('stop', 'start'));
gulp.task('reload', gulp.series('app.stop', 'app.start'));
gulp.task('reset', gulp.series('database.reset'));
//! Setup Convenience
gulp.task('clean', gulp.parallel('build.reset', 'dist.reset'));
gulp.task('purge', gulp.parallel('setup.clean'));
gulp.task('certs', gulp.parallel('setup.certs'));
gulp.task('docker', gulp.parallel('setup.docker'));
//! Build Convenience
gulp.task('semantic', gulp.parallel('build.semantic'));
gulp.task('docs', gulp.parallel('api.docs'));
gulp.task('lint', gulp.parallel('client.lint', 'server.lint'));
gulp.task('build', gulp.parallel('client.build', 'server.build', 'build.config'));
gulp.task('watch', gulp.parallel('client.watch', 'server.watch'));
//! Enviroment Variables
gulp.task('env.dev', function(done) { process.env.NODE_ENV = 'development'; done(); });
gulp.task('env.test', function(done) { process.env.NODE_ENV = 'testing'; done(); });
gulp.task('env.dist', function(done) { process.env.NODE_ENV = 'production'; done(); });
//! Test Plans
for (let i in config.tests){
(function(i) {
gulp.task(i + '.test', gulp.series(function (done){
process.env.test = i;
done();
}, 'server.test'));
})(i);
}
//Stop database and app containers on exit
let shutdown = function(){
let app = docker.getContainer(config.name + '_app');
let db = docker.getContainer(config.name + '_db');
app.stop({ t: 5 }, function(err, data){
app.remove({ force: true }, function(err, data){
db.stop({ t: 5 }, function(err, data){
db.remove({ force: true }, function(err, data){
if (!global.hasOwnProperty('app')){
process.exit();
}
});
});
});
});
}
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);