underpost 2.7.1 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +13 -13
- package/.env.development +7 -7
- package/.env.production +7 -7
- package/.env.test +7 -7
- package/.github/workflows/publish.yml +26 -0
- package/.nycrc +9 -9
- package/.prettierignore +12 -12
- package/.prettierrc +9 -9
- package/.vscode/extensions.json +72 -72
- package/.vscode/settings.json +100 -99
- package/Dockerfile +89 -89
- package/LICENSE +21 -21
- package/README.md +96 -96
- package/bin/db.js +172 -119
- package/bin/deploy.js +582 -661
- package/bin/dns.js +1 -1
- package/bin/file.js +92 -92
- package/bin/index.js +53 -53
- package/bin/install.js +398 -357
- package/bin/shortcut.js +44 -44
- package/bin/ssl.js +65 -64
- package/bin/util.js +182 -182
- package/bin/vs.js +35 -35
- package/conf.js +251 -249
- package/docker-compose.yml +67 -67
- package/jsconfig.json +7 -7
- package/jsdoc.json +32 -32
- package/nodemon.json +6 -6
- package/package.json +137 -132
- package/prometheus.yml +36 -36
- package/setup.sh +24 -24
- package/src/api/core/core.controller.js +69 -69
- package/src/api/core/core.model.js +11 -11
- package/src/api/core/core.router.js +23 -23
- package/src/api/core/core.service.js +29 -29
- package/src/api/crypto/crypto.controller.js +51 -51
- package/src/api/crypto/crypto.model.js +23 -23
- package/src/api/crypto/crypto.router.js +20 -20
- package/src/api/crypto/crypto.service.js +64 -64
- package/src/api/default/default.controller.js +69 -69
- package/src/api/default/default.model.js +20 -20
- package/src/api/default/default.router.js +23 -23
- package/src/api/default/default.service.js +31 -31
- package/src/api/file/file.controller.js +53 -51
- package/src/api/file/file.model.js +19 -19
- package/src/api/file/file.router.js +21 -20
- package/src/api/file/file.service.js +76 -70
- package/src/api/instance/instance.controller.js +69 -69
- package/src/api/instance/instance.model.js +36 -36
- package/src/api/instance/instance.router.js +33 -33
- package/src/api/instance/instance.service.js +48 -48
- package/src/api/test/test.controller.js +59 -59
- package/src/api/test/test.model.js +14 -14
- package/src/api/test/test.router.js +21 -21
- package/src/api/test/test.service.js +35 -35
- package/src/api/user/user.build.js +16 -0
- package/src/api/user/user.controller.js +70 -70
- package/src/api/user/user.model.js +65 -65
- package/src/api/user/user.router.js +345 -345
- package/src/api/user/user.service.js +479 -479
- package/src/api.js +23 -23
- package/src/client/Default.index.js +40 -40
- package/src/client/components/core/Account.js +290 -290
- package/src/client/components/core/AgGrid.js +160 -160
- package/src/client/components/core/Auth.js +19 -19
- package/src/client/components/core/Badge.js +32 -32
- package/src/client/components/core/BlockChain.js +41 -41
- package/src/client/components/core/Blog.js +9 -9
- package/src/client/components/core/BtnIcon.js +101 -94
- package/src/client/components/core/CalendarCore.js +458 -319
- package/src/client/components/core/Chat.js +64 -64
- package/src/client/components/core/ColorPalette.js +5267 -5267
- package/src/client/components/core/CommonJs.js +735 -732
- package/src/client/components/core/Content.js +193 -49
- package/src/client/components/core/Css.js +1064 -1027
- package/src/client/components/core/CssCore.js +817 -796
- package/src/client/components/core/D3Chart.js +44 -44
- package/src/client/components/core/Docs.js +229 -229
- package/src/client/components/core/DropDown.js +164 -164
- package/src/client/components/core/EventsUI.js +46 -54
- package/src/client/components/core/FileExplorer.js +699 -624
- package/src/client/components/core/FullScreen.js +45 -45
- package/src/client/components/core/Input.js +346 -259
- package/src/client/components/core/JoyStick.js +77 -77
- package/src/client/components/core/Keyboard.js +73 -73
- package/src/client/components/core/LoadingAnimation.js +179 -157
- package/src/client/components/core/LogIn.js +187 -181
- package/src/client/components/core/LogOut.js +58 -52
- package/src/client/components/core/Logger.js +26 -26
- package/src/client/components/core/Modal.js +1612 -1596
- package/src/client/components/core/NotificationManager.js +84 -84
- package/src/client/components/core/Panel.js +613 -413
- package/src/client/components/core/PanelForm.js +468 -0
- package/src/client/components/core/Polyhedron.js +162 -162
- package/src/client/components/core/Recover.js +204 -204
- package/src/client/components/core/Responsive.js +53 -53
- package/src/client/components/core/RichText.js +51 -27
- package/src/client/components/core/Router.js +76 -77
- package/src/client/components/core/Scroll.js +34 -0
- package/src/client/components/core/SignUp.js +125 -125
- package/src/client/components/core/SocketIo.js +72 -72
- package/src/client/components/core/Stream.js +113 -113
- package/src/client/components/core/ToggleSwitch.js +87 -87
- package/src/client/components/core/ToolTip.js +26 -26
- package/src/client/components/core/Translate.js +437 -408
- package/src/client/components/core/Validator.js +100 -100
- package/src/client/components/core/VanillaJs.js +460 -457
- package/src/client/components/core/Wallet.js +106 -106
- package/src/client/components/core/Webhook.js +25 -25
- package/src/client/components/core/Worker.js +272 -272
- package/src/client/components/default/CommonDefault.js +29 -29
- package/src/client/components/default/CssDefault.js +13 -13
- package/src/client/components/default/ElementsDefault.js +38 -38
- package/src/client/components/default/LogInDefault.js +41 -41
- package/src/client/components/default/LogOutDefault.js +28 -28
- package/src/client/components/default/MenuDefault.js +389 -389
- package/src/client/components/default/RoutesDefault.js +48 -48
- package/src/client/components/default/SettingsDefault.js +16 -16
- package/src/client/components/default/SignUpDefault.js +9 -9
- package/src/client/components/default/SocketIoDefault.js +54 -54
- package/src/client/components/default/TranslateDefault.js +7 -7
- package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
- package/src/client/public/default/browserconfig.xml +11 -11
- package/src/client/public/default/manifest.webmanifest +68 -68
- package/src/client/public/default/plantuml/client-conf.svg +1 -0
- package/src/client/public/default/plantuml/client-schema.svg +1 -0
- package/src/client/public/default/plantuml/cron-conf.svg +1 -0
- package/src/client/public/default/plantuml/cron-schema.svg +1 -0
- package/src/client/public/default/plantuml/server-conf.svg +1 -0
- package/src/client/public/default/plantuml/server-schema.svg +1 -0
- package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
- package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
- package/src/client/public/default/sitemap +147 -147
- package/src/client/public/default/yandex-browser-manifest.json +8 -8
- package/src/client/public/doc/sitemap +147 -147
- package/src/client/public/test/sitemap +147 -147
- package/src/client/services/core/core.service.js +170 -152
- package/src/client/services/crypto/crypto.service.js +70 -70
- package/src/client/services/default/default.management.js +345 -345
- package/src/client/services/default/default.service.js +89 -89
- package/src/client/services/file/file.service.js +70 -70
- package/src/client/services/instance/instance.management.js +74 -74
- package/src/client/services/instance/instance.service.js +89 -89
- package/src/client/services/test/test.service.js +70 -70
- package/src/client/services/user/user.management.js +50 -50
- package/src/client/services/user/user.service.js +89 -89
- package/src/client/ssr/Render.js +16 -16
- package/src/client/ssr/body-components/CacheControl.js +114 -113
- package/src/client/ssr/body-components/DefaultSplashScreen.js +79 -79
- package/src/client/ssr/email-components/DefaultRecoverEmail.js +21 -21
- package/src/client/ssr/email-components/DefaultVerifyEmail.js +17 -17
- package/src/client/ssr/head-components/Css.js +241 -241
- package/src/client/ssr/head-components/DefaultScripts.js +3 -3
- package/src/client/ssr/head-components/Microdata.js +11 -11
- package/src/client/ssr/head-components/Production.js +1 -1
- package/src/client/ssr/head-components/PwaDefault.js +59 -59
- package/src/client/ssr/head-components/Seo.js +14 -14
- package/src/client/sw/default.sw.js +201 -201
- package/src/client/sw/template.sw.js +84 -84
- package/src/client.build.js +22 -22
- package/src/client.dev.js +21 -21
- package/src/cron.js +25 -25
- package/src/db/DataBaseProvider.js +34 -34
- package/src/db/mariadb/MariaDB.js +33 -33
- package/src/db/mongo/MongooseDB.js +46 -46
- package/src/dns.js +22 -22
- package/src/index.js +42 -29
- package/src/mailer/EmailRender.js +69 -69
- package/src/mailer/MailerProvider.js +96 -96
- package/src/proxy.js +22 -22
- package/src/runtime/lampp/Lampp.js +69 -44
- package/src/runtime/nginx/Nginx.js +3 -3
- package/src/runtime/xampp/Xampp.js +49 -49
- package/src/server/auth.js +235 -204
- package/src/server/backup.js +101 -94
- package/src/server/client-build-live.js +72 -72
- package/src/server/client-build.js +705 -699
- package/src/server/client-dev-server.js +60 -58
- package/src/server/client-formatted.js +48 -48
- package/src/server/client-icons.js +149 -150
- package/src/server/conf.js +860 -611
- package/src/server/dns.js +98 -98
- package/src/server/downloader.js +42 -42
- package/src/server/logger.js +180 -180
- package/src/server/network.js +122 -122
- package/src/server/peer.js +33 -33
- package/src/server/process.js +66 -66
- package/src/server/prompt-optimizer.js +28 -28
- package/src/server/proxy.js +118 -118
- package/src/server/runtime.js +444 -393
- package/src/server/ssl.js +109 -107
- package/src/server.js +25 -25
- package/src/ws/IoInterface.js +45 -45
- package/src/ws/IoServer.js +39 -39
- package/src/ws/core/channels/core.ws.chat.js +23 -23
- package/src/ws/core/channels/core.ws.mailer.js +35 -35
- package/src/ws/core/channels/core.ws.stream.js +31 -31
- package/src/ws/core/core.ws.connection.js +28 -28
- package/src/ws/core/core.ws.emit.js +14 -14
- package/src/ws/core/core.ws.server.js +24 -24
- package/src/ws/core/management/core.ws.chat.js +8 -8
- package/src/ws/core/management/core.ws.mailer.js +16 -16
- package/src/ws/core/management/core.ws.stream.js +8 -8
- package/src/ws/default/channels/default.ws.main.js +16 -16
- package/src/ws/default/default.ws.connection.js +22 -22
- package/src/ws/default/default.ws.emit.js +14 -14
- package/src/ws/default/default.ws.server.js +20 -20
- package/src/ws/default/management/default.ws.main.js +8 -8
- package/startup.js +11 -11
- package/supervisord-openssh-server.conf +4 -4
- package/test/api.test.js +60 -60
package/src/server/conf.js
CHANGED
|
@@ -1,611 +1,860 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
import { cap, capFirst, newInstance, range, timer } from '../client/components/core/CommonJs.js';
|
|
4
|
-
import * as dir from 'path';
|
|
5
|
-
import cliProgress from 'cli-progress';
|
|
6
|
-
import cliSpinners from 'cli-spinners';
|
|
7
|
-
import logUpdate from 'log-update';
|
|
8
|
-
import colors from 'colors';
|
|
9
|
-
import { loggerFactory } from './logger.js';
|
|
10
|
-
import { shellExec } from './process.js';
|
|
11
|
-
import { DefaultConf } from '../../conf.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (fs.existsSync(`./
|
|
27
|
-
|
|
28
|
-
if (process.argv[2]
|
|
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
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
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
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
fs.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
fs.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
toServerConf[host][path].
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
toSsrConf
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (!fromOptions.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (!fromOptions.
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
fs.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (!fromOptions.
|
|
325
|
-
if (!fromOptions.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (!fromOptions.
|
|
350
|
-
if (!fromOptions.
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
// target: `http
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
host,
|
|
422
|
-
path,
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
// target: `http
|
|
436
|
-
|
|
437
|
-
host
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
const
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
//
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
)
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
absolutePath.match(
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
absolutePath.match(
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
import { cap, capFirst, getCapVariableName, newInstance, range, timer } from '../client/components/core/CommonJs.js';
|
|
4
|
+
import * as dir from 'path';
|
|
5
|
+
import cliProgress from 'cli-progress';
|
|
6
|
+
import cliSpinners from 'cli-spinners';
|
|
7
|
+
import logUpdate from 'log-update';
|
|
8
|
+
import colors from 'colors';
|
|
9
|
+
import { loggerFactory } from './logger.js';
|
|
10
|
+
import { shellExec, shellCd } from './process.js';
|
|
11
|
+
import { DefaultConf } from '../../conf.js';
|
|
12
|
+
import ncp from 'copy-paste';
|
|
13
|
+
import read from 'read';
|
|
14
|
+
import splitFile from 'split-file';
|
|
15
|
+
|
|
16
|
+
colors.enable();
|
|
17
|
+
dotenv.config();
|
|
18
|
+
|
|
19
|
+
const logger = loggerFactory(import.meta);
|
|
20
|
+
|
|
21
|
+
// monitoring: https://app.pm2.io/
|
|
22
|
+
|
|
23
|
+
const Config = {
|
|
24
|
+
default: DefaultConf,
|
|
25
|
+
build: async function (options = { folder: '' }) {
|
|
26
|
+
if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
|
|
27
|
+
fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
|
|
28
|
+
if (fs.existsSync(`./engine-private/conf/${process.argv[2]}`)) return loadConf(process.argv[2]);
|
|
29
|
+
if (fs.existsSync(`./engine-private/replica/${process.argv[2]}`)) return loadConf(process.argv[2]);
|
|
30
|
+
|
|
31
|
+
if (process.argv[2] === 'deploy') return;
|
|
32
|
+
|
|
33
|
+
if (process.argv[2] === 'proxy') {
|
|
34
|
+
this.default.server = {};
|
|
35
|
+
for (const deployId of process.argv[3].split(',')) {
|
|
36
|
+
let confPath = `./engine-private/conf/${deployId}/conf.server.json`;
|
|
37
|
+
const privateConfDevPath = `./engine-private/conf/${deployId}/conf.server.dev.${process.argv[4]}.json`;
|
|
38
|
+
const confDevPath = fs.existsSync(privateConfDevPath)
|
|
39
|
+
? privateConfDevPath
|
|
40
|
+
: `./engine-private/conf/${deployId}/conf.server.dev.json`;
|
|
41
|
+
|
|
42
|
+
if (process.env.NODE_ENV === 'development' && fs.existsSync(confDevPath)) confPath = confDevPath;
|
|
43
|
+
const serverConf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
|
|
44
|
+
|
|
45
|
+
for (const host of Object.keys(loadReplicas(serverConf))) {
|
|
46
|
+
if (serverConf[host]['/'])
|
|
47
|
+
this.default.server[host] = {
|
|
48
|
+
...this.default.server[host],
|
|
49
|
+
...serverConf[host],
|
|
50
|
+
};
|
|
51
|
+
else
|
|
52
|
+
this.default.server[host] = {
|
|
53
|
+
...serverConf[host],
|
|
54
|
+
...this.default.server[host],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!options || !options.folder)
|
|
60
|
+
options = {
|
|
61
|
+
...options,
|
|
62
|
+
folder: `./conf`,
|
|
63
|
+
};
|
|
64
|
+
if (!fs.existsSync(options.folder)) fs.mkdirSync(options.folder, { recursive: true });
|
|
65
|
+
for (const confType of Object.keys(this.default)) {
|
|
66
|
+
fs.writeFileSync(
|
|
67
|
+
`${options.folder}/conf.${confType}.json`,
|
|
68
|
+
JSON.stringify(this.default[confType], null, 4),
|
|
69
|
+
'utf8',
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const loadConf = (deployId) => {
|
|
76
|
+
const folder = fs.existsSync(`./engine-private/replica/${deployId}`)
|
|
77
|
+
? `./engine-private/replica/${deployId}`
|
|
78
|
+
: `./engine-private/conf/${deployId}`;
|
|
79
|
+
if (!fs.existsSync(`./conf`)) fs.mkdirSync(`./conf`);
|
|
80
|
+
if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
|
|
81
|
+
const isValidDeployId = fs.existsSync(`${folder}`);
|
|
82
|
+
for (const typeConf of Object.keys(Config.default)) {
|
|
83
|
+
let srcConf = isValidDeployId
|
|
84
|
+
? fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8')
|
|
85
|
+
: JSON.stringify(Config.default[typeConf]);
|
|
86
|
+
if (process.env.NODE_ENV === 'development' && typeConf === 'server') {
|
|
87
|
+
const devConfPath = `${folder}/conf.${typeConf}.dev${process.argv[3] ? `.${process.argv[3]}` : ''}.json`;
|
|
88
|
+
if (fs.existsSync(devConfPath)) srcConf = fs.readFileSync(devConfPath, 'utf8');
|
|
89
|
+
}
|
|
90
|
+
if (typeConf === 'server') srcConf = JSON.stringify(loadReplicas(JSON.parse(srcConf)), null, 4);
|
|
91
|
+
fs.writeFileSync(`./conf/conf.${typeConf}.json`, srcConf, 'utf8');
|
|
92
|
+
}
|
|
93
|
+
if (!isValidDeployId) return {};
|
|
94
|
+
fs.writeFileSync(`./.env.production`, fs.readFileSync(`${folder}/.env.production`, 'utf8'), 'utf8');
|
|
95
|
+
fs.writeFileSync(`./.env.development`, fs.readFileSync(`${folder}/.env.development`, 'utf8'), 'utf8');
|
|
96
|
+
fs.writeFileSync(`./.env.test`, fs.readFileSync(`${folder}/.env.test`, 'utf8'), 'utf8');
|
|
97
|
+
if (process.env.NODE_ENV) {
|
|
98
|
+
fs.writeFileSync(`./.env`, fs.readFileSync(`${folder}/.env.${process.env.NODE_ENV}`, 'utf8'), 'utf8');
|
|
99
|
+
const env = dotenv.parse(fs.readFileSync(`${folder}/.env.${process.env.NODE_ENV}`, 'utf8'));
|
|
100
|
+
process.env = {
|
|
101
|
+
...process.env,
|
|
102
|
+
...env,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
fs.writeFileSync(`./package.json`, fs.readFileSync(`${folder}/package.json`, 'utf8'), 'utf8');
|
|
106
|
+
return { folder, deployId };
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const loadReplicas = (confServer) => {
|
|
110
|
+
for (const host of Object.keys(confServer)) {
|
|
111
|
+
for (const path of Object.keys(confServer[host])) {
|
|
112
|
+
const { replicas, singleReplica } = confServer[host][path];
|
|
113
|
+
if (replicas && (process.argv[2] === 'proxy' || !singleReplica))
|
|
114
|
+
for (const replicaPath of replicas) {
|
|
115
|
+
confServer[host][replicaPath] = newInstance(confServer[host][path]);
|
|
116
|
+
delete confServer[host][replicaPath].replicas;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return confServer;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const cloneConf = async (
|
|
124
|
+
{ toOptions, fromOptions },
|
|
125
|
+
fromDefaultOptions = { deployId: 'dd-default', clientId: 'default' },
|
|
126
|
+
) => {
|
|
127
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
128
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
129
|
+
|
|
130
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
131
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
132
|
+
|
|
133
|
+
const toClientVariableName = getCapVariableName(toOptions.clientId);
|
|
134
|
+
const fromClientVariableName = getCapVariableName(fromOptions.clientId);
|
|
135
|
+
|
|
136
|
+
const formattedSrc = (dataConf) =>
|
|
137
|
+
JSON.stringify(dataConf, null, 4)
|
|
138
|
+
.replaceAll(fromClientVariableName, toClientVariableName)
|
|
139
|
+
.replaceAll(fromOptions.clientId, toOptions.clientId);
|
|
140
|
+
|
|
141
|
+
const isMergeConf = fs.existsSync(confToFolder);
|
|
142
|
+
if (!isMergeConf) fs.mkdirSync(confToFolder, { recursive: true });
|
|
143
|
+
|
|
144
|
+
fs.writeFileSync(
|
|
145
|
+
`${confToFolder}/.env.production`,
|
|
146
|
+
fs.readFileSync(`${confFromFolder}/.env.production`, 'utf8'),
|
|
147
|
+
'utf8',
|
|
148
|
+
);
|
|
149
|
+
fs.writeFileSync(
|
|
150
|
+
`${confToFolder}/.env.development`,
|
|
151
|
+
fs.readFileSync(`${confFromFolder}/.env.development`, 'utf8'),
|
|
152
|
+
'utf8',
|
|
153
|
+
);
|
|
154
|
+
fs.writeFileSync(`${confToFolder}/.env.test`, fs.readFileSync(`${confFromFolder}/.env.test`, 'utf8'), 'utf8');
|
|
155
|
+
|
|
156
|
+
for (const confTypeId of ['server', 'client', 'cron', 'ssr']) {
|
|
157
|
+
const confFromData = JSON.parse(fs.readFileSync(`${confFromFolder}/conf.${confTypeId}.json`, 'utf8'));
|
|
158
|
+
fs.writeFileSync(`${confToFolder}/conf.${confTypeId}.json`, formattedSrc(confFromData), 'utf8');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const packageData = JSON.parse(fs.readFileSync(`${confFromFolder}/package.json`, 'utf8'));
|
|
162
|
+
packageData.scripts.start = packageData.scripts.start.replaceAll(fromOptions.deployId, toOptions.deployId);
|
|
163
|
+
fs.writeFileSync(`${confToFolder}/package.json`, JSON.stringify(packageData, null, 4), 'utf8');
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const addClientConf = async (
|
|
167
|
+
{ toOptions, fromOptions },
|
|
168
|
+
fromDefaultOptions = { deployId: 'dd-default', clientId: 'default' },
|
|
169
|
+
) => {
|
|
170
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
171
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
172
|
+
|
|
173
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
174
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
175
|
+
|
|
176
|
+
const toClientConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.client.json`, 'utf8'));
|
|
177
|
+
const fromClientConf = JSON.parse(fs.readFileSync(`${confFromFolder}/conf.client.json`, 'utf8'));
|
|
178
|
+
|
|
179
|
+
const toClientVariableName = getCapVariableName(toOptions.clientId);
|
|
180
|
+
const fromClientVariableName = getCapVariableName(fromOptions.clientId);
|
|
181
|
+
|
|
182
|
+
const { host, path } = toOptions;
|
|
183
|
+
|
|
184
|
+
toClientConf[fromOptions.clientId] = fromClientConf[fromOptions.clientId];
|
|
185
|
+
|
|
186
|
+
fs.writeFileSync(`${confToFolder}/conf.client.json`, JSON.stringify(toClientConf, null, 4), 'utf8');
|
|
187
|
+
|
|
188
|
+
const toServerConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
189
|
+
const fromServerConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
190
|
+
|
|
191
|
+
toServerConf[host][path].client = fromOptions.clientId;
|
|
192
|
+
toServerConf[host][path].runtime = 'nodejs';
|
|
193
|
+
toServerConf[host][path].apis = fromClientConf[fromOptions.clientId].services;
|
|
194
|
+
|
|
195
|
+
fs.writeFileSync(`${confToFolder}/conf.server.json`, JSON.stringify(toServerConf, null, 4), 'utf8');
|
|
196
|
+
|
|
197
|
+
const fromSsrConf = JSON.parse(fs.readFileSync(`${confFromFolder}/conf.ssr.json`, 'utf8'));
|
|
198
|
+
const toSsrConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.ssr.json`, 'utf8'));
|
|
199
|
+
|
|
200
|
+
toSsrConf[fromClientVariableName] = fromSsrConf[fromClientVariableName];
|
|
201
|
+
|
|
202
|
+
fs.writeFileSync(`${confToFolder}/conf.ssr.json`, JSON.stringify(toSsrConf, null, 4), 'utf8');
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const buildClientSrc = async (
|
|
206
|
+
{ toOptions, fromOptions },
|
|
207
|
+
fromDefaultOptions = { deployId: 'dd-default', clientId: 'default' },
|
|
208
|
+
) => {
|
|
209
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
210
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
211
|
+
|
|
212
|
+
const confFromFolder = `./src/client/components/${fromOptions.clientId}`;
|
|
213
|
+
const confToFolder = `./src/client/components/${toOptions.clientId}`;
|
|
214
|
+
|
|
215
|
+
const toClientVariableName = getCapVariableName(toOptions.clientId);
|
|
216
|
+
const fromClientVariableName = getCapVariableName(fromOptions.clientId);
|
|
217
|
+
|
|
218
|
+
const formattedSrc = (src) =>
|
|
219
|
+
src.replaceAll(fromClientVariableName, toClientVariableName).replaceAll(fromOptions.clientId, toOptions.clientId);
|
|
220
|
+
|
|
221
|
+
const isMergeConf = fs.existsSync(confToFolder);
|
|
222
|
+
if (!isMergeConf) fs.mkdirSync(confToFolder, { recursive: true });
|
|
223
|
+
|
|
224
|
+
const files = await fs.readdir(confFromFolder, { recursive: true });
|
|
225
|
+
for (const relativePath of files) {
|
|
226
|
+
const fromFilePath = dir.resolve(`${confFromFolder}/${relativePath}`);
|
|
227
|
+
const toFilePath = dir.resolve(`${confToFolder}/${relativePath}`);
|
|
228
|
+
|
|
229
|
+
fs.writeFileSync(formattedSrc(toFilePath), formattedSrc(fs.readFileSync(fromFilePath, 'utf8')), 'utf8');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
fs.writeFileSync(
|
|
233
|
+
`./src/client/ssr/head-components/${toClientVariableName}Scripts.js`,
|
|
234
|
+
formattedSrc(fs.readFileSync(`./src/client/ssr/head-components/${fromClientVariableName}Scripts.js`, 'utf8')),
|
|
235
|
+
'utf8',
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
fs.writeFileSync(
|
|
239
|
+
`./src/client/${toClientVariableName}.js`,
|
|
240
|
+
formattedSrc(fs.readFileSync(`./src/client/${fromClientVariableName}.js`, 'utf8')),
|
|
241
|
+
'utf8',
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
fs.copySync(`./src/client/public/${fromOptions.clientId}`, `./src/client/public/${toOptions.clientId}`);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const buildApiSrc = async (
|
|
248
|
+
{ toOptions, fromOptions },
|
|
249
|
+
fromDefaultOptions = { apiId: 'default', deployId: 'dd-default', clientId: 'default' },
|
|
250
|
+
) => {
|
|
251
|
+
if (!fromOptions.apiId) fromOptions.apiId = fromDefaultOptions.apiId;
|
|
252
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
253
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
254
|
+
|
|
255
|
+
const toClientVariableName = getCapVariableName(toOptions.apiId);
|
|
256
|
+
const fromClientVariableName = getCapVariableName(fromOptions.apiId);
|
|
257
|
+
|
|
258
|
+
const formattedSrc = (src) =>
|
|
259
|
+
src.replaceAll(fromClientVariableName, toClientVariableName).replaceAll(fromOptions.apiId, toOptions.apiId);
|
|
260
|
+
|
|
261
|
+
const apiToFolder = `./src/api/${toOptions.apiId}`;
|
|
262
|
+
const apiFromFolder = `./src/api/${fromOptions.apiId}`;
|
|
263
|
+
|
|
264
|
+
const isMergeConf = fs.existsSync(apiToFolder);
|
|
265
|
+
if (!isMergeConf) fs.mkdirSync(apiToFolder, { recursive: true });
|
|
266
|
+
|
|
267
|
+
for (const srcApiType of ['model', 'controller', 'service', 'router']) {
|
|
268
|
+
fs.writeFileSync(
|
|
269
|
+
`${apiToFolder}/${toOptions.apiId}.${srcApiType}.js`,
|
|
270
|
+
formattedSrc(fs.readFileSync(`${apiFromFolder}/${fromOptions.apiId}.${srcApiType}.js`, 'utf8')),
|
|
271
|
+
'utf8',
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
fs.mkdirSync(`./src/client/services/${toOptions.apiId}`, { recursive: true });
|
|
276
|
+
if (fs.existsSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.service.js`))
|
|
277
|
+
fs.writeFileSync(
|
|
278
|
+
`./src/client/services/${toOptions.apiId}/${toOptions.apiId}.service.js`,
|
|
279
|
+
formattedSrc(
|
|
280
|
+
fs.readFileSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.service.js`, 'utf8'),
|
|
281
|
+
),
|
|
282
|
+
'utf8',
|
|
283
|
+
);
|
|
284
|
+
return;
|
|
285
|
+
if (fs.existsSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.management.js`))
|
|
286
|
+
fs.writeFileSync(
|
|
287
|
+
`./src/client/services/${toOptions.apiId}/${toOptions.apiId}.management.js`,
|
|
288
|
+
formattedSrc(
|
|
289
|
+
fs.readFileSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.management.js`, 'utf8'),
|
|
290
|
+
),
|
|
291
|
+
'utf8',
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const addApiConf = async (
|
|
296
|
+
{ toOptions, fromOptions },
|
|
297
|
+
fromDefaultOptions = { apiId: 'default', deployId: 'dd-default', clientId: 'default' },
|
|
298
|
+
) => {
|
|
299
|
+
if (!fromOptions.apiId) fromOptions.apiId = fromDefaultOptions.apiId;
|
|
300
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
301
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
302
|
+
|
|
303
|
+
const toClientVariableName = getCapVariableName(toOptions.apiId);
|
|
304
|
+
const fromClientVariableName = getCapVariableName(fromOptions.apiId);
|
|
305
|
+
|
|
306
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
307
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
308
|
+
|
|
309
|
+
const confServer = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
310
|
+
for (const host of Object.keys(confServer))
|
|
311
|
+
for (const path of Object.keys(confServer[host]))
|
|
312
|
+
if (confServer[host][path].apis) confServer[host][path].apis.push(toOptions.apiId);
|
|
313
|
+
fs.writeFileSync(`${confToFolder}/conf.server.json`, JSON.stringify(confServer, null, 4), 'utf8');
|
|
314
|
+
|
|
315
|
+
const confClient = JSON.parse(fs.readFileSync(`${confToFolder}/conf.client.json`, 'utf8'));
|
|
316
|
+
confClient[toOptions.clientId].services.push(toOptions.apiId);
|
|
317
|
+
fs.writeFileSync(`${confToFolder}/conf.client.json`, JSON.stringify(confClient, null, 4), 'utf8');
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const addWsConf = async (
|
|
321
|
+
{ toOptions, fromOptions },
|
|
322
|
+
fromDefaultOptions = { wsId: 'default', deployId: 'dd-default', host: 'default.net', paths: '/' },
|
|
323
|
+
) => {
|
|
324
|
+
if (!fromOptions.wsId) fromOptions.wsId = fromDefaultOptions.wsId;
|
|
325
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
326
|
+
if (!fromOptions.host) fromOptions.host = fromDefaultOptions.host;
|
|
327
|
+
if (!fromOptions.paths) fromOptions.paths = fromDefaultOptions.paths;
|
|
328
|
+
|
|
329
|
+
const toClientVariableName = getCapVariableName(toOptions.apiId);
|
|
330
|
+
const fromClientVariableName = getCapVariableName(fromOptions.apiId);
|
|
331
|
+
|
|
332
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
333
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
334
|
+
|
|
335
|
+
const paths = toOptions.paths.split(',');
|
|
336
|
+
|
|
337
|
+
const confServer = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
338
|
+
for (const host of Object.keys(confServer))
|
|
339
|
+
for (const path of Object.keys(confServer[host]))
|
|
340
|
+
if (host === toOptions.host && paths.includes(path) && confServer[host][path])
|
|
341
|
+
confServer[host][path].ws = toOptions.wsId;
|
|
342
|
+
fs.writeFileSync(`${confToFolder}/conf.server.json`, JSON.stringify(confServer, null, 4), 'utf8');
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const buildWsSrc = async (
|
|
346
|
+
{ toOptions, fromOptions },
|
|
347
|
+
fromDefaultOptions = { wsId: 'default', deployId: 'dd-default', host: 'default.net', paths: '/' },
|
|
348
|
+
) => {
|
|
349
|
+
if (!fromOptions.wsId) fromOptions.wsId = fromDefaultOptions.wsId;
|
|
350
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
351
|
+
if (!fromOptions.host) fromOptions.host = fromDefaultOptions.host;
|
|
352
|
+
if (!fromOptions.paths) fromOptions.paths = fromDefaultOptions.paths;
|
|
353
|
+
|
|
354
|
+
const toClientVariableName = getCapVariableName(toOptions.wsId);
|
|
355
|
+
const fromClientVariableName = getCapVariableName(fromOptions.wsId);
|
|
356
|
+
|
|
357
|
+
const confFromFolder = `./src/ws/${fromOptions.wsId}`;
|
|
358
|
+
const confToFolder = `./src/ws/${toOptions.wsId}`;
|
|
359
|
+
|
|
360
|
+
const paths = toOptions.paths.split(',');
|
|
361
|
+
|
|
362
|
+
const formattedSrc = (src) =>
|
|
363
|
+
src.replaceAll(fromClientVariableName, toClientVariableName).replaceAll(fromOptions.wsId, toOptions.wsId);
|
|
364
|
+
|
|
365
|
+
const files = await fs.readdir(confFromFolder, { recursive: true });
|
|
366
|
+
for (const relativePath of files) {
|
|
367
|
+
const fromFilePath = dir.resolve(`${confFromFolder}/${relativePath}`);
|
|
368
|
+
const toFilePath = dir.resolve(`${confToFolder}/${relativePath}`);
|
|
369
|
+
|
|
370
|
+
if (fs.lstatSync(fromFilePath).isDirectory() && !fs.existsSync(formattedSrc(toFilePath)))
|
|
371
|
+
fs.mkdirSync(formattedSrc(toFilePath), { recursive: true });
|
|
372
|
+
|
|
373
|
+
if (fs.lstatSync(fromFilePath).isFile() && !fs.existsSync(formattedSrc(toFilePath))) {
|
|
374
|
+
fs.writeFileSync(formattedSrc(toFilePath), formattedSrc(fs.readFileSync(fromFilePath, 'utf8')), 'utf8');
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const cloneSrcComponents = async ({ toOptions, fromOptions }) => {
|
|
380
|
+
const toClientVariableName = getCapVariableName(toOptions.componentsFolder);
|
|
381
|
+
const fromClientVariableName = getCapVariableName(fromOptions.componentsFolder);
|
|
382
|
+
|
|
383
|
+
const formattedSrc = (src) =>
|
|
384
|
+
src
|
|
385
|
+
.replaceAll(fromClientVariableName, toClientVariableName)
|
|
386
|
+
.replaceAll(fromOptions.componentsFolder, toOptions.componentsFolder);
|
|
387
|
+
|
|
388
|
+
const confFromFolder = `./src/client/components/${fromOptions.componentsFolder}`;
|
|
389
|
+
const confToFolder = `./src/client/components/${toOptions.componentsFolder}`;
|
|
390
|
+
|
|
391
|
+
fs.mkdirSync(confToFolder, { recursive: true });
|
|
392
|
+
|
|
393
|
+
const files = await fs.readdir(confFromFolder);
|
|
394
|
+
for (const relativePath of files) {
|
|
395
|
+
const fromFilePath = dir.resolve(`${confFromFolder}/${relativePath}`);
|
|
396
|
+
const toFilePath = dir.resolve(`${confToFolder}/${relativePath}`);
|
|
397
|
+
|
|
398
|
+
fs.writeFileSync(formattedSrc(toFilePath), formattedSrc(fs.readFileSync(fromFilePath, 'utf8')), 'utf8');
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const buildProxyRouter = () => {
|
|
403
|
+
const confServer = JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'));
|
|
404
|
+
let currentPort = parseInt(process.env.PORT) + 1;
|
|
405
|
+
const proxyRouter = {};
|
|
406
|
+
const singleReplicaHosts = [];
|
|
407
|
+
for (const host of Object.keys(confServer)) {
|
|
408
|
+
for (const path of Object.keys(confServer[host])) {
|
|
409
|
+
if (confServer[host][path].singleReplica && !singleReplicaHosts.includes(host)) {
|
|
410
|
+
singleReplicaHosts.push(host);
|
|
411
|
+
currentPort++;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
confServer[host][path].port = newInstance(currentPort);
|
|
415
|
+
for (const port of confServer[host][path].proxy) {
|
|
416
|
+
if (!(port in proxyRouter)) proxyRouter[port] = {};
|
|
417
|
+
proxyRouter[port][`${host}${path}`] = {
|
|
418
|
+
// target: `http://${host}:${confServer[host][path].port}${path}`,
|
|
419
|
+
target: `http://localhost:${confServer[host][path].port - singleReplicaHosts.length}`,
|
|
420
|
+
// target: `http://127.0.0.1:${confServer[host][path].port}`,
|
|
421
|
+
proxy: confServer[host][path].proxy,
|
|
422
|
+
redirect: confServer[host][path].redirect,
|
|
423
|
+
host,
|
|
424
|
+
path,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
currentPort++;
|
|
428
|
+
if (confServer[host][path].peer) {
|
|
429
|
+
const peerPath = path === '/' ? `/peer` : `${path}/peer`;
|
|
430
|
+
confServer[host][peerPath] = newInstance(confServer[host][path]);
|
|
431
|
+
confServer[host][peerPath].port = newInstance(currentPort);
|
|
432
|
+
for (const port of confServer[host][path].proxy) {
|
|
433
|
+
if (!(port in proxyRouter)) proxyRouter[port] = {};
|
|
434
|
+
proxyRouter[port][`${host}${peerPath}`] = {
|
|
435
|
+
// target: `http://${host}:${confServer[host][peerPath].port}${peerPath}`,
|
|
436
|
+
target: `http://localhost:${confServer[host][peerPath].port - singleReplicaHosts.length}`,
|
|
437
|
+
// target: `http://127.0.0.1:${confServer[host][peerPath].port}`,
|
|
438
|
+
proxy: confServer[host][peerPath].proxy,
|
|
439
|
+
host,
|
|
440
|
+
path: peerPath,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
currentPort++;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return proxyRouter;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const cliBar = async (time = 5000) => {
|
|
451
|
+
// create new progress bar
|
|
452
|
+
const b = new cliProgress.SingleBar({
|
|
453
|
+
format: 'Delay | {bar} | {percentage}% || {value}/{total} Chunks || Speed: {speed}',
|
|
454
|
+
barCompleteChar: '\u2588',
|
|
455
|
+
barIncompleteChar: '\u2591',
|
|
456
|
+
hideCursor: true,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
const maxValueDisplay = 200;
|
|
460
|
+
const minValueDisplay = 0;
|
|
461
|
+
const steps = 10;
|
|
462
|
+
const incrementValue = 200 / steps;
|
|
463
|
+
const delayTime = time / steps;
|
|
464
|
+
// initialize the bar - defining payload token "speed" with the default value "N/A"
|
|
465
|
+
b.start(maxValueDisplay, minValueDisplay, {
|
|
466
|
+
speed: 'N/A',
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// update values
|
|
470
|
+
// b1.increment();
|
|
471
|
+
// b1.update(20);
|
|
472
|
+
|
|
473
|
+
for (const step of range(1, steps)) {
|
|
474
|
+
b.increment(incrementValue);
|
|
475
|
+
await timer(delayTime);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// stop the bar
|
|
479
|
+
b.stop();
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
const cliSpinner = async (time = 5000, message0, message1, color, type = 'dots') => {
|
|
483
|
+
const { frames, interval } = cliSpinners[type];
|
|
484
|
+
const steps = parseInt(time / interval);
|
|
485
|
+
let index = 0;
|
|
486
|
+
for (const step of range(1, steps)) {
|
|
487
|
+
const msg = `${message0 ? message0 : ''}${frames[index]}${message1 ? message1 : ''}`;
|
|
488
|
+
logUpdate(color ? msg[color] : msg);
|
|
489
|
+
await timer(interval);
|
|
490
|
+
index++;
|
|
491
|
+
if (index === frames.length) index = 0;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const buildReplicaId = ({ deployId, replica }) => `${deployId}-${replica.slice(1)}`;
|
|
496
|
+
|
|
497
|
+
const getDataDeploy = (
|
|
498
|
+
options = { buildSingleReplica: false, deployGroupId: '', deployId: '', disableSyncEnvPort: false },
|
|
499
|
+
) => {
|
|
500
|
+
let dataDeploy = JSON.parse(fs.readFileSync(`./engine-private/deploy/${options.deployGroupId}.json`, 'utf8'));
|
|
501
|
+
|
|
502
|
+
if (options.deployId) dataDeploy = dataDeploy.filter((d) => d === options.deployId);
|
|
503
|
+
|
|
504
|
+
dataDeploy = dataDeploy.map((deployId) => {
|
|
505
|
+
return {
|
|
506
|
+
deployId,
|
|
507
|
+
};
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
if (options && options.buildSingleReplica && fs.existsSync(`./engine-private/replica`))
|
|
511
|
+
fs.removeSync(`./engine-private/replica`);
|
|
512
|
+
|
|
513
|
+
let buildDataDeploy = [];
|
|
514
|
+
for (const deployObj of dataDeploy) {
|
|
515
|
+
const serverConf = loadReplicas(
|
|
516
|
+
JSON.parse(fs.readFileSync(`./engine-private/conf/${deployObj.deployId}/conf.server.json`, 'utf8')),
|
|
517
|
+
);
|
|
518
|
+
let replicaDataDeploy = [];
|
|
519
|
+
for (const host of Object.keys(serverConf))
|
|
520
|
+
for (const path of Object.keys(serverConf[host])) {
|
|
521
|
+
if (serverConf[host][path].replicas && serverConf[host][path].singleReplica) {
|
|
522
|
+
if (options && options.buildSingleReplica) shellExec(Cmd.replica(deployObj.deployId, host, path));
|
|
523
|
+
replicaDataDeploy = replicaDataDeploy.concat(
|
|
524
|
+
serverConf[host][path].replicas.map((r) => {
|
|
525
|
+
return {
|
|
526
|
+
deployId: buildReplicaId({ deployId: deployObj.deployId, replica: r }),
|
|
527
|
+
replicaHost: host,
|
|
528
|
+
};
|
|
529
|
+
}),
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
buildDataDeploy.push(deployObj);
|
|
534
|
+
if (replicaDataDeploy.length > 0) buildDataDeploy = buildDataDeploy.concat(replicaDataDeploy);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
const enableSyncEnvPort = !options.disableSyncEnvPort && options.buildSingleReplica;
|
|
538
|
+
if (enableSyncEnvPort) shellExec(Cmd.syncPorts(options.deployGroupId));
|
|
539
|
+
|
|
540
|
+
logger.info('buildDataDeploy', { buildDataDeploy, enableSyncEnvPort });
|
|
541
|
+
|
|
542
|
+
return buildDataDeploy;
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
const validateTemplatePath = (absolutePath = '') => {
|
|
546
|
+
const host = 'default.net';
|
|
547
|
+
const path = '/';
|
|
548
|
+
const client = 'default';
|
|
549
|
+
const ssr = 'Default';
|
|
550
|
+
const confServer = DefaultConf.server[host][path];
|
|
551
|
+
const confClient = DefaultConf.client[client];
|
|
552
|
+
const confSsr = DefaultConf.ssr[ssr];
|
|
553
|
+
const clients = Object.keys(confClient).concat(['core', 'test']);
|
|
554
|
+
|
|
555
|
+
if (absolutePath.match('src/api') && !confServer.apis.find((p) => absolutePath.match(`src/api/${p}/`))) {
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
if (
|
|
559
|
+
absolutePath.match('src/client/services/') &&
|
|
560
|
+
!clients.find((p) => absolutePath.match(`src/client/services/${p}/`))
|
|
561
|
+
) {
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
if (absolutePath.match('src/client/public/') && !clients.find((p) => absolutePath.match(`src/client/public/${p}/`))) {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
if (
|
|
568
|
+
absolutePath.match('src/client/components/') &&
|
|
569
|
+
!clients.find((p) => absolutePath.match(`src/client/components/${p}/`))
|
|
570
|
+
) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
if (absolutePath.match('src/client/sw/') && !clients.find((p) => absolutePath.match(`src/client/sw/${p}.sw.js`))) {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
if (
|
|
577
|
+
absolutePath.match('src/client/ssr/body-components') &&
|
|
578
|
+
!confSsr.body.find((p) => absolutePath.match(`src/client/ssr/body-components/${p}.js`))
|
|
579
|
+
) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
if (
|
|
583
|
+
absolutePath.match('src/client/ssr/head-components') &&
|
|
584
|
+
!confSsr.head.find((p) => absolutePath.match(`src/client/ssr/head-components/${p}.js`))
|
|
585
|
+
) {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
if (
|
|
589
|
+
absolutePath.match('/client') &&
|
|
590
|
+
absolutePath.match('.index.js') &&
|
|
591
|
+
!clients.find((p) => absolutePath.match(`src/client/${capFirst(p)}.index.js`))
|
|
592
|
+
) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
if (absolutePath.match('src/ws/') && !clients.find((p) => absolutePath.match(`src/ws/${p}/`))) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
return true;
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
const deployTest = async (dataDeploy) => {
|
|
602
|
+
const failed = [];
|
|
603
|
+
for (const deploy of dataDeploy) {
|
|
604
|
+
const deployServerConfPath = fs.existsSync(`./engine-private/replica/${deploy.deployId}/conf.server.json`)
|
|
605
|
+
? `./engine-private/replica/${deploy.deployId}/conf.server.json`
|
|
606
|
+
: `./engine-private/conf/${deploy.deployId}/conf.server.json`;
|
|
607
|
+
const serverConf = loadReplicas(JSON.parse(fs.readFileSync(deployServerConfPath, 'utf8')));
|
|
608
|
+
let fail = false;
|
|
609
|
+
for (const host of Object.keys(serverConf))
|
|
610
|
+
for (const path of Object.keys(serverConf[host])) {
|
|
611
|
+
const urlTest = `https://${host}${path}`;
|
|
612
|
+
try {
|
|
613
|
+
const result = await axios.get(urlTest);
|
|
614
|
+
const test = result.data.split('<title>');
|
|
615
|
+
if (test[1])
|
|
616
|
+
logger.info('Success deploy', {
|
|
617
|
+
...deploy,
|
|
618
|
+
result: test[1].split('</title>')[0],
|
|
619
|
+
urlTest,
|
|
620
|
+
});
|
|
621
|
+
else {
|
|
622
|
+
logger.error('Error deploy', {
|
|
623
|
+
...deploy,
|
|
624
|
+
result: result.data,
|
|
625
|
+
urlTest,
|
|
626
|
+
});
|
|
627
|
+
fail = true;
|
|
628
|
+
}
|
|
629
|
+
} catch (error) {
|
|
630
|
+
logger.error('Error deploy', {
|
|
631
|
+
...deploy,
|
|
632
|
+
message: error.message,
|
|
633
|
+
urlTest,
|
|
634
|
+
});
|
|
635
|
+
fail = true;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (fail) failed.push(deploy);
|
|
639
|
+
}
|
|
640
|
+
return { failed };
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
const getDeployGroupId = () => {
|
|
644
|
+
const deployGroupIndexArg = process.argv.findIndex((a) => a.match(`deploy-group:`));
|
|
645
|
+
if (deployGroupIndexArg > -1) return process.argv[deployGroupIndexArg].split(':')[1].trim();
|
|
646
|
+
return 'dd';
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
const getCronBackUpFolder = (host = '', path = '') => {
|
|
650
|
+
return `${host}${path.replace(/\\/g, '/').replace(`/`, '-')}`;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
const execDeploy = async (options = { deployId: 'default' }) => {
|
|
654
|
+
const { deployId } = options;
|
|
655
|
+
shellExec(Cmd.delete(deployId));
|
|
656
|
+
shellExec(Cmd.conf(deployId));
|
|
657
|
+
shellExec(Cmd.run(deployId));
|
|
658
|
+
return await new Promise(async (resolve) => {
|
|
659
|
+
const maxTime = 1000 * 60 * 5;
|
|
660
|
+
const minTime = 10000 * 2;
|
|
661
|
+
const intervalTime = 1000;
|
|
662
|
+
let currentTime = 0;
|
|
663
|
+
const attempt = () => {
|
|
664
|
+
if (currentTime >= minTime && !fs.existsSync(`./tmp/await-deploy`)) {
|
|
665
|
+
clearInterval(processMonitor);
|
|
666
|
+
return resolve(true);
|
|
667
|
+
}
|
|
668
|
+
cliSpinner(
|
|
669
|
+
intervalTime,
|
|
670
|
+
`[deploy.js] `,
|
|
671
|
+
` Load instance | elapsed time ${currentTime / 1000}s / ${maxTime / 1000}s`,
|
|
672
|
+
'yellow',
|
|
673
|
+
'material',
|
|
674
|
+
);
|
|
675
|
+
currentTime += intervalTime;
|
|
676
|
+
if (currentTime >= maxTime) return resolve(false);
|
|
677
|
+
};
|
|
678
|
+
const processMonitor = setInterval(attempt, intervalTime);
|
|
679
|
+
});
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
const deployRun = async (dataDeploy, reset) => {
|
|
683
|
+
if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
|
|
684
|
+
if (reset) fs.writeFileSync(`./tmp/runtime-router.json`, '{}', 'utf8');
|
|
685
|
+
for (const deploy of dataDeploy) await execDeploy(deploy);
|
|
686
|
+
const { failed } = await deployTest(dataDeploy);
|
|
687
|
+
if (failed.length > 0) {
|
|
688
|
+
for (const deploy of failed) logger.error(deploy.deployId, Cmd.run(deploy.deployId));
|
|
689
|
+
await read({ prompt: 'Press enter to retry failed processes\n' });
|
|
690
|
+
await deployRun(failed);
|
|
691
|
+
} else logger.info(`Deploy process successfully`);
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
const updateSrc = () => {
|
|
695
|
+
const silent = true;
|
|
696
|
+
shellExec(`git pull origin master`, { silent });
|
|
697
|
+
shellCd(`engine-private`);
|
|
698
|
+
shellExec(`git pull origin master`, { silent });
|
|
699
|
+
shellCd(`..`);
|
|
700
|
+
// shellExec(`npm install && npm install --only=dev`);
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const restoreMacroDb = async (deployGroupId = '') => {
|
|
704
|
+
const dataDeploy = await getDataDeploy({ deployGroupId, buildSingleReplica: false });
|
|
705
|
+
for (const deployGroup of dataDeploy) {
|
|
706
|
+
if (!deployGroup.replicaHost) {
|
|
707
|
+
const deployServerConfPath = `./engine-private/conf/${deployGroup.deployId}/conf.server.json`;
|
|
708
|
+
const serverConf = JSON.parse(fs.readFileSync(deployServerConfPath, 'utf8'));
|
|
709
|
+
|
|
710
|
+
for (const host of Object.keys(serverConf)) {
|
|
711
|
+
for (const path of Object.keys(serverConf[host])) {
|
|
712
|
+
const { db, singleReplica } = serverConf[host][path];
|
|
713
|
+
if (db && !singleReplica) {
|
|
714
|
+
const cmd = `node bin/db ${host}${path} import ${deployGroup.deployId} cron`;
|
|
715
|
+
shellExec(cmd);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
const mergeBackUp = async (baseBackJsonPath, outputFilePath) => {
|
|
724
|
+
const names = JSON.parse(fs.readFileSync(baseBackJsonPath, 'utf8')).map((p) =>
|
|
725
|
+
p.replaceAll(`\\`, '/').replaceAll('C:/', '/').replaceAll('c:/', '/'),
|
|
726
|
+
);
|
|
727
|
+
await new Promise((resolve) => {
|
|
728
|
+
splitFile
|
|
729
|
+
.mergeFiles(names, outputFilePath)
|
|
730
|
+
.then(() => {
|
|
731
|
+
resolve();
|
|
732
|
+
})
|
|
733
|
+
.catch((err) => {
|
|
734
|
+
console.log('Error: ', err);
|
|
735
|
+
resolve();
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
const getRestoreCronCmd = async (options = { host: '', path: '', conf: {}, deployId: '' }) => {
|
|
741
|
+
const { host, path, conf, deployId } = options;
|
|
742
|
+
const { runtime, db, git, directory } = conf[host][path];
|
|
743
|
+
const { provider, name, user, password = '', backupPath = '' } = db;
|
|
744
|
+
|
|
745
|
+
if (['xampp', 'lampp'].includes(runtime)) {
|
|
746
|
+
logger.info('Create database', `node bin/db ${host}${path} create ${deployId}`);
|
|
747
|
+
shellExec(`node bin/db ${host}${path} create ${deployId}`);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if (git) {
|
|
751
|
+
if (directory && !fs.existsSync(directory)) fs.mkdirSync(directory, { recursive: true });
|
|
752
|
+
|
|
753
|
+
shellExec(`git clone ${git}`);
|
|
754
|
+
|
|
755
|
+
// fs.mkdirSync(`./public/${host}${path}`, { recursive: true });
|
|
756
|
+
|
|
757
|
+
if (fs.existsSync(`./${git.split('/').pop()}`))
|
|
758
|
+
fs.moveSync(`./${git.split('/').pop()}`, directory ? directory : `./public/${host}${path}`, {
|
|
759
|
+
overwrite: true,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
let cmd, currentBackupTimestamp, baseBackUpPath;
|
|
764
|
+
|
|
765
|
+
if (process.argv.includes('cron')) {
|
|
766
|
+
baseBackUpPath = `${process.cwd()}/engine-private/cron-backups/${getCronBackUpFolder(host, path)}`;
|
|
767
|
+
|
|
768
|
+
const files = await fs.readdir(baseBackUpPath, { withFileTypes: true });
|
|
769
|
+
|
|
770
|
+
currentBackupTimestamp = files
|
|
771
|
+
.map((fileObj) => parseInt(fileObj.name))
|
|
772
|
+
.sort((a, b) => a - b)
|
|
773
|
+
.reverse()[0];
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
switch (provider) {
|
|
777
|
+
case 'mariadb':
|
|
778
|
+
{
|
|
779
|
+
if (process.argv.includes('cron')) {
|
|
780
|
+
cmd = `mysql -u ${user} -p${password} ${name} < ${baseBackUpPath}/${currentBackupTimestamp}/${name}.sql`;
|
|
781
|
+
if (fs.existsSync(`${baseBackUpPath}/${currentBackupTimestamp}/${name}-parths.json`))
|
|
782
|
+
await mergeBackUp(
|
|
783
|
+
`${baseBackUpPath}/${currentBackupTimestamp}/${name}-parths.json`,
|
|
784
|
+
`${baseBackUpPath}/${currentBackupTimestamp}/${name}.sql`,
|
|
785
|
+
);
|
|
786
|
+
} else {
|
|
787
|
+
cmd = `mysql -u ${user} -p${password} ${name} < ${
|
|
788
|
+
backupPath ? backupPath : `./engine-private/sql-backups/${name}.sql`
|
|
789
|
+
}`;
|
|
790
|
+
if (
|
|
791
|
+
fs.existsSync(
|
|
792
|
+
`${
|
|
793
|
+
backupPath ? backupPath.split('/').slice(0, -1).join('/') : `./engine-private/sql-backups`
|
|
794
|
+
}/${name}-parths.json`,
|
|
795
|
+
)
|
|
796
|
+
)
|
|
797
|
+
await mergeBackUp(
|
|
798
|
+
`${
|
|
799
|
+
backupPath ? backupPath.split('/').slice(0, -1).join('/') : `./engine-private/sql-backups`
|
|
800
|
+
}/${name}-parths.json`,
|
|
801
|
+
`${
|
|
802
|
+
backupPath ? backupPath.split('/').slice(0, -1).join('/') : `./engine-private/sql-backups`
|
|
803
|
+
}/${name}.sql`,
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
break;
|
|
808
|
+
|
|
809
|
+
case 'mongoose':
|
|
810
|
+
{
|
|
811
|
+
if (process.argv.includes('cron')) {
|
|
812
|
+
cmd = `mongorestore -d ${name} ${baseBackUpPath}/${currentBackupTimestamp}/${name}`;
|
|
813
|
+
} else cmd = `mongorestore -d ${name} ${backupPath ? backupPath : `./engine-private/mongodb-backup/${name}`}`;
|
|
814
|
+
}
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// logger.info('Restore', cmd);
|
|
819
|
+
|
|
820
|
+
return cmd;
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
const Cmd = {
|
|
824
|
+
delete: (deployId) => `pm2 delete ${deployId}`,
|
|
825
|
+
run: (deployId) => `node bin/deploy run ${deployId}`,
|
|
826
|
+
build: (deployId) => `node bin/deploy build-full-client ${deployId}${process.argv.includes('l') ? ' l' : ''}`,
|
|
827
|
+
conf: (deployId, env) => `node bin/deploy conf ${deployId} ${env ? env : 'production'}`,
|
|
828
|
+
replica: (deployId, host, path) => `node bin/deploy build-single-replica ${deployId} ${host} ${path}`,
|
|
829
|
+
syncPorts: (deployGroupId) => `node bin/deploy sync-env-port ${deployGroupId}`,
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
export {
|
|
833
|
+
Cmd,
|
|
834
|
+
Config,
|
|
835
|
+
loadConf,
|
|
836
|
+
loadReplicas,
|
|
837
|
+
cloneConf,
|
|
838
|
+
getCapVariableName,
|
|
839
|
+
buildClientSrc,
|
|
840
|
+
buildApiSrc,
|
|
841
|
+
addApiConf,
|
|
842
|
+
addClientConf,
|
|
843
|
+
addWsConf,
|
|
844
|
+
buildWsSrc,
|
|
845
|
+
cloneSrcComponents,
|
|
846
|
+
buildProxyRouter,
|
|
847
|
+
cliBar,
|
|
848
|
+
cliSpinner,
|
|
849
|
+
getDataDeploy,
|
|
850
|
+
validateTemplatePath,
|
|
851
|
+
buildReplicaId,
|
|
852
|
+
restoreMacroDb,
|
|
853
|
+
getDeployGroupId,
|
|
854
|
+
execDeploy,
|
|
855
|
+
deployRun,
|
|
856
|
+
updateSrc,
|
|
857
|
+
getCronBackUpFolder,
|
|
858
|
+
getRestoreCronCmd,
|
|
859
|
+
mergeBackUp,
|
|
860
|
+
};
|