@underpostnet/underpost 2.7.82

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