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