-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
165 lines (138 loc) · 4.34 KB
/
gulpfile.js
File metadata and controls
165 lines (138 loc) · 4.34 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const { series, parallel, src, dest } = require('gulp');
var exec = require('child_process').exec;
var rename = require("gulp-rename");
const tar = require('gulp-tar');
const gzip = require('gulp-gzip');
const fs = require("fs")
var del = require('del');
buildVersion = ""
const cleanFront = async () => {
await del('WordWaveWeb/dist/*')
}
const cleanAdmin = async () => {
await del('Speech2TextWeb/build/*')
}
const cleanBack = async () => {
}
const cleanBuild = async () => {
await del('./build')
await del('./dist')
}
const buildBack = async () => {
await src([
'./COMServer/*.py',
'./COMServer/requirements.txt',
'./COMServer/DTO/*.py',
'./COMServer/dictionnaries/*',
'./COMServer/static/*'
], { base: './COMServer' })
.pipe(dest('./build'))
await src('./COMServer/config.prod.json')
.pipe(rename('config.json'))
.pipe(dest('./build'))
}
const buildFront = () => {
return new Promise(cb => {
exec('cd WordWaveWeb && npm i && npm run build', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr)
console.log(err);
cb()
});
})
}
const buildAdmin = () => {
return new Promise(cb => {
exec('cd Speech2TextWeb && npm i && npm run build', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr)
console.log(err);
cb()
});
})
}
const renameFrontIndex = () => {
return src('./WordWaveWeb/dist/index.html')
.pipe(rename('data.html'))
.pipe(dest('./WordWaveWeb/dist'))
}
const copyFront = () => {
return src('./WordWaveWeb/dist/**/*')
.pipe(dest('./build/static'))
}
const renameAdminIndex = () => {
return src('./Speech2TextWeb/build/index.html')
.pipe(rename('admin.html'))
.pipe(dest('./Speech2TextWeb/build'))
}
const copyAdmin = () => {
return src('./Speech2TextWeb/build/**/*')
.pipe(dest('./build/static'))
}
const setVersion = async(cb)=> {
let version = await fs.readFileSync('./version')
version = String(version).split('.')
version[version.length - 1]++
version = version.join('.')
await fs.writeFileSync('./version', version)
buildVersion = version
await src([
'./version',
'./Dockerfile'
])
.pipe(dest(['./build']))
return new Promise(cb => {
exec('git tag '+version, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr)
console.log(err);
cb()
});
})
}
const buildDocker = () => {
return new Promise(cb => {
exec(' cd build && docker build . --no-cache -t pazka/wordwave:latest', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr)
console.log(err);
cb()
});
})
}
/**
* Old way of publishing the resulting backend docker image
* Now I will use "publish"
*/
const compress = () => {
return new Promise(cb => {
fileName = "wordwave"
exec(`mkdir dist && cd dist && docker save pazka/wordwave > ${fileName}.tar && gzip -v ${fileName}.tar`, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr)
console.log(err);
cb()
});
})
}
const publish = () => {
return new Promise(cb => {
fileName = "wordwave"
exec(`docker push pazka/wordwave:latest`, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr)
console.log(err);
cb()
});
})
}
const buildFrontTask = series(buildFront,renameFrontIndex,copyFront)
const buildAdminTask = series(buildAdmin,renameAdminIndex,copyAdmin)
const buildApp = series(buildBack, parallel(buildFrontTask, buildAdminTask), setVersion);
const buildImage = series(buildDocker, publish)
const build = series(buildApp, buildImage);
const clean = parallel(cleanAdmin, cleanFront, cleanBack, cleanBuild);
exports.clean = clean
exports.buildImage = buildImage
exports.buildApp = series(clean, buildApp)
exports.default = series(clean, build);