@underpostnet/underpost 2.7.9

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.
Files changed (297) hide show
  1. package/.dockerignore +14 -0
  2. package/.env.development +6 -0
  3. package/.env.production +6 -0
  4. package/.env.test +6 -0
  5. package/.github/workflows/ghpkg.yml +115 -0
  6. package/.github/workflows/publish.yml +84 -0
  7. package/.github/workflows/pwa-microservices-template.page.yml +54 -0
  8. package/.github/workflows/pwa-microservices-template.test.yml +30 -0
  9. package/.nycrc +9 -0
  10. package/.prettierignore +13 -0
  11. package/.prettierrc +9 -0
  12. package/.vscode/extensions.json +72 -0
  13. package/.vscode/settings.json +106 -0
  14. package/AUTHORS.md +10 -0
  15. package/CHANGELOG.md +85 -0
  16. package/Dockerfile +90 -0
  17. package/LICENSE +21 -0
  18. package/README.md +96 -0
  19. package/bin/cron.js +47 -0
  20. package/bin/db.js +180 -0
  21. package/bin/deploy.js +859 -0
  22. package/bin/file.js +109 -0
  23. package/bin/index.js +82 -0
  24. package/bin/ssl.js +55 -0
  25. package/bin/util.js +204 -0
  26. package/bin/vs.js +35 -0
  27. package/conf.js +265 -0
  28. package/docker-compose.yml +67 -0
  29. package/jsconfig.json +7 -0
  30. package/jsdoc.json +32 -0
  31. package/nodemon.json +6 -0
  32. package/package.json +134 -0
  33. package/prometheus.yml +36 -0
  34. package/src/api/core/core.controller.js +69 -0
  35. package/src/api/core/core.model.js +11 -0
  36. package/src/api/core/core.router.js +23 -0
  37. package/src/api/core/core.service.js +31 -0
  38. package/src/api/crypto/crypto.controller.js +51 -0
  39. package/src/api/crypto/crypto.model.js +23 -0
  40. package/src/api/crypto/crypto.router.js +20 -0
  41. package/src/api/crypto/crypto.service.js +64 -0
  42. package/src/api/default/default.controller.js +69 -0
  43. package/src/api/default/default.model.js +20 -0
  44. package/src/api/default/default.router.js +23 -0
  45. package/src/api/default/default.service.js +31 -0
  46. package/src/api/file/file.controller.js +53 -0
  47. package/src/api/file/file.model.js +19 -0
  48. package/src/api/file/file.router.js +21 -0
  49. package/src/api/file/file.service.js +80 -0
  50. package/src/api/instance/instance.controller.js +69 -0
  51. package/src/api/instance/instance.model.js +36 -0
  52. package/src/api/instance/instance.router.js +33 -0
  53. package/src/api/instance/instance.service.js +48 -0
  54. package/src/api/test/test.controller.js +59 -0
  55. package/src/api/test/test.model.js +14 -0
  56. package/src/api/test/test.router.js +21 -0
  57. package/src/api/test/test.service.js +35 -0
  58. package/src/api/user/user.build.js +16 -0
  59. package/src/api/user/user.controller.js +70 -0
  60. package/src/api/user/user.model.js +65 -0
  61. package/src/api/user/user.router.js +345 -0
  62. package/src/api/user/user.service.js +479 -0
  63. package/src/api.js +23 -0
  64. package/src/client/Default.index.js +40 -0
  65. package/src/client/components/core/Account.js +290 -0
  66. package/src/client/components/core/AgGrid.js +160 -0
  67. package/src/client/components/core/Auth.js +19 -0
  68. package/src/client/components/core/Badge.js +32 -0
  69. package/src/client/components/core/Blockchain.js +41 -0
  70. package/src/client/components/core/Blog.js +9 -0
  71. package/src/client/components/core/BtnIcon.js +101 -0
  72. package/src/client/components/core/CalendarCore.js +458 -0
  73. package/src/client/components/core/Chat.js +64 -0
  74. package/src/client/components/core/ColorPalette.js +5267 -0
  75. package/src/client/components/core/CommonJs.js +742 -0
  76. package/src/client/components/core/Content.js +193 -0
  77. package/src/client/components/core/Css.js +846 -0
  78. package/src/client/components/core/CssCore.js +844 -0
  79. package/src/client/components/core/D3Chart.js +44 -0
  80. package/src/client/components/core/Docs.js +331 -0
  81. package/src/client/components/core/DropDown.js +164 -0
  82. package/src/client/components/core/EventsUI.js +46 -0
  83. package/src/client/components/core/FileExplorer.js +699 -0
  84. package/src/client/components/core/FullScreen.js +45 -0
  85. package/src/client/components/core/Input.js +346 -0
  86. package/src/client/components/core/JoyStick.js +77 -0
  87. package/src/client/components/core/Keyboard.js +73 -0
  88. package/src/client/components/core/LoadingAnimation.js +178 -0
  89. package/src/client/components/core/LogIn.js +187 -0
  90. package/src/client/components/core/LogOut.js +58 -0
  91. package/src/client/components/core/Logger.js +26 -0
  92. package/src/client/components/core/Modal.js +1814 -0
  93. package/src/client/components/core/NotificationManager.js +84 -0
  94. package/src/client/components/core/Panel.js +613 -0
  95. package/src/client/components/core/PanelForm.js +469 -0
  96. package/src/client/components/core/Polyhedron.js +162 -0
  97. package/src/client/components/core/Recover.js +204 -0
  98. package/src/client/components/core/Responsive.js +68 -0
  99. package/src/client/components/core/RichText.js +53 -0
  100. package/src/client/components/core/Router.js +76 -0
  101. package/src/client/components/core/Scroll.js +34 -0
  102. package/src/client/components/core/SignUp.js +125 -0
  103. package/src/client/components/core/SocketIo.js +72 -0
  104. package/src/client/components/core/Stream.js +113 -0
  105. package/src/client/components/core/ToggleSwitch.js +87 -0
  106. package/src/client/components/core/ToolTip.js +26 -0
  107. package/src/client/components/core/Translate.js +446 -0
  108. package/src/client/components/core/Validator.js +100 -0
  109. package/src/client/components/core/VanillaJs.js +463 -0
  110. package/src/client/components/core/Wallet.js +106 -0
  111. package/src/client/components/core/WebComponent.js +44 -0
  112. package/src/client/components/core/Webhook.js +25 -0
  113. package/src/client/components/core/Worker.js +280 -0
  114. package/src/client/components/default/CommonDefault.js +29 -0
  115. package/src/client/components/default/CssDefault.js +13 -0
  116. package/src/client/components/default/ElementsDefault.js +38 -0
  117. package/src/client/components/default/LogInDefault.js +41 -0
  118. package/src/client/components/default/LogOutDefault.js +28 -0
  119. package/src/client/components/default/MenuDefault.js +389 -0
  120. package/src/client/components/default/RoutesDefault.js +48 -0
  121. package/src/client/components/default/SettingsDefault.js +16 -0
  122. package/src/client/components/default/SignUpDefault.js +9 -0
  123. package/src/client/components/default/SocketIoDefault.js +54 -0
  124. package/src/client/components/default/TranslateDefault.js +7 -0
  125. package/src/client/public/default/android-chrome-144x144.png +0 -0
  126. package/src/client/public/default/android-chrome-192x192.png +0 -0
  127. package/src/client/public/default/android-chrome-256x256.png +0 -0
  128. package/src/client/public/default/android-chrome-36x36.png +0 -0
  129. package/src/client/public/default/android-chrome-384x384.png +0 -0
  130. package/src/client/public/default/android-chrome-48x48.png +0 -0
  131. package/src/client/public/default/android-chrome-512x512.png +0 -0
  132. package/src/client/public/default/android-chrome-72x72.png +0 -0
  133. package/src/client/public/default/android-chrome-96x96.png +0 -0
  134. package/src/client/public/default/apple-touch-icon-1024x1024.png +0 -0
  135. package/src/client/public/default/apple-touch-icon-114x114.png +0 -0
  136. package/src/client/public/default/apple-touch-icon-120x120.png +0 -0
  137. package/src/client/public/default/apple-touch-icon-144x144.png +0 -0
  138. package/src/client/public/default/apple-touch-icon-152x152.png +0 -0
  139. package/src/client/public/default/apple-touch-icon-167x167.png +0 -0
  140. package/src/client/public/default/apple-touch-icon-180x180.png +0 -0
  141. package/src/client/public/default/apple-touch-icon-57x57.png +0 -0
  142. package/src/client/public/default/apple-touch-icon-60x60.png +0 -0
  143. package/src/client/public/default/apple-touch-icon-72x72.png +0 -0
  144. package/src/client/public/default/apple-touch-icon-76x76.png +0 -0
  145. package/src/client/public/default/apple-touch-icon-precomposed.png +0 -0
  146. package/src/client/public/default/apple-touch-icon.png +0 -0
  147. package/src/client/public/default/apple-touch-startup-image-1125x2436.png +0 -0
  148. package/src/client/public/default/apple-touch-startup-image-1136x640.png +0 -0
  149. package/src/client/public/default/apple-touch-startup-image-1170x2532.png +0 -0
  150. package/src/client/public/default/apple-touch-startup-image-1179x2556.png +0 -0
  151. package/src/client/public/default/apple-touch-startup-image-1242x2208.png +0 -0
  152. package/src/client/public/default/apple-touch-startup-image-1242x2688.png +0 -0
  153. package/src/client/public/default/apple-touch-startup-image-1284x2778.png +0 -0
  154. package/src/client/public/default/apple-touch-startup-image-1290x2796.png +0 -0
  155. package/src/client/public/default/apple-touch-startup-image-1334x750.png +0 -0
  156. package/src/client/public/default/apple-touch-startup-image-1488x2266.png +0 -0
  157. package/src/client/public/default/apple-touch-startup-image-1536x2048.png +0 -0
  158. package/src/client/public/default/apple-touch-startup-image-1620x2160.png +0 -0
  159. package/src/client/public/default/apple-touch-startup-image-1640x2160.png +0 -0
  160. package/src/client/public/default/apple-touch-startup-image-1668x2224.png +0 -0
  161. package/src/client/public/default/apple-touch-startup-image-1668x2388.png +0 -0
  162. package/src/client/public/default/apple-touch-startup-image-1792x828.png +0 -0
  163. package/src/client/public/default/apple-touch-startup-image-2048x1536.png +0 -0
  164. package/src/client/public/default/apple-touch-startup-image-2048x2732.png +0 -0
  165. package/src/client/public/default/apple-touch-startup-image-2160x1620.png +0 -0
  166. package/src/client/public/default/apple-touch-startup-image-2160x1640.png +0 -0
  167. package/src/client/public/default/apple-touch-startup-image-2208x1242.png +0 -0
  168. package/src/client/public/default/apple-touch-startup-image-2224x1668.png +0 -0
  169. package/src/client/public/default/apple-touch-startup-image-2266x1488.png +0 -0
  170. package/src/client/public/default/apple-touch-startup-image-2388x1668.png +0 -0
  171. package/src/client/public/default/apple-touch-startup-image-2436x1125.png +0 -0
  172. package/src/client/public/default/apple-touch-startup-image-2532x1170.png +0 -0
  173. package/src/client/public/default/apple-touch-startup-image-2556x1179.png +0 -0
  174. package/src/client/public/default/apple-touch-startup-image-2688x1242.png +0 -0
  175. package/src/client/public/default/apple-touch-startup-image-2732x2048.png +0 -0
  176. package/src/client/public/default/apple-touch-startup-image-2778x1284.png +0 -0
  177. package/src/client/public/default/apple-touch-startup-image-2796x1290.png +0 -0
  178. package/src/client/public/default/apple-touch-startup-image-640x1136.png +0 -0
  179. package/src/client/public/default/apple-touch-startup-image-750x1334.png +0 -0
  180. package/src/client/public/default/apple-touch-startup-image-828x1792.png +0 -0
  181. package/src/client/public/default/assets/background/white.jpg +0 -0
  182. package/src/client/public/default/assets/background/white0-min.jpg +0 -0
  183. package/src/client/public/default/assets/background/white0.jpg +0 -0
  184. package/src/client/public/default/assets/logo/base-icon.png +0 -0
  185. package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
  186. package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
  187. package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
  188. package/src/client/public/default/browserconfig.xml +12 -0
  189. package/src/client/public/default/favicon-16x16.png +0 -0
  190. package/src/client/public/default/favicon-32x32.png +0 -0
  191. package/src/client/public/default/favicon-48x48.png +0 -0
  192. package/src/client/public/default/favicon.ico +0 -0
  193. package/src/client/public/default/manifest.webmanifest +69 -0
  194. package/src/client/public/default/mstile-144x144.png +0 -0
  195. package/src/client/public/default/mstile-150x150.png +0 -0
  196. package/src/client/public/default/mstile-310x150.png +0 -0
  197. package/src/client/public/default/mstile-310x310.png +0 -0
  198. package/src/client/public/default/mstile-70x70.png +0 -0
  199. package/src/client/public/default/plantuml/client-conf.svg +1 -0
  200. package/src/client/public/default/plantuml/client-schema.svg +1 -0
  201. package/src/client/public/default/plantuml/cron-conf.svg +1 -0
  202. package/src/client/public/default/plantuml/cron-schema.svg +1 -0
  203. package/src/client/public/default/plantuml/server-conf.svg +1 -0
  204. package/src/client/public/default/plantuml/server-schema.svg +1 -0
  205. package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
  206. package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
  207. package/src/client/public/default/site.webmanifest +69 -0
  208. package/src/client/public/default/sitemap +148 -0
  209. package/src/client/public/default/yandex-browser-50x50.png +0 -0
  210. package/src/client/public/default/yandex-browser-manifest.json +9 -0
  211. package/src/client/public/doc/favicon.ico +0 -0
  212. package/src/client/public/doc/sitemap +148 -0
  213. package/src/client/public/test/favicon.ico +0 -0
  214. package/src/client/public/test/sitemap +148 -0
  215. package/src/client/services/core/core.service.js +170 -0
  216. package/src/client/services/crypto/crypto.service.js +70 -0
  217. package/src/client/services/default/default.management.js +343 -0
  218. package/src/client/services/default/default.service.js +89 -0
  219. package/src/client/services/file/file.service.js +70 -0
  220. package/src/client/services/instance/instance.management.js +74 -0
  221. package/src/client/services/instance/instance.service.js +89 -0
  222. package/src/client/services/test/test.service.js +70 -0
  223. package/src/client/services/user/user.management.js +50 -0
  224. package/src/client/services/user/user.service.js +89 -0
  225. package/src/client/ssr/Render.js +237 -0
  226. package/src/client/ssr/common/Alert.js +75 -0
  227. package/src/client/ssr/common/SsrCore.js +91 -0
  228. package/src/client/ssr/common/Translate.js +26 -0
  229. package/src/client/ssr/common/Worker.js +28 -0
  230. package/src/client/ssr/components/body/CacheControl.js +114 -0
  231. package/src/client/ssr/components/body/DefaultSplashScreen.js +90 -0
  232. package/src/client/ssr/components/email/DefaultRecoverEmail.js +21 -0
  233. package/src/client/ssr/components/email/DefaultVerifyEmail.js +17 -0
  234. package/src/client/ssr/components/head/Css.js +241 -0
  235. package/src/client/ssr/components/head/DefaultScripts.js +3 -0
  236. package/src/client/ssr/components/head/Production.js +1 -0
  237. package/src/client/ssr/components/head/Pwa.js +146 -0
  238. package/src/client/ssr/components/head/PwaDefault.js +60 -0
  239. package/src/client/ssr/components/head/Seo.js +14 -0
  240. package/src/client/ssr/pages/404.js +12 -0
  241. package/src/client/ssr/pages/500.js +12 -0
  242. package/src/client/ssr/pages/maintenance.js +14 -0
  243. package/src/client/ssr/pages/offline.js +21 -0
  244. package/src/client/sw/default.sw.js +205 -0
  245. package/src/client/sw/template.sw.js +84 -0
  246. package/src/client.build.js +22 -0
  247. package/src/client.dev.js +21 -0
  248. package/src/db/DataBaseProvider.js +45 -0
  249. package/src/db/mariadb/MariaDB.js +33 -0
  250. package/src/db/mongo/MongooseDB.js +124 -0
  251. package/src/dns.js +22 -0
  252. package/src/index.js +43 -0
  253. package/src/mailer/EmailRender.js +69 -0
  254. package/src/mailer/MailerProvider.js +96 -0
  255. package/src/proxy.js +22 -0
  256. package/src/runtime/lampp/Lampp.js +115 -0
  257. package/src/runtime/nginx/Nginx.js +3 -0
  258. package/src/runtime/xampp/Xampp.js +49 -0
  259. package/src/server/auth.js +235 -0
  260. package/src/server/backup.js +120 -0
  261. package/src/server/client-build-live.js +98 -0
  262. package/src/server/client-build.js +754 -0
  263. package/src/server/client-dev-server.js +60 -0
  264. package/src/server/client-formatted.js +58 -0
  265. package/src/server/client-icons.js +151 -0
  266. package/src/server/conf.js +929 -0
  267. package/src/server/crypto.js +91 -0
  268. package/src/server/dns.js +118 -0
  269. package/src/server/downloader.js +42 -0
  270. package/src/server/logger.js +190 -0
  271. package/src/server/network.js +209 -0
  272. package/src/server/peer.js +33 -0
  273. package/src/server/process.js +66 -0
  274. package/src/server/prompt-optimizer.js +28 -0
  275. package/src/server/proxy.js +118 -0
  276. package/src/server/runtime.js +463 -0
  277. package/src/server/ssl.js +120 -0
  278. package/src/server.js +25 -0
  279. package/src/ws/IoInterface.js +45 -0
  280. package/src/ws/IoServer.js +39 -0
  281. package/src/ws/core/channels/core.ws.chat.js +23 -0
  282. package/src/ws/core/channels/core.ws.mailer.js +35 -0
  283. package/src/ws/core/channels/core.ws.stream.js +31 -0
  284. package/src/ws/core/core.ws.connection.js +28 -0
  285. package/src/ws/core/core.ws.emit.js +14 -0
  286. package/src/ws/core/core.ws.server.js +24 -0
  287. package/src/ws/core/management/core.ws.chat.js +8 -0
  288. package/src/ws/core/management/core.ws.mailer.js +16 -0
  289. package/src/ws/core/management/core.ws.stream.js +8 -0
  290. package/src/ws/default/channels/default.ws.main.js +16 -0
  291. package/src/ws/default/default.ws.connection.js +22 -0
  292. package/src/ws/default/default.ws.emit.js +14 -0
  293. package/src/ws/default/default.ws.server.js +20 -0
  294. package/src/ws/default/management/default.ws.main.js +8 -0
  295. package/startup.js +11 -0
  296. package/supervisord-openssh-server.conf +5 -0
  297. package/test/api.test.js +60 -0
@@ -0,0 +1,754 @@
1
+ 'use strict';
2
+
3
+ import fs from 'fs-extra';
4
+ import { srcFormatted, componentFormatted, viewFormatted, ssrFactory } from './client-formatted.js';
5
+ import { loggerFactory } from './logger.js';
6
+ import { cap, newInstance, orderArrayFromAttrInt, titleFormatted } from '../client/components/core/CommonJs.js';
7
+ import UglifyJS from 'uglify-js';
8
+ import { minify } from 'html-minifier-terser';
9
+ import dotenv from 'dotenv';
10
+ import AdmZip from 'adm-zip';
11
+ import * as dir from 'path';
12
+ import { shellExec } from './process.js';
13
+ import swaggerAutoGen from 'swagger-autogen';
14
+ import { SitemapStream, streamToPromise } from 'sitemap';
15
+ import { Readable } from 'stream';
16
+ import { buildIcons, buildTextImg, getBufferPngText } from './client-icons.js';
17
+
18
+ dotenv.config();
19
+
20
+ // Static Site Generation (SSG)
21
+
22
+ const buildAcmeChallengePath = (acmeChallengeFullPath = '') => {
23
+ fs.mkdirSync(acmeChallengeFullPath, {
24
+ recursive: true,
25
+ });
26
+ fs.writeFileSync(`${acmeChallengeFullPath}/.gitkeep`, '', 'utf8');
27
+ };
28
+
29
+ const fullBuild = async ({
30
+ path,
31
+ logger,
32
+ client,
33
+ db,
34
+ dists,
35
+ rootClientPath,
36
+ acmeChallengeFullPath,
37
+ publicClientId,
38
+ iconsBuild,
39
+ metadata,
40
+ }) => {
41
+ logger.warn('Full build', rootClientPath);
42
+
43
+ fs.removeSync(rootClientPath);
44
+
45
+ buildAcmeChallengePath(acmeChallengeFullPath);
46
+
47
+ if (fs.existsSync(`./src/client/public/${publicClientId}`)) {
48
+ if (iconsBuild) {
49
+ const defaultBaseIconFolderPath = `src/client/public/${publicClientId}/assets/logo`;
50
+ if (!fs.existsSync(defaultBaseIconFolderPath)) fs.mkdirSync(defaultBaseIconFolderPath, { recursive: true });
51
+ const defaultBaseIconPath = `${defaultBaseIconFolderPath}/base-icon.png`;
52
+ if (!fs.existsSync(defaultBaseIconPath))
53
+ await buildTextImg(metadata.title, { debugFilename: defaultBaseIconPath });
54
+
55
+ if (!fs.existsSync(`./src/client/public/${publicClientId}/site.webmanifest`))
56
+ await buildIcons({ publicClientId, metadata });
57
+ }
58
+ fs.copySync(
59
+ `./src/client/public/${publicClientId}`,
60
+ rootClientPath /* {
61
+ filter: function (name) {
62
+ console.log(name);
63
+ return true;
64
+ },
65
+ } */,
66
+ );
67
+ } else if (fs.existsSync(`./engine-private/src/client/public/${publicClientId}`)) {
68
+ switch (publicClientId) {
69
+ case 'mysql_test':
70
+ if (db) {
71
+ fs.copySync(`./engine-private/src/client/public/${publicClientId}`, rootClientPath);
72
+ fs.writeFileSync(
73
+ `${rootClientPath}/index.php`,
74
+ fs
75
+ .readFileSync(`${rootClientPath}/index.php`, 'utf8')
76
+ .replace('test_servername', 'localhost')
77
+ .replace('test_username', db.user)
78
+ .replace('test_password', db.password)
79
+ .replace('test_dbname', db.name),
80
+ 'utf8',
81
+ );
82
+ } else logger.error('not provided db config');
83
+ break;
84
+
85
+ default:
86
+ break;
87
+ }
88
+ }
89
+ if (dists)
90
+ for (const dist of dists) {
91
+ if ('folder' in dist) {
92
+ fs.mkdirSync(`${rootClientPath}${dist.public_folder}`, { recursive: true });
93
+ fs.copySync(dist.folder, `${rootClientPath}${dist.public_folder}`);
94
+ }
95
+ if ('styles' in dist) {
96
+ fs.mkdirSync(`${rootClientPath}${dist.public_styles_folder}`, { recursive: true });
97
+ fs.copySync(dist.styles, `${rootClientPath}${dist.public_styles_folder}`);
98
+ }
99
+ }
100
+ };
101
+
102
+ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }) => {
103
+ const logger = loggerFactory(import.meta);
104
+ const confClient = JSON.parse(fs.readFileSync(`./conf/conf.client.json`, 'utf8'));
105
+ const confServer = JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'));
106
+ const confSSR = JSON.parse(fs.readFileSync(`./conf/conf.ssr.json`, 'utf8'));
107
+ const packageData = JSON.parse(fs.readFileSync(`./package.json`, 'utf8'));
108
+ const acmeChallengePath = `/.well-known/acme-challenge`;
109
+ const publicPath = `./public`;
110
+
111
+ // { srcBuildPath, publicBuildPath }
112
+ const enableLiveRebuild =
113
+ options && options.liveClientBuildPaths && options.liveClientBuildPaths.length > 0 ? true : false;
114
+
115
+ // common ssr components
116
+ let jsSsrCommonComponents = '';
117
+ {
118
+ const files = await fs.readdir(`./src/client/ssr/common`);
119
+ for (const relativePath of files)
120
+ jsSsrCommonComponents += await srcFormatted(
121
+ fs.readFileSync(`./src/client/ssr/common/${relativePath}`, 'utf8').split('export')[0],
122
+ );
123
+ }
124
+
125
+ let currentPort = parseInt(process.env.PORT) + 1;
126
+ for (const host of Object.keys(confServer)) {
127
+ const paths = orderArrayFromAttrInt(Object.keys(confServer[host]), 'length', 'asc');
128
+ for (const path of paths) {
129
+ if (
130
+ options &&
131
+ options.instances &&
132
+ options.instances.length > 0 &&
133
+ !options.instances.find((i) => i.path === path && i.host === host)
134
+ )
135
+ continue;
136
+ const {
137
+ runtime,
138
+ client,
139
+ directory,
140
+ disabledRebuild,
141
+ minifyBuild,
142
+ db,
143
+ redirect,
144
+ apis,
145
+ iconsBuild,
146
+ docsBuild,
147
+ apiBaseProxyPath,
148
+ apiBaseHost,
149
+ ttiLoadTimeLimit,
150
+ singleReplica,
151
+ } = confServer[host][path];
152
+ if (singleReplica) continue;
153
+ if (!confClient[client]) confClient[client] = {};
154
+ const { components, dists, views, services, metadata, publicRef } = confClient[client];
155
+ let backgroundImage;
156
+ if (metadata) {
157
+ backgroundImage = metadata.backgroundImage;
158
+ if (metadata.thumbnail) metadata.thumbnail = `${path === '/' ? path : `${path}/`}${metadata.thumbnail}`;
159
+ }
160
+ const rootClientPath = directory ? directory : `${publicPath}/${host}${path}`;
161
+ const port = newInstance(currentPort);
162
+ const publicClientId = publicRef ? publicRef : client;
163
+ const fullBuildEnabled = !process.argv.includes('l') && !confServer[host][path].liteBuild && !enableLiveRebuild;
164
+ // const baseHost = process.env.NODE_ENV === 'production' ? `https://${host}` : `http://localhost:${port}`;
165
+ const baseHost = process.env.NODE_ENV === 'production' ? `https://${host}` : ``;
166
+ // ''; // process.env.NODE_ENV === 'production' ? `https://${host}` : ``;
167
+ currentPort++;
168
+
169
+ const acmeChallengeFullPath = directory
170
+ ? `${directory}${acmeChallengePath}`
171
+ : `${publicPath}/${host}${acmeChallengePath}`;
172
+
173
+ if (!enableLiveRebuild) buildAcmeChallengePath(acmeChallengeFullPath);
174
+
175
+ if (redirect || disabledRebuild) continue;
176
+
177
+ if (fullBuildEnabled) {
178
+ // !(confServer[host]['/'] && confServer[host]['/'].liteBuild)
179
+ await fullBuild({
180
+ path,
181
+ logger,
182
+ client,
183
+ db,
184
+ dists,
185
+ rootClientPath,
186
+ acmeChallengeFullPath,
187
+ publicClientId,
188
+ iconsBuild,
189
+ metadata,
190
+ });
191
+ if (apis && false)
192
+ for (const apiBuildScript of apis) {
193
+ const scriptPath = `src/api/${apiBuildScript}/${apiBuildScript}.build.js`;
194
+ if (fs.existsSync(`./${scriptPath}`)) {
195
+ shellExec(`node ${scriptPath}`);
196
+ }
197
+ }
198
+ }
199
+
200
+ if (components)
201
+ for (const module of Object.keys(components)) {
202
+ if (!fs.existsSync(`${rootClientPath}/components/${module}`))
203
+ fs.mkdirSync(`${rootClientPath}/components/${module}`, { recursive: true });
204
+
205
+ for (const component of components[module]) {
206
+ const jsSrcPath = `./src/client/components/${module}/${component}.js`;
207
+ const jsPublicPath = `${rootClientPath}/components/${module}/${component}.js`;
208
+
209
+ if (enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath)) continue;
210
+
211
+ const jsSrc = componentFormatted(
212
+ await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')),
213
+ module,
214
+ dists,
215
+ path,
216
+ 'components',
217
+ baseHost,
218
+ );
219
+ fs.writeFileSync(
220
+ jsPublicPath,
221
+ minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
222
+ 'utf8',
223
+ );
224
+ }
225
+ }
226
+
227
+ if (services) {
228
+ for (const module of services) {
229
+ if (!fs.existsSync(`${rootClientPath}/services/${module}`))
230
+ fs.mkdirSync(`${rootClientPath}/services/${module}`, { recursive: true });
231
+
232
+ if (fs.existsSync(`./src/client/services/${module}/${module}.service.js`)) {
233
+ const jsSrcPath = `./src/client/services/${module}/${module}.service.js`;
234
+ const jsPublicPath = `${rootClientPath}/services/${module}/${module}.service.js`;
235
+ if (enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath)) continue;
236
+
237
+ let jsSrc = componentFormatted(
238
+ await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')),
239
+ module,
240
+ dists,
241
+ path,
242
+ 'services',
243
+ baseHost,
244
+ );
245
+ if (module === 'core' && (process.env.NODE_ENV === 'production' || process.argv.includes('static'))) {
246
+ if (apiBaseHost)
247
+ jsSrc = jsSrc.replace(
248
+ 'const getBaseHost = () => location.host;',
249
+ `const getBaseHost = () => '${apiBaseHost}';`,
250
+ );
251
+ if (apiBaseProxyPath) {
252
+ jsSrc = jsSrc.replace('${getProxyPath()}api/', `${apiBaseProxyPath}${process.env.BASE_API}/`);
253
+ jsSrc = jsSrc.replace(
254
+ "const getWsBasePath = () => (getProxyPath() !== '/' ? `${getProxyPath()}socket.io/` : undefined);",
255
+ `const getWsBasePath = () => '${apiBaseProxyPath}socket.io/';`,
256
+ );
257
+ }
258
+ }
259
+ fs.writeFileSync(
260
+ jsPublicPath,
261
+ minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
262
+ 'utf8',
263
+ );
264
+ }
265
+ }
266
+
267
+ for (const module of services) {
268
+ if (fs.existsSync(`./src/client/services/${module}/${module}.management.js`)) {
269
+ const jsSrcPath = `./src/client/services/${module}/${module}.management.js`;
270
+ const jsPublicPath = `${rootClientPath}/services/${module}/${module}.management.js`;
271
+ if (enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath)) continue;
272
+
273
+ const jsSrc = componentFormatted(
274
+ await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')),
275
+ module,
276
+ dists,
277
+ path,
278
+ 'services',
279
+ baseHost,
280
+ );
281
+ fs.writeFileSync(
282
+ jsPublicPath,
283
+ minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
284
+ 'utf8',
285
+ );
286
+ }
287
+ }
288
+ }
289
+
290
+ const buildId = `${client}.index`;
291
+ const siteMapLinks = [];
292
+ let Render = () => '';
293
+ eval(await srcFormatted(fs.readFileSync(`./src/client/ssr/Render.js`, 'utf8')));
294
+
295
+ if (views) {
296
+ const buildJsSrcPage = async (jsSrcPath, jsPublicPath, filter) => {
297
+ if (!(enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath))) {
298
+ let jsSrc = viewFormatted(await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')), dists, path, baseHost);
299
+ if (jsSrc.split('/*imports*/')[1]) jsSrc = jsSrc.split('/*imports*/')[1];
300
+ if (filter) jsSrc = await filter(jsSrc);
301
+ fs.writeFileSync(
302
+ jsPublicPath,
303
+ minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
304
+ 'utf8',
305
+ );
306
+ }
307
+ };
308
+
309
+ // service woker
310
+ await buildJsSrcPage(
311
+ fs.existsSync(`./src/client/sw/${publicClientId}.sw.js`)
312
+ ? `./src/client/sw/${publicClientId}.sw.js`
313
+ : `./src/client/sw/default.sw.js`,
314
+ `${rootClientPath}/sw.js`,
315
+ path !== '/'
316
+ ? (jsSrc) => jsSrc.replaceAll(`const PROXY_PATH = '/';`, `const PROXY_PATH = '${path}/';`)
317
+ : undefined,
318
+ );
319
+
320
+ // ssr pages
321
+ for (const page of await fs.readdir('./src/client/ssr/pages')) {
322
+ await buildJsSrcPage(`./src/client/ssr/pages/${page}`, `${rootClientPath}/${page}`);
323
+
324
+ const htmlSrc = Render({
325
+ title: metadata?.title ? metadata.title : cap(client),
326
+ ssrPath: '/',
327
+ ssrHeadComponents: '',
328
+ ssrBodyComponents: '',
329
+ baseSsrLib: jsSsrCommonComponents + fs.readFileSync(`${rootClientPath}/${page}`, 'utf8'),
330
+ });
331
+
332
+ fs.writeFileSync(
333
+ `${rootClientPath}/${page.slice(0, -3)}.html`,
334
+ minifyBuild || process.env.NODE_ENV === 'production'
335
+ ? await minify(htmlSrc, {
336
+ minifyCSS: true,
337
+ minifyJS: true,
338
+ collapseBooleanAttributes: true,
339
+ collapseInlineTagWhitespace: true,
340
+ collapseWhitespace: true,
341
+ })
342
+ : htmlSrc,
343
+ 'utf8',
344
+ );
345
+ }
346
+
347
+ if (
348
+ !(
349
+ enableLiveRebuild &&
350
+ !options.liveClientBuildPaths.find(
351
+ (p) => p.srcBuildPath.startsWith(`./src/client/ssr`) || p.srcBuildPath.slice(-9) === '.index.js',
352
+ )
353
+ )
354
+ )
355
+ for (const view of views) {
356
+ const buildPath = `${
357
+ rootClientPath[rootClientPath.length - 1] === '/' ? rootClientPath.slice(0, -1) : rootClientPath
358
+ }${view.path === '/' ? view.path : `${view.path}/`}`;
359
+
360
+ if (!fs.existsSync(buildPath)) fs.mkdirSync(buildPath, { recursive: true });
361
+
362
+ logger.info('View build', buildPath);
363
+
364
+ const jsSrc = viewFormatted(
365
+ await srcFormatted(fs.readFileSync(`./src/client/${view.client}.index.js`, 'utf8')),
366
+ dists,
367
+ path,
368
+ baseHost,
369
+ );
370
+
371
+ fs.writeFileSync(
372
+ `${buildPath}${buildId}.js`,
373
+ minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
374
+ 'utf8',
375
+ );
376
+
377
+ // const title = `${metadata && metadata.title ? metadata.title : cap(client)}${
378
+ // view.title ? ` | ${view.title}` : view.path !== '/' ? ` | ${titleFormatted(view.path)}` : ''
379
+ // }`;
380
+
381
+ const title = `${
382
+ view.title ? `${view.title} | ` : view.path !== '/' ? `${titleFormatted(view.path)} | ` : ''
383
+ }${metadata && metadata.title ? metadata.title : cap(client)}`;
384
+
385
+ const canonicalURL = `https://${host}${path}${
386
+ view.path === '/' ? (path === '/' ? '' : '/') : path === '/' ? `${view.path.slice(1)}/` : `${view.path}/`
387
+ }`;
388
+ const ssrPath = path === '/' ? path : `${path}/`;
389
+
390
+ let ssrHeadComponents = ``;
391
+ let ssrBodyComponents = ``;
392
+ if ('ssr' in view) {
393
+ // https://metatags.io/
394
+ if (process.env.NODE_ENV === 'production' && !confSSR[view.ssr].head.includes('Production'))
395
+ confSSR[view.ssr].head.unshift('Production');
396
+
397
+ for (const ssrHeadComponent of confSSR[view.ssr].head) {
398
+ const SrrComponent = await ssrFactory(
399
+ `./src/client/ssr/components/head/${ssrHeadComponent}.js`,
400
+ jsSsrCommonComponents,
401
+ );
402
+
403
+ switch (ssrHeadComponent) {
404
+ case 'Pwa':
405
+ const validPwaBuild =
406
+ metadata &&
407
+ fs.existsSync(`./src/client/public/${publicClientId}/browserconfig.xml`) &&
408
+ fs.existsSync(`./src/client/public/${publicClientId}/site.webmanifest`);
409
+
410
+ if (validPwaBuild) {
411
+ // build webmanifest
412
+ const webmanifestJson = JSON.parse(
413
+ fs.readFileSync(`./src/client/public/${publicClientId}/site.webmanifest`, 'utf8'),
414
+ );
415
+ if (metadata.title) {
416
+ webmanifestJson.name = metadata.title;
417
+ webmanifestJson.short_name = metadata.title;
418
+ }
419
+ if (metadata.description) {
420
+ webmanifestJson.description = metadata.description;
421
+ }
422
+ if (metadata.themeColor) {
423
+ webmanifestJson.theme_color = metadata.themeColor;
424
+ webmanifestJson.background_color = metadata.themeColor;
425
+ }
426
+ fs.writeFileSync(
427
+ `${buildPath}site.webmanifest`,
428
+ JSON.stringify(webmanifestJson, null, 4).replaceAll(`: "/`, `: "${ssrPath}`),
429
+ 'utf8',
430
+ );
431
+ // build browserconfig
432
+ fs.writeFileSync(
433
+ `${buildPath}browserconfig.xml`,
434
+ fs
435
+ .readFileSync(`./src/client/public/${publicClientId}/browserconfig.xml`, 'utf8')
436
+ .replaceAll(
437
+ `<TileColor></TileColor>`,
438
+ metadata.themeColor
439
+ ? `<TileColor>${metadata.themeColor}</TileColor>`
440
+ : `<TileColor>#e0e0e0</TileColor>`,
441
+ )
442
+ .replaceAll(`src="/`, `src="${ssrPath}`),
443
+ 'utf8',
444
+ );
445
+
446
+ // Android play store example:
447
+ //
448
+ // "related_applications": [
449
+ // {
450
+ // "platform": "play",
451
+ // "url": "https://play.google.com/store/apps/details?id=cheeaun.hackerweb"
452
+ // }
453
+ // ],
454
+ // "prefer_related_applications": true
455
+ }
456
+ if (validPwaBuild) ssrHeadComponents += SrrComponent({ title, ssrPath, canonicalURL, ...metadata });
457
+ break;
458
+ case 'Seo':
459
+ if (metadata) {
460
+ ssrHeadComponents += SrrComponent({ title, ssrPath, canonicalURL, ...metadata });
461
+ }
462
+ break;
463
+ case 'Microdata':
464
+ if (
465
+ fs.existsSync(`./src/client/public/${publicClientId}/microdata.json`) // &&
466
+ // path === '/' &&
467
+ // view.path === '/'
468
+ ) {
469
+ const microdata = JSON.parse(
470
+ fs.readFileSync(`./src/client/public/${publicClientId}/microdata.json`, 'utf8'),
471
+ );
472
+ ssrHeadComponents += SrrComponent({ microdata });
473
+ }
474
+ break;
475
+ default:
476
+ ssrHeadComponents += SrrComponent({ ssrPath, host, path });
477
+ break;
478
+ }
479
+ }
480
+
481
+ for (const ssrBodyComponent of confSSR[view.ssr].body) {
482
+ const SrrComponent = await ssrFactory(
483
+ `./src/client/ssr/components/body/${ssrBodyComponent}.js`,
484
+ jsSsrCommonComponents,
485
+ );
486
+ switch (ssrBodyComponent) {
487
+ case 'UnderpostDefaultSplashScreen':
488
+ case 'CyberiaDefaultSplashScreen':
489
+ case 'NexodevSplashScreen':
490
+ case 'DefaultSplashScreen':
491
+ if (backgroundImage) {
492
+ ssrHeadComponents += SrrComponent({
493
+ base64BackgroundImage: `data:image/${backgroundImage.split('.').pop()};base64,${fs
494
+ .readFileSync(backgroundImage)
495
+ .toString('base64')}`,
496
+ });
497
+ break;
498
+ } else {
499
+ ssrHeadComponents += SrrComponent({ metadata });
500
+ break;
501
+ const bufferBackgroundImage = await getBufferPngText({
502
+ text: ' ',
503
+ textColor: metadata?.themeColor ? metadata.themeColor : '#ececec',
504
+ size: '100x100',
505
+ bgColor: metadata?.themeColor ? metadata.themeColor : '#ececec',
506
+ });
507
+ ssrHeadComponents += SrrComponent({
508
+ base64BackgroundImage: `data:image/png;base64,${bufferBackgroundImage.toString('base64')}`,
509
+ });
510
+ }
511
+
512
+ case 'CyberiaSplashScreenLore': {
513
+ ssrBodyComponents += SrrComponent({
514
+ ssrPath,
515
+ host,
516
+ path,
517
+ ttiLoadTimeLimit,
518
+ });
519
+ break;
520
+ }
521
+
522
+ default:
523
+ ssrBodyComponents += SrrComponent({ ssrPath, host, path, ttiLoadTimeLimit });
524
+ break;
525
+ }
526
+ }
527
+ }
528
+ const htmlSrc = Render({
529
+ title,
530
+ buildId,
531
+ ssrPath,
532
+ ssrHeadComponents,
533
+ ssrBodyComponents,
534
+ baseSsrLib: jsSsrCommonComponents,
535
+ });
536
+
537
+ /** @type {import('sitemap').SitemapItem} */
538
+ const siteMapLink = {
539
+ url: `${path === '/' ? '' : path}${view.path}`,
540
+ changefreq: 'daily',
541
+ priority: 0.8,
542
+ };
543
+ siteMapLinks.push(siteMapLink);
544
+
545
+ fs.writeFileSync(
546
+ `${buildPath}index.html`,
547
+ minifyBuild || process.env.NODE_ENV === 'production'
548
+ ? await minify(htmlSrc, {
549
+ minifyCSS: true,
550
+ minifyJS: true,
551
+ collapseBooleanAttributes: true,
552
+ collapseInlineTagWhitespace: true,
553
+ collapseWhitespace: true,
554
+ })
555
+ : htmlSrc,
556
+ 'utf8',
557
+ );
558
+ }
559
+ }
560
+ if (!enableLiveRebuild && siteMapLinks.length > 0) {
561
+ const xslUrl = fs.existsSync(`${rootClientPath}/sitemap`)
562
+ ? `${path === '/' ? '' : path}/sitemap.xsl`
563
+ : undefined;
564
+ // Create a stream to write to
565
+ /** @type {import('sitemap').SitemapStreamOptions} */
566
+ const sitemapOptions = { hostname: `https://${host}`, xslUrl };
567
+
568
+ const siteMapStream = new SitemapStream(sitemapOptions);
569
+ let siteMapSrc = await new Promise((resolve) =>
570
+ streamToPromise(Readable.from(siteMapLinks).pipe(siteMapStream)).then((data) => resolve(data.toString())),
571
+ );
572
+ switch (publicClientId) {
573
+ case 'underpost':
574
+ siteMapSrc = siteMapSrc.replaceAll(
575
+ `</urlset>`,
576
+ `${fs.readFileSync(`./src/client/public/underpost/sitemap-template.txt`, 'utf8')} </urlset>`,
577
+ );
578
+ break;
579
+
580
+ default:
581
+ break;
582
+ }
583
+ // Return a promise that resolves with your XML string
584
+ fs.writeFileSync(`${rootClientPath}/sitemap.xml`, siteMapSrc, 'utf8');
585
+ if (xslUrl)
586
+ fs.writeFileSync(
587
+ `${rootClientPath}/sitemap.xsl`,
588
+ fs.readFileSync(`${rootClientPath}/sitemap`, 'utf8').replaceAll('{{web-url}}', `https://${host}${path}`),
589
+ 'utf8',
590
+ );
591
+
592
+ fs.writeFileSync(
593
+ `${rootClientPath}/robots.txt`,
594
+ `User-agent: *
595
+ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
596
+ 'utf8',
597
+ );
598
+ }
599
+
600
+ if (!enableLiveRebuild && !process.argv.includes('l') && !process.argv.includes('deploy') && docsBuild) {
601
+ // https://www.pullrequest.com/blog/leveraging-jsdoc-for-better-code-documentation-in-javascript/
602
+ // https://jsdoc.app/about-configuring-jsdoc
603
+ // https://jsdoc.app/ Block tags
604
+
605
+ const jsDocsConfig = JSON.parse(fs.readFileSync(`./jsdoc.json`, 'utf8'));
606
+ jsDocsConfig.opts.destination = `./public/${host}${path === '/' ? path : `${path}/`}docs/`;
607
+ jsDocsConfig.opts.theme_opts.title = metadata && metadata.title ? metadata.title : undefined;
608
+ jsDocsConfig.opts.theme_opts.favicon = `./public/${host}${path === '/' ? path : `${path}/favicon.ico`}`;
609
+ fs.writeFileSync(`./jsdoc.json`, JSON.stringify(jsDocsConfig, null, 4), 'utf8');
610
+ logger.warn('build jsdoc view', jsDocsConfig.opts.destination);
611
+ shellExec(`npm run docs`, { silent: true });
612
+
613
+ // coverage
614
+ if (!fs.existsSync(`./coverage`)) {
615
+ shellExec(`npm test`);
616
+ }
617
+ const coverageBuildPath = `${jsDocsConfig.opts.destination}/coverage`;
618
+ fs.mkdirSync(coverageBuildPath, { recursive: true });
619
+ fs.copySync(`./coverage`, coverageBuildPath);
620
+
621
+ // uml
622
+ // shellExec(`node bin/deploy uml ${host} ${path}`);
623
+
624
+ // https://swagger-autogen.github.io/docs/
625
+
626
+ const basePath = path === '/' ? `${process.env.BASE_API}` : `/${process.env.BASE_API}`;
627
+
628
+ const doc = {
629
+ info: {
630
+ version: packageData.version, // by default: '1.0.0'
631
+ title: metadata?.title ? `${metadata.title}` : 'REST API', // by default: 'REST API'
632
+ description: metadata?.description ? metadata.description : '', // by default: ''
633
+ },
634
+ servers: [
635
+ {
636
+ url:
637
+ process.env.NODE_ENV === 'development'
638
+ ? `http://localhost:${port}${path}${basePath}`
639
+ : `https://${host}${path}${basePath}`, // by default: 'http://localhost:3000'
640
+ description: `${process.env.NODE_ENV} server`, // by default: ''
641
+ },
642
+ ],
643
+ tags: [
644
+ // by default: empty Array
645
+ {
646
+ name: 'user', // Tag name
647
+ description: 'User API operations', // Tag description
648
+ },
649
+ ],
650
+ components: {
651
+ schemas: {
652
+ userRequest: {
653
+ username: 'user123',
654
+ password: 'Password123',
655
+ email: 'user@example.com',
656
+ },
657
+ userResponse: {
658
+ status: 'success',
659
+ data: {
660
+ token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Il9pZCI6IjY2YzM3N2Y1N2Y5OWU1OTY5YjgxZG...',
661
+ user: {
662
+ _id: '66c377f57f99e5969b81de89',
663
+ email: 'user@example.com',
664
+ emailConfirmed: false,
665
+ username: 'user123',
666
+ role: 'user',
667
+ profileImageId: '66c377f57f99e5969b81de87',
668
+ },
669
+ },
670
+ },
671
+ userUpdateResponse: {
672
+ status: 'success',
673
+ data: {
674
+ _id: '66c377f57f99e5969b81de89',
675
+ email: 'user@example.com',
676
+ emailConfirmed: false,
677
+ username: 'user123222',
678
+ role: 'user',
679
+ profileImageId: '66c377f57f99e5969b81de87',
680
+ },
681
+ },
682
+ userGetResponse: {
683
+ status: 'success',
684
+ data: {
685
+ _id: '66c377f57f99e5969b81de89',
686
+ email: 'user@example.com',
687
+ emailConfirmed: false,
688
+ username: 'user123222',
689
+ role: 'user',
690
+ profileImageId: '66c377f57f99e5969b81de87',
691
+ },
692
+ },
693
+ userLogInRequest: {
694
+ email: 'user@example.com',
695
+ password: 'Password123',
696
+ },
697
+ userBadRequestResponse: {
698
+ status: 'error',
699
+ message: 'Bad request. Please check your inputs, and try again',
700
+ },
701
+ },
702
+ securitySchemes: {
703
+ bearerAuth: {
704
+ type: 'http',
705
+ scheme: 'bearer',
706
+ },
707
+ },
708
+ },
709
+ };
710
+
711
+ // plantuml
712
+ logger.info('copy plantuml', `${rootClientPath}/docs/plantuml`);
713
+ fs.copySync(`./src/client/public/default/plantuml`, `${rootClientPath}/docs/plantuml`);
714
+
715
+ logger.warn('build swagger api docs', doc.info);
716
+
717
+ const outputFile = `./public/${host}${path === '/' ? path : `${path}/`}swagger-output.json`;
718
+ const routes = [];
719
+ for (const api of apis) {
720
+ if (['user'].includes(api)) routes.push(`./src/api/${api}/${api}.router.js`);
721
+ }
722
+
723
+ /* NOTE: If you are using the express Router, you must pass in the 'routes' only the
724
+ root file where the route starts, such as index.js, app.js, routes.js, etc ... */
725
+
726
+ await swaggerAutoGen({ openapi: '3.0.0' })(outputFile, routes, doc);
727
+ }
728
+ if (!enableLiveRebuild && process.argv.includes('zip')) {
729
+ logger.warn('build zip', rootClientPath);
730
+
731
+ if (!fs.existsSync('./build')) fs.mkdirSync('./build');
732
+
733
+ const zip = new AdmZip();
734
+ const files = await fs.readdir(rootClientPath, { recursive: true });
735
+
736
+ for (const relativePath of files) {
737
+ const filePath = dir.resolve(`${rootClientPath}/${relativePath}`);
738
+ if (!fs.lstatSync(filePath).isDirectory()) {
739
+ const folder = dir.relative(`public/${host}${path}`, dir.dirname(filePath));
740
+ zip.addLocalFile(filePath, folder);
741
+ }
742
+ }
743
+
744
+ const buildId = `${host}-${path.replaceAll('/', '')}`;
745
+
746
+ logger.warn('write zip', `./build/${buildId}.zip`);
747
+
748
+ zip.writeZip(`./build/${buildId}.zip`);
749
+ }
750
+ }
751
+ }
752
+ };
753
+
754
+ export { buildClient };