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.
- package/.dockerignore +14 -0
- package/.env.development +8 -0
- package/.env.production +8 -0
- package/.env.test +8 -0
- package/.nycrc +9 -0
- package/.prettierignore +13 -0
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +72 -0
- package/.vscode/settings.json +99 -0
- package/Dockerfile +88 -0
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/bin/db.js +119 -0
- package/bin/deploy.js +600 -0
- package/bin/dns.js +1 -0
- package/bin/file.js +92 -0
- package/bin/help.js +110 -0
- package/bin/index.js +29 -0
- package/bin/install.js +357 -0
- package/bin/shortcut.js +44 -0
- package/bin/ssl.js +61 -0
- package/bin/util.js +182 -0
- package/bin/vs.js +35 -0
- package/conf.js +244 -0
- package/docker-compose.yml +67 -0
- package/jsconfig.json +7 -0
- package/jsdoc.json +32 -0
- package/nodemon.json +6 -0
- package/package.json +128 -0
- package/prometheus.yml +36 -0
- package/setup.sh +25 -0
- package/src/api/core/core.controller.js +69 -0
- package/src/api/core/core.model.js +11 -0
- package/src/api/core/core.router.js +23 -0
- package/src/api/core/core.service.js +29 -0
- package/src/api/crypto/crypto.controller.js +51 -0
- package/src/api/crypto/crypto.model.js +23 -0
- package/src/api/crypto/crypto.router.js +20 -0
- package/src/api/crypto/crypto.service.js +64 -0
- package/src/api/default/default.controller.js +69 -0
- package/src/api/default/default.model.js +20 -0
- package/src/api/default/default.router.js +23 -0
- package/src/api/default/default.service.js +31 -0
- package/src/api/file/file.controller.js +51 -0
- package/src/api/file/file.model.js +19 -0
- package/src/api/file/file.router.js +20 -0
- package/src/api/file/file.service.js +70 -0
- package/src/api/instance/instance.controller.js +69 -0
- package/src/api/instance/instance.model.js +36 -0
- package/src/api/instance/instance.router.js +33 -0
- package/src/api/instance/instance.service.js +48 -0
- package/src/api/test/test.controller.js +59 -0
- package/src/api/test/test.model.js +14 -0
- package/src/api/test/test.router.js +21 -0
- package/src/api/test/test.service.js +35 -0
- package/src/api/user/user.controller.js +70 -0
- package/src/api/user/user.model.js +65 -0
- package/src/api/user/user.router.js +345 -0
- package/src/api/user/user.service.js +479 -0
- package/src/api.js +23 -0
- package/src/client/Default.index.js +40 -0
- package/src/client/components/core/Account.js +290 -0
- package/src/client/components/core/AgGrid.js +160 -0
- package/src/client/components/core/Auth.js +19 -0
- package/src/client/components/core/Badge.js +32 -0
- package/src/client/components/core/BlockChain.js +41 -0
- package/src/client/components/core/Blog.js +9 -0
- package/src/client/components/core/BtnIcon.js +91 -0
- package/src/client/components/core/CalendarCore.js +319 -0
- package/src/client/components/core/Chat.js +64 -0
- package/src/client/components/core/ColorPalette.js +5267 -0
- package/src/client/components/core/CommonJs.js +708 -0
- package/src/client/components/core/Content.js +49 -0
- package/src/client/components/core/Css.js +1027 -0
- package/src/client/components/core/CssCore.js +792 -0
- package/src/client/components/core/D3Chart.js +44 -0
- package/src/client/components/core/Docs.js +130 -0
- package/src/client/components/core/DropDown.js +164 -0
- package/src/client/components/core/EventsUI.js +54 -0
- package/src/client/components/core/FileExplorer.js +624 -0
- package/src/client/components/core/FullScreen.js +45 -0
- package/src/client/components/core/Input.js +259 -0
- package/src/client/components/core/JoyStick.js +77 -0
- package/src/client/components/core/Keyboard.js +73 -0
- package/src/client/components/core/LoadingAnimation.js +157 -0
- package/src/client/components/core/LogIn.js +181 -0
- package/src/client/components/core/LogOut.js +52 -0
- package/src/client/components/core/Logger.js +26 -0
- package/src/client/components/core/Modal.js +1596 -0
- package/src/client/components/core/NotificationManager.js +84 -0
- package/src/client/components/core/Panel.js +413 -0
- package/src/client/components/core/Polyhedron.js +162 -0
- package/src/client/components/core/Recover.js +204 -0
- package/src/client/components/core/Responsive.js +53 -0
- package/src/client/components/core/RichText.js +27 -0
- package/src/client/components/core/Router.js +77 -0
- package/src/client/components/core/SignUp.js +125 -0
- package/src/client/components/core/SocketIo.js +72 -0
- package/src/client/components/core/Stream.js +113 -0
- package/src/client/components/core/ToggleSwitch.js +87 -0
- package/src/client/components/core/ToolTip.js +26 -0
- package/src/client/components/core/Translate.js +408 -0
- package/src/client/components/core/Validator.js +100 -0
- package/src/client/components/core/VanillaJs.js +454 -0
- package/src/client/components/core/Wallet.js +106 -0
- package/src/client/components/core/Webhook.js +25 -0
- package/src/client/components/core/Worker.js +272 -0
- package/src/client/components/default/CommonDefault.js +29 -0
- package/src/client/components/default/CssDefault.js +13 -0
- package/src/client/components/default/ElementsDefault.js +38 -0
- package/src/client/components/default/LogInDefault.js +41 -0
- package/src/client/components/default/LogOutDefault.js +28 -0
- package/src/client/components/default/MenuDefault.js +389 -0
- package/src/client/components/default/RoutesDefault.js +48 -0
- package/src/client/components/default/SettingsDefault.js +16 -0
- package/src/client/components/default/SignUpDefault.js +9 -0
- package/src/client/components/default/SocketIoDefault.js +54 -0
- package/src/client/components/default/TranslateDefault.js +7 -0
- package/src/client/public/default/android-chrome-144x144.png +0 -0
- package/src/client/public/default/android-chrome-192x192.png +0 -0
- package/src/client/public/default/android-chrome-256x256.png +0 -0
- package/src/client/public/default/android-chrome-36x36.png +0 -0
- package/src/client/public/default/android-chrome-384x384.png +0 -0
- package/src/client/public/default/android-chrome-48x48.png +0 -0
- package/src/client/public/default/android-chrome-512x512.png +0 -0
- package/src/client/public/default/android-chrome-72x72.png +0 -0
- package/src/client/public/default/android-chrome-96x96.png +0 -0
- package/src/client/public/default/apple-touch-icon-1024x1024.png +0 -0
- package/src/client/public/default/apple-touch-icon-114x114.png +0 -0
- package/src/client/public/default/apple-touch-icon-120x120.png +0 -0
- package/src/client/public/default/apple-touch-icon-144x144.png +0 -0
- package/src/client/public/default/apple-touch-icon-152x152.png +0 -0
- package/src/client/public/default/apple-touch-icon-167x167.png +0 -0
- package/src/client/public/default/apple-touch-icon-180x180.png +0 -0
- package/src/client/public/default/apple-touch-icon-57x57.png +0 -0
- package/src/client/public/default/apple-touch-icon-60x60.png +0 -0
- package/src/client/public/default/apple-touch-icon-72x72.png +0 -0
- package/src/client/public/default/apple-touch-icon-76x76.png +0 -0
- package/src/client/public/default/apple-touch-icon-precomposed.png +0 -0
- package/src/client/public/default/apple-touch-icon.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1125x2436.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1136x640.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1170x2532.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1179x2556.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1242x2208.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1242x2688.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1284x2778.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1290x2796.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1334x750.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1488x2266.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1536x2048.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1620x2160.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1640x2160.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1668x2224.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1668x2388.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1792x828.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2048x1536.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2048x2732.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2160x1620.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2160x1640.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2208x1242.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2224x1668.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2266x1488.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2388x1668.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2436x1125.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2532x1170.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2556x1179.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2688x1242.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2732x2048.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2778x1284.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2796x1290.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-640x1136.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-750x1334.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-828x1792.png +0 -0
- package/src/client/public/default/assets/background/white.jpg +0 -0
- package/src/client/public/default/assets/background/white0-min.jpg +0 -0
- package/src/client/public/default/assets/background/white0.jpg +0 -0
- package/src/client/public/default/assets/logo/base-icon.png +0 -0
- package/src/client/public/default/browserconfig.xml +12 -0
- package/src/client/public/default/favicon-16x16.png +0 -0
- package/src/client/public/default/favicon-32x32.png +0 -0
- package/src/client/public/default/favicon-48x48.png +0 -0
- package/src/client/public/default/favicon.ico +0 -0
- package/src/client/public/default/manifest.webmanifest +69 -0
- package/src/client/public/default/mstile-144x144.png +0 -0
- package/src/client/public/default/mstile-150x150.png +0 -0
- package/src/client/public/default/mstile-310x150.png +0 -0
- package/src/client/public/default/mstile-310x310.png +0 -0
- package/src/client/public/default/mstile-70x70.png +0 -0
- package/src/client/public/default/sitemap +148 -0
- package/src/client/public/default/yandex-browser-50x50.png +0 -0
- package/src/client/public/default/yandex-browser-manifest.json +9 -0
- package/src/client/public/doc/favicon.ico +0 -0
- package/src/client/public/doc/sitemap +148 -0
- package/src/client/public/test/favicon.ico +0 -0
- package/src/client/public/test/sitemap +148 -0
- package/src/client/services/core/core.service.js +152 -0
- package/src/client/services/crypto/crypto.service.js +70 -0
- package/src/client/services/default/default.management.js +345 -0
- package/src/client/services/default/default.service.js +89 -0
- package/src/client/services/file/file.service.js +70 -0
- package/src/client/services/instance/instance.management.js +74 -0
- package/src/client/services/instance/instance.service.js +89 -0
- package/src/client/services/test/test.service.js +70 -0
- package/src/client/services/user/user.management.js +50 -0
- package/src/client/services/user/user.service.js +89 -0
- package/src/client/ssr/Render.js +16 -0
- package/src/client/ssr/body-components/CacheControl.js +113 -0
- package/src/client/ssr/body-components/DefaultSplashScreen.js +79 -0
- package/src/client/ssr/email-components/DefaultRecoverEmail.js +21 -0
- package/src/client/ssr/email-components/DefaultVerifyEmail.js +17 -0
- package/src/client/ssr/head-components/Css.js +241 -0
- package/src/client/ssr/head-components/DefaultScripts.js +3 -0
- package/src/client/ssr/head-components/Microdata.js +11 -0
- package/src/client/ssr/head-components/Production.js +1 -0
- package/src/client/ssr/head-components/PwaDefault.js +60 -0
- package/src/client/ssr/head-components/Seo.js +14 -0
- package/src/client/sw/default.sw.js +201 -0
- package/src/client/sw/template.sw.js +84 -0
- package/src/client.build.js +22 -0
- package/src/client.dev.js +21 -0
- package/src/cron.js +25 -0
- package/src/db/DataBaseProvider.js +34 -0
- package/src/db/mariadb/MariaDB.js +33 -0
- package/src/db/mongo/MongooseDB.js +46 -0
- package/src/dns.js +22 -0
- package/src/mailer/EmailRender.js +69 -0
- package/src/mailer/MailerProvider.js +96 -0
- package/src/proxy.js +22 -0
- package/src/runtime/lampp/Lampp.js +44 -0
- package/src/runtime/nginx/Nginx.js +3 -0
- package/src/runtime/xampp/Xampp.js +49 -0
- package/src/server/auth.js +204 -0
- package/src/server/backup.js +83 -0
- package/src/server/client-build-live.js +72 -0
- package/src/server/client-build.js +688 -0
- package/src/server/client-dev-server.js +58 -0
- package/src/server/client-formatted.js +48 -0
- package/src/server/client-icons.js +150 -0
- package/src/server/conf.js +611 -0
- package/src/server/dns.js +87 -0
- package/src/server/downloader.js +42 -0
- package/src/server/logger.js +135 -0
- package/src/server/network.js +122 -0
- package/src/server/peer.js +33 -0
- package/src/server/process.js +66 -0
- package/src/server/proxy.js +118 -0
- package/src/server/runtime.js +393 -0
- package/src/server/ssl.js +107 -0
- package/src/server.js +25 -0
- package/src/ws/IoInterface.js +45 -0
- package/src/ws/IoServer.js +39 -0
- package/src/ws/core/channels/core.ws.chat.js +23 -0
- package/src/ws/core/channels/core.ws.mailer.js +35 -0
- package/src/ws/core/channels/core.ws.stream.js +31 -0
- package/src/ws/core/core.ws.connection.js +28 -0
- package/src/ws/core/core.ws.emit.js +14 -0
- package/src/ws/core/core.ws.server.js +24 -0
- package/src/ws/core/management/core.ws.chat.js +8 -0
- package/src/ws/core/management/core.ws.mailer.js +16 -0
- package/src/ws/core/management/core.ws.stream.js +8 -0
- package/src/ws/default/channels/default.ws.main.js +16 -0
- package/src/ws/default/default.ws.connection.js +22 -0
- package/src/ws/default/default.ws.emit.js +14 -0
- package/src/ws/default/default.ws.server.js +20 -0
- package/src/ws/default/management/default.ws.main.js +8 -0
- package/startup.js +11 -0
- package/supervisord-openssh-server.conf +5 -0
- package/test/api.test.js +60 -0
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
import { cap, capFirst, newInstance, range, timer } from '../client/components/core/CommonJs.js';
|
|
4
|
+
import * as dir from 'path';
|
|
5
|
+
import cliProgress from 'cli-progress';
|
|
6
|
+
import cliSpinners from 'cli-spinners';
|
|
7
|
+
import logUpdate from 'log-update';
|
|
8
|
+
import colors from 'colors';
|
|
9
|
+
import { loggerFactory } from './logger.js';
|
|
10
|
+
import { shellExec } from './process.js';
|
|
11
|
+
import { DefaultConf } from '../../conf.js';
|
|
12
|
+
|
|
13
|
+
colors.enable();
|
|
14
|
+
dotenv.config();
|
|
15
|
+
|
|
16
|
+
const logger = loggerFactory(import.meta);
|
|
17
|
+
|
|
18
|
+
// monitoring: https://app.pm2.io/
|
|
19
|
+
|
|
20
|
+
const Config = {
|
|
21
|
+
default: DefaultConf,
|
|
22
|
+
build: async function (options = { folder: '' }) {
|
|
23
|
+
if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
|
|
24
|
+
fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
|
|
25
|
+
if (fs.existsSync(`./engine-private/conf/${process.argv[2]}`)) return loadConf(process.argv[2]);
|
|
26
|
+
if (fs.existsSync(`./engine-private/replica/${process.argv[2]}`)) return loadConf(process.argv[2]);
|
|
27
|
+
|
|
28
|
+
if (process.argv[2] === 'deploy') return;
|
|
29
|
+
|
|
30
|
+
if (process.argv[2] === 'proxy') {
|
|
31
|
+
this.default.server = {};
|
|
32
|
+
for (const deployId of process.argv[3].split(',')) {
|
|
33
|
+
let confPath = `./engine-private/conf/${deployId}/conf.server.json`;
|
|
34
|
+
const privateConfDevPath = `./engine-private/conf/${deployId}/conf.server.dev.${process.argv[4]}.json`;
|
|
35
|
+
const confDevPath = fs.existsSync(privateConfDevPath)
|
|
36
|
+
? privateConfDevPath
|
|
37
|
+
: `./engine-private/conf/${deployId}/conf.server.dev.json`;
|
|
38
|
+
|
|
39
|
+
if (process.env.NODE_ENV === 'development' && fs.existsSync(confDevPath)) confPath = confDevPath;
|
|
40
|
+
const serverConf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
|
|
41
|
+
|
|
42
|
+
for (const host of Object.keys(loadReplicas(serverConf))) {
|
|
43
|
+
if (serverConf[host]['/'])
|
|
44
|
+
this.default.server[host] = {
|
|
45
|
+
...this.default.server[host],
|
|
46
|
+
...serverConf[host],
|
|
47
|
+
};
|
|
48
|
+
else
|
|
49
|
+
this.default.server[host] = {
|
|
50
|
+
...serverConf[host],
|
|
51
|
+
...this.default.server[host],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!options || !options.folder)
|
|
57
|
+
options = {
|
|
58
|
+
...options,
|
|
59
|
+
folder: `./conf`,
|
|
60
|
+
};
|
|
61
|
+
if (!fs.existsSync(options.folder)) fs.mkdirSync(options.folder, { recursive: true });
|
|
62
|
+
for (const confType of Object.keys(this.default)) {
|
|
63
|
+
fs.writeFileSync(
|
|
64
|
+
`${options.folder}/conf.${confType}.json`,
|
|
65
|
+
JSON.stringify(this.default[confType], null, 4),
|
|
66
|
+
'utf8',
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const loadConf = (deployId) => {
|
|
73
|
+
const folder = fs.existsSync(`./engine-private/replica/${deployId}`)
|
|
74
|
+
? `./engine-private/replica/${deployId}`
|
|
75
|
+
: `./engine-private/conf/${deployId}`;
|
|
76
|
+
if (!fs.existsSync(`./conf`)) fs.mkdirSync(`./conf`);
|
|
77
|
+
const isValidDeployId = fs.existsSync(`${folder}`);
|
|
78
|
+
for (const typeConf of Object.keys(Config.default)) {
|
|
79
|
+
let srcConf = isValidDeployId
|
|
80
|
+
? fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8')
|
|
81
|
+
: JSON.stringify(Config.default[typeConf]);
|
|
82
|
+
if (process.env.NODE_ENV === 'development' && typeConf === 'server') {
|
|
83
|
+
const devConfPath = `${folder}/conf.${typeConf}.dev${process.argv[3] ? `.${process.argv[3]}` : ''}.json`;
|
|
84
|
+
if (fs.existsSync(devConfPath)) srcConf = fs.readFileSync(devConfPath, 'utf8');
|
|
85
|
+
}
|
|
86
|
+
if (typeConf === 'server') srcConf = JSON.stringify(loadReplicas(JSON.parse(srcConf)), null, 4);
|
|
87
|
+
fs.writeFileSync(`./conf/conf.${typeConf}.json`, srcConf, 'utf8');
|
|
88
|
+
}
|
|
89
|
+
if (!isValidDeployId) return {};
|
|
90
|
+
fs.writeFileSync(`./.env.production`, fs.readFileSync(`${folder}/.env.production`, 'utf8'), 'utf8');
|
|
91
|
+
fs.writeFileSync(`./.env.development`, fs.readFileSync(`${folder}/.env.development`, 'utf8'), 'utf8');
|
|
92
|
+
fs.writeFileSync(`./.env.test`, fs.readFileSync(`${folder}/.env.test`, 'utf8'), 'utf8');
|
|
93
|
+
if (process.env.NODE_ENV) {
|
|
94
|
+
fs.writeFileSync(`./.env`, fs.readFileSync(`${folder}/.env.${process.env.NODE_ENV}`, 'utf8'), 'utf8');
|
|
95
|
+
const env = dotenv.parse(fs.readFileSync(`${folder}/.env.${process.env.NODE_ENV}`, 'utf8'));
|
|
96
|
+
process.env = {
|
|
97
|
+
...process.env,
|
|
98
|
+
...env,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
fs.writeFileSync(`./package.json`, fs.readFileSync(`${folder}/package.json`, 'utf8'), 'utf8');
|
|
102
|
+
return { folder, deployId };
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const loadReplicas = (confServer) => {
|
|
106
|
+
for (const host of Object.keys(confServer)) {
|
|
107
|
+
for (const path of Object.keys(confServer[host])) {
|
|
108
|
+
const { replicas, singleReplica } = confServer[host][path];
|
|
109
|
+
if (replicas && (process.argv[2] === 'proxy' || !singleReplica))
|
|
110
|
+
for (const replicaPath of replicas) {
|
|
111
|
+
confServer[host][replicaPath] = newInstance(confServer[host][path]);
|
|
112
|
+
delete confServer[host][replicaPath].replicas;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return confServer;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const getCapVariableName = (value = 'default') => cap(value.replaceAll('-', ' ')).replaceAll(' ', '');
|
|
120
|
+
|
|
121
|
+
const cloneConf = async (
|
|
122
|
+
{ toOptions, fromOptions },
|
|
123
|
+
fromDefaultOptions = { deployId: 'dd-default', clientId: 'default' },
|
|
124
|
+
) => {
|
|
125
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
126
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
127
|
+
|
|
128
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
129
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
130
|
+
|
|
131
|
+
const toClientVariableName = getCapVariableName(toOptions.clientId);
|
|
132
|
+
const fromClientVariableName = getCapVariableName(fromOptions.clientId);
|
|
133
|
+
|
|
134
|
+
const formattedSrc = (dataConf) =>
|
|
135
|
+
JSON.stringify(dataConf, null, 4)
|
|
136
|
+
.replaceAll(fromClientVariableName, toClientVariableName)
|
|
137
|
+
.replaceAll(fromOptions.clientId, toOptions.clientId);
|
|
138
|
+
|
|
139
|
+
const isMergeConf = fs.existsSync(confToFolder);
|
|
140
|
+
if (!isMergeConf) fs.mkdirSync(confToFolder, { recursive: true });
|
|
141
|
+
|
|
142
|
+
fs.writeFileSync(
|
|
143
|
+
`${confToFolder}/.env.production`,
|
|
144
|
+
fs.readFileSync(`${confFromFolder}/.env.production`, 'utf8'),
|
|
145
|
+
'utf8',
|
|
146
|
+
);
|
|
147
|
+
fs.writeFileSync(
|
|
148
|
+
`${confToFolder}/.env.development`,
|
|
149
|
+
fs.readFileSync(`${confFromFolder}/.env.development`, 'utf8'),
|
|
150
|
+
'utf8',
|
|
151
|
+
);
|
|
152
|
+
fs.writeFileSync(`${confToFolder}/.env.test`, fs.readFileSync(`${confFromFolder}/.env.test`, 'utf8'), 'utf8');
|
|
153
|
+
|
|
154
|
+
for (const confTypeId of ['server', 'client', 'cron', 'ssr']) {
|
|
155
|
+
const confFromData = JSON.parse(fs.readFileSync(`${confFromFolder}/conf.${confTypeId}.json`, 'utf8'));
|
|
156
|
+
fs.writeFileSync(`${confToFolder}/conf.${confTypeId}.json`, formattedSrc(confFromData), 'utf8');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const packageData = JSON.parse(fs.readFileSync(`${confFromFolder}/package.json`, 'utf8'));
|
|
160
|
+
packageData.scripts.start = packageData.scripts.start.replaceAll(fromOptions.deployId, toOptions.deployId);
|
|
161
|
+
fs.writeFileSync(`${confToFolder}/package.json`, JSON.stringify(packageData, null, 4), 'utf8');
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const addClientConf = async (
|
|
165
|
+
{ toOptions, fromOptions },
|
|
166
|
+
fromDefaultOptions = { deployId: 'dd-default', clientId: 'default' },
|
|
167
|
+
) => {
|
|
168
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
169
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
170
|
+
|
|
171
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
172
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
173
|
+
|
|
174
|
+
const toClientConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.client.json`, 'utf8'));
|
|
175
|
+
const fromClientConf = JSON.parse(fs.readFileSync(`${confFromFolder}/conf.client.json`, 'utf8'));
|
|
176
|
+
|
|
177
|
+
const toClientVariableName = getCapVariableName(toOptions.clientId);
|
|
178
|
+
const fromClientVariableName = getCapVariableName(fromOptions.clientId);
|
|
179
|
+
|
|
180
|
+
const { host, path } = toOptions;
|
|
181
|
+
|
|
182
|
+
toClientConf[fromOptions.clientId] = fromClientConf[fromOptions.clientId];
|
|
183
|
+
|
|
184
|
+
fs.writeFileSync(`${confToFolder}/conf.client.json`, JSON.stringify(toClientConf, null, 4), 'utf8');
|
|
185
|
+
|
|
186
|
+
const toServerConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
187
|
+
const fromServerConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
188
|
+
|
|
189
|
+
toServerConf[host][path].client = fromOptions.clientId;
|
|
190
|
+
toServerConf[host][path].runtime = 'nodejs';
|
|
191
|
+
toServerConf[host][path].apis = fromClientConf[fromOptions.clientId].services;
|
|
192
|
+
|
|
193
|
+
fs.writeFileSync(`${confToFolder}/conf.server.json`, JSON.stringify(toServerConf, null, 4), 'utf8');
|
|
194
|
+
|
|
195
|
+
const fromSsrConf = JSON.parse(fs.readFileSync(`${confFromFolder}/conf.ssr.json`, 'utf8'));
|
|
196
|
+
const toSsrConf = JSON.parse(fs.readFileSync(`${confToFolder}/conf.ssr.json`, 'utf8'));
|
|
197
|
+
|
|
198
|
+
toSsrConf[fromClientVariableName] = fromSsrConf[fromClientVariableName];
|
|
199
|
+
|
|
200
|
+
fs.writeFileSync(`${confToFolder}/conf.ssr.json`, JSON.stringify(toSsrConf, null, 4), 'utf8');
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const buildClientSrc = async (
|
|
204
|
+
{ toOptions, fromOptions },
|
|
205
|
+
fromDefaultOptions = { deployId: 'dd-default', clientId: 'default' },
|
|
206
|
+
) => {
|
|
207
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
208
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
209
|
+
|
|
210
|
+
const confFromFolder = `./src/client/components/${fromOptions.clientId}`;
|
|
211
|
+
const confToFolder = `./src/client/components/${toOptions.clientId}`;
|
|
212
|
+
|
|
213
|
+
const toClientVariableName = getCapVariableName(toOptions.clientId);
|
|
214
|
+
const fromClientVariableName = getCapVariableName(fromOptions.clientId);
|
|
215
|
+
|
|
216
|
+
const formattedSrc = (src) =>
|
|
217
|
+
src.replaceAll(fromClientVariableName, toClientVariableName).replaceAll(fromOptions.clientId, toOptions.clientId);
|
|
218
|
+
|
|
219
|
+
const isMergeConf = fs.existsSync(confToFolder);
|
|
220
|
+
if (!isMergeConf) fs.mkdirSync(confToFolder, { recursive: true });
|
|
221
|
+
|
|
222
|
+
const files = await fs.readdir(confFromFolder, { recursive: true });
|
|
223
|
+
for (const relativePath of files) {
|
|
224
|
+
const fromFilePath = dir.resolve(`${confFromFolder}/${relativePath}`);
|
|
225
|
+
const toFilePath = dir.resolve(`${confToFolder}/${relativePath}`);
|
|
226
|
+
|
|
227
|
+
fs.writeFileSync(formattedSrc(toFilePath), formattedSrc(fs.readFileSync(fromFilePath, 'utf8')), 'utf8');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fs.writeFileSync(
|
|
231
|
+
`./src/client/ssr/head-components/${toClientVariableName}Scripts.js`,
|
|
232
|
+
formattedSrc(fs.readFileSync(`./src/client/ssr/head-components/${fromClientVariableName}Scripts.js`, 'utf8')),
|
|
233
|
+
'utf8',
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
fs.writeFileSync(
|
|
237
|
+
`./src/client/${toClientVariableName}.js`,
|
|
238
|
+
formattedSrc(fs.readFileSync(`./src/client/${fromClientVariableName}.js`, 'utf8')),
|
|
239
|
+
'utf8',
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
fs.copySync(`./src/client/public/${fromOptions.clientId}`, `./src/client/public/${toOptions.clientId}`);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const buildApiSrc = async (
|
|
246
|
+
{ toOptions, fromOptions },
|
|
247
|
+
fromDefaultOptions = { apiId: 'default', deployId: 'dd-default', clientId: 'default' },
|
|
248
|
+
) => {
|
|
249
|
+
if (!fromOptions.apiId) fromOptions.apiId = fromDefaultOptions.apiId;
|
|
250
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
251
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
252
|
+
|
|
253
|
+
const toClientVariableName = getCapVariableName(toOptions.apiId);
|
|
254
|
+
const fromClientVariableName = getCapVariableName(fromOptions.apiId);
|
|
255
|
+
|
|
256
|
+
const formattedSrc = (src) =>
|
|
257
|
+
src.replaceAll(fromClientVariableName, toClientVariableName).replaceAll(fromOptions.apiId, toOptions.apiId);
|
|
258
|
+
|
|
259
|
+
const apiToFolder = `./src/api/${toOptions.apiId}`;
|
|
260
|
+
const apiFromFolder = `./src/api/${fromOptions.apiId}`;
|
|
261
|
+
|
|
262
|
+
const isMergeConf = fs.existsSync(apiToFolder);
|
|
263
|
+
if (!isMergeConf) fs.mkdirSync(apiToFolder, { recursive: true });
|
|
264
|
+
|
|
265
|
+
for (const srcApiType of ['model', 'controller', 'service', 'router']) {
|
|
266
|
+
fs.writeFileSync(
|
|
267
|
+
`${apiToFolder}/${toOptions.apiId}.${srcApiType}.js`,
|
|
268
|
+
formattedSrc(fs.readFileSync(`${apiFromFolder}/${fromOptions.apiId}.${srcApiType}.js`, 'utf8')),
|
|
269
|
+
'utf8',
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
fs.mkdirSync(`./src/client/services/${toOptions.apiId}`, { recursive: true });
|
|
274
|
+
if (fs.existsSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.service.js`))
|
|
275
|
+
fs.writeFileSync(
|
|
276
|
+
`./src/client/services/${toOptions.apiId}/${toOptions.apiId}.service.js`,
|
|
277
|
+
formattedSrc(
|
|
278
|
+
fs.readFileSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.service.js`, 'utf8'),
|
|
279
|
+
),
|
|
280
|
+
'utf8',
|
|
281
|
+
);
|
|
282
|
+
return;
|
|
283
|
+
if (fs.existsSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.management.js`))
|
|
284
|
+
fs.writeFileSync(
|
|
285
|
+
`./src/client/services/${toOptions.apiId}/${toOptions.apiId}.management.js`,
|
|
286
|
+
formattedSrc(
|
|
287
|
+
fs.readFileSync(`./src/client/services/${fromOptions.apiId}/${fromOptions.apiId}.management.js`, 'utf8'),
|
|
288
|
+
),
|
|
289
|
+
'utf8',
|
|
290
|
+
);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const addApiConf = async (
|
|
294
|
+
{ toOptions, fromOptions },
|
|
295
|
+
fromDefaultOptions = { apiId: 'default', deployId: 'dd-default', clientId: 'default' },
|
|
296
|
+
) => {
|
|
297
|
+
if (!fromOptions.apiId) fromOptions.apiId = fromDefaultOptions.apiId;
|
|
298
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
299
|
+
if (!fromOptions.clientId) fromOptions.clientId = fromDefaultOptions.clientId;
|
|
300
|
+
|
|
301
|
+
const toClientVariableName = getCapVariableName(toOptions.apiId);
|
|
302
|
+
const fromClientVariableName = getCapVariableName(fromOptions.apiId);
|
|
303
|
+
|
|
304
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
305
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
306
|
+
|
|
307
|
+
const confServer = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
308
|
+
for (const host of Object.keys(confServer))
|
|
309
|
+
for (const path of Object.keys(confServer[host]))
|
|
310
|
+
if (confServer[host][path].apis) confServer[host][path].apis.push(toOptions.apiId);
|
|
311
|
+
fs.writeFileSync(`${confToFolder}/conf.server.json`, JSON.stringify(confServer, null, 4), 'utf8');
|
|
312
|
+
|
|
313
|
+
const confClient = JSON.parse(fs.readFileSync(`${confToFolder}/conf.client.json`, 'utf8'));
|
|
314
|
+
confClient[toOptions.clientId].services.push(toOptions.apiId);
|
|
315
|
+
fs.writeFileSync(`${confToFolder}/conf.client.json`, JSON.stringify(confClient, null, 4), 'utf8');
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const addWsConf = async (
|
|
319
|
+
{ toOptions, fromOptions },
|
|
320
|
+
fromDefaultOptions = { wsId: 'default', deployId: 'dd-default', host: 'default.net', paths: '/' },
|
|
321
|
+
) => {
|
|
322
|
+
if (!fromOptions.wsId) fromOptions.wsId = fromDefaultOptions.wsId;
|
|
323
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
324
|
+
if (!fromOptions.host) fromOptions.host = fromDefaultOptions.host;
|
|
325
|
+
if (!fromOptions.paths) fromOptions.paths = fromDefaultOptions.paths;
|
|
326
|
+
|
|
327
|
+
const toClientVariableName = getCapVariableName(toOptions.apiId);
|
|
328
|
+
const fromClientVariableName = getCapVariableName(fromOptions.apiId);
|
|
329
|
+
|
|
330
|
+
const confFromFolder = `./engine-private/conf/${fromOptions.deployId}`;
|
|
331
|
+
const confToFolder = `./engine-private/conf/${toOptions.deployId}`;
|
|
332
|
+
|
|
333
|
+
const paths = toOptions.paths.split(',');
|
|
334
|
+
|
|
335
|
+
const confServer = JSON.parse(fs.readFileSync(`${confToFolder}/conf.server.json`, 'utf8'));
|
|
336
|
+
for (const host of Object.keys(confServer))
|
|
337
|
+
for (const path of Object.keys(confServer[host]))
|
|
338
|
+
if (host === toOptions.host && paths.includes(path) && confServer[host][path])
|
|
339
|
+
confServer[host][path].ws = toOptions.wsId;
|
|
340
|
+
fs.writeFileSync(`${confToFolder}/conf.server.json`, JSON.stringify(confServer, null, 4), 'utf8');
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const buildWsSrc = async (
|
|
344
|
+
{ toOptions, fromOptions },
|
|
345
|
+
fromDefaultOptions = { wsId: 'default', deployId: 'dd-default', host: 'default.net', paths: '/' },
|
|
346
|
+
) => {
|
|
347
|
+
if (!fromOptions.wsId) fromOptions.wsId = fromDefaultOptions.wsId;
|
|
348
|
+
if (!fromOptions.deployId) fromOptions.deployId = fromDefaultOptions.deployId;
|
|
349
|
+
if (!fromOptions.host) fromOptions.host = fromDefaultOptions.host;
|
|
350
|
+
if (!fromOptions.paths) fromOptions.paths = fromDefaultOptions.paths;
|
|
351
|
+
|
|
352
|
+
const toClientVariableName = getCapVariableName(toOptions.wsId);
|
|
353
|
+
const fromClientVariableName = getCapVariableName(fromOptions.wsId);
|
|
354
|
+
|
|
355
|
+
const confFromFolder = `./src/ws/${fromOptions.wsId}`;
|
|
356
|
+
const confToFolder = `./src/ws/${toOptions.wsId}`;
|
|
357
|
+
|
|
358
|
+
const paths = toOptions.paths.split(',');
|
|
359
|
+
|
|
360
|
+
const formattedSrc = (src) =>
|
|
361
|
+
src.replaceAll(fromClientVariableName, toClientVariableName).replaceAll(fromOptions.wsId, toOptions.wsId);
|
|
362
|
+
|
|
363
|
+
const files = await fs.readdir(confFromFolder, { recursive: true });
|
|
364
|
+
for (const relativePath of files) {
|
|
365
|
+
const fromFilePath = dir.resolve(`${confFromFolder}/${relativePath}`);
|
|
366
|
+
const toFilePath = dir.resolve(`${confToFolder}/${relativePath}`);
|
|
367
|
+
|
|
368
|
+
if (fs.lstatSync(fromFilePath).isDirectory() && !fs.existsSync(formattedSrc(toFilePath)))
|
|
369
|
+
fs.mkdirSync(formattedSrc(toFilePath), { recursive: true });
|
|
370
|
+
|
|
371
|
+
if (fs.lstatSync(fromFilePath).isFile() && !fs.existsSync(formattedSrc(toFilePath))) {
|
|
372
|
+
fs.writeFileSync(formattedSrc(toFilePath), formattedSrc(fs.readFileSync(fromFilePath, 'utf8')), 'utf8');
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const cloneSrcComponents = async ({ toOptions, fromOptions }) => {
|
|
378
|
+
const toClientVariableName = getCapVariableName(toOptions.componentsFolder);
|
|
379
|
+
const fromClientVariableName = getCapVariableName(fromOptions.componentsFolder);
|
|
380
|
+
|
|
381
|
+
const formattedSrc = (src) =>
|
|
382
|
+
src
|
|
383
|
+
.replaceAll(fromClientVariableName, toClientVariableName)
|
|
384
|
+
.replaceAll(fromOptions.componentsFolder, toOptions.componentsFolder);
|
|
385
|
+
|
|
386
|
+
const confFromFolder = `./src/client/components/${fromOptions.componentsFolder}`;
|
|
387
|
+
const confToFolder = `./src/client/components/${toOptions.componentsFolder}`;
|
|
388
|
+
|
|
389
|
+
fs.mkdirSync(confToFolder, { recursive: true });
|
|
390
|
+
|
|
391
|
+
const files = await fs.readdir(confFromFolder);
|
|
392
|
+
for (const relativePath of files) {
|
|
393
|
+
const fromFilePath = dir.resolve(`${confFromFolder}/${relativePath}`);
|
|
394
|
+
const toFilePath = dir.resolve(`${confToFolder}/${relativePath}`);
|
|
395
|
+
|
|
396
|
+
fs.writeFileSync(formattedSrc(toFilePath), formattedSrc(fs.readFileSync(fromFilePath, 'utf8')), 'utf8');
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
const buildProxyRouter = () => {
|
|
401
|
+
const confServer = JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'));
|
|
402
|
+
let currentPort = parseInt(process.env.PORT) + 1;
|
|
403
|
+
const proxyRouter = {};
|
|
404
|
+
const singleReplicaHosts = [];
|
|
405
|
+
for (const host of Object.keys(confServer)) {
|
|
406
|
+
for (const path of Object.keys(confServer[host])) {
|
|
407
|
+
if (confServer[host][path].singleReplica && !singleReplicaHosts.includes(host)) {
|
|
408
|
+
singleReplicaHosts.push(host);
|
|
409
|
+
currentPort++;
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
confServer[host][path].port = newInstance(currentPort);
|
|
413
|
+
for (const port of confServer[host][path].proxy) {
|
|
414
|
+
if (!(port in proxyRouter)) proxyRouter[port] = {};
|
|
415
|
+
proxyRouter[port][`${host}${path}`] = {
|
|
416
|
+
// target: `http://${host}:${confServer[host][path].port}${path}`,
|
|
417
|
+
target: `http://localhost:${confServer[host][path].port - singleReplicaHosts.length}`,
|
|
418
|
+
// target: `http://127.0.0.1:${confServer[host][path].port}`,
|
|
419
|
+
proxy: confServer[host][path].proxy,
|
|
420
|
+
redirect: confServer[host][path].redirect,
|
|
421
|
+
host,
|
|
422
|
+
path,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
currentPort++;
|
|
426
|
+
if (confServer[host][path].peer) {
|
|
427
|
+
const peerPath = path === '/' ? `/peer` : `${path}/peer`;
|
|
428
|
+
confServer[host][peerPath] = newInstance(confServer[host][path]);
|
|
429
|
+
confServer[host][peerPath].port = newInstance(currentPort);
|
|
430
|
+
for (const port of confServer[host][path].proxy) {
|
|
431
|
+
if (!(port in proxyRouter)) proxyRouter[port] = {};
|
|
432
|
+
proxyRouter[port][`${host}${peerPath}`] = {
|
|
433
|
+
// target: `http://${host}:${confServer[host][peerPath].port}${peerPath}`,
|
|
434
|
+
target: `http://localhost:${confServer[host][peerPath].port - singleReplicaHosts.length}`,
|
|
435
|
+
// target: `http://127.0.0.1:${confServer[host][peerPath].port}`,
|
|
436
|
+
proxy: confServer[host][peerPath].proxy,
|
|
437
|
+
host,
|
|
438
|
+
path: peerPath,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
currentPort++;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return proxyRouter;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const cliBar = async (time = 5000) => {
|
|
449
|
+
// create new progress bar
|
|
450
|
+
const b = new cliProgress.SingleBar({
|
|
451
|
+
format: 'Delay | {bar} | {percentage}% || {value}/{total} Chunks || Speed: {speed}',
|
|
452
|
+
barCompleteChar: '\u2588',
|
|
453
|
+
barIncompleteChar: '\u2591',
|
|
454
|
+
hideCursor: true,
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
const maxValueDisplay = 200;
|
|
458
|
+
const minValueDisplay = 0;
|
|
459
|
+
const steps = 10;
|
|
460
|
+
const incrementValue = 200 / steps;
|
|
461
|
+
const delayTime = time / steps;
|
|
462
|
+
// initialize the bar - defining payload token "speed" with the default value "N/A"
|
|
463
|
+
b.start(maxValueDisplay, minValueDisplay, {
|
|
464
|
+
speed: 'N/A',
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// update values
|
|
468
|
+
// b1.increment();
|
|
469
|
+
// b1.update(20);
|
|
470
|
+
|
|
471
|
+
for (const step of range(1, steps)) {
|
|
472
|
+
b.increment(incrementValue);
|
|
473
|
+
await timer(delayTime);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// stop the bar
|
|
477
|
+
b.stop();
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
const cliSpinner = async (time = 5000, message0, message1, color, type = 'dots') => {
|
|
481
|
+
const { frames, interval } = cliSpinners[type];
|
|
482
|
+
const steps = parseInt(time / interval);
|
|
483
|
+
let index = 0;
|
|
484
|
+
for (const step of range(1, steps)) {
|
|
485
|
+
const msg = `${message0 ? message0 : ''}${frames[index]}${message1 ? message1 : ''}`;
|
|
486
|
+
logUpdate(color ? msg[color] : msg);
|
|
487
|
+
await timer(interval);
|
|
488
|
+
index++;
|
|
489
|
+
if (index === frames.length) index = 0;
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const getDataDeploy = (options = { buildSingleReplica: false, deployGroupId: '' }) => {
|
|
494
|
+
let dataDeploy = JSON.parse(
|
|
495
|
+
fs.readFileSync(
|
|
496
|
+
`./engine-private/deploy/${options?.deployGroupId ? options.deployGroupId : process.argv[3]}.json`,
|
|
497
|
+
'utf8',
|
|
498
|
+
),
|
|
499
|
+
).map((deployId) => {
|
|
500
|
+
return {
|
|
501
|
+
deployId,
|
|
502
|
+
};
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
if (options && options.buildSingleReplica && fs.existsSync(`./engine-private/replica`))
|
|
506
|
+
fs.removeSync(`./engine-private/replica`);
|
|
507
|
+
|
|
508
|
+
let buildDataDeploy = [];
|
|
509
|
+
for (const deployObj of dataDeploy) {
|
|
510
|
+
const serverConf = loadReplicas(
|
|
511
|
+
JSON.parse(fs.readFileSync(`./engine-private/conf/${deployObj.deployId}/conf.server.json`, 'utf8')),
|
|
512
|
+
);
|
|
513
|
+
let replicaDataDeploy = [];
|
|
514
|
+
for (const host of Object.keys(serverConf))
|
|
515
|
+
for (const path of Object.keys(serverConf[host])) {
|
|
516
|
+
if (serverConf[host][path].replicas && serverConf[host][path].singleReplica) {
|
|
517
|
+
if (options && options.buildSingleReplica)
|
|
518
|
+
shellExec(`node bin/deploy build-single-replica ${deployObj.deployId} ${host} ${path}`);
|
|
519
|
+
replicaDataDeploy = replicaDataDeploy.concat(
|
|
520
|
+
serverConf[host][path].replicas.map((r) => {
|
|
521
|
+
return {
|
|
522
|
+
deployId: `${deployObj.deployId}-${r.slice(1)}`,
|
|
523
|
+
replicaHost: host,
|
|
524
|
+
};
|
|
525
|
+
}),
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
buildDataDeploy.push(deployObj);
|
|
530
|
+
if (replicaDataDeploy.length > 0) buildDataDeploy = buildDataDeploy.concat(replicaDataDeploy);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
logger.info('buildDataDeploy', buildDataDeploy);
|
|
534
|
+
return buildDataDeploy;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
const validateTemplatePath = (absolutePath = '') => {
|
|
538
|
+
const host = 'default.net';
|
|
539
|
+
const path = '/';
|
|
540
|
+
const client = 'default';
|
|
541
|
+
const ssr = 'Default';
|
|
542
|
+
const confServer = DefaultConf.server[host][path];
|
|
543
|
+
const confClient = DefaultConf.client[client];
|
|
544
|
+
const confSsr = DefaultConf.ssr[ssr];
|
|
545
|
+
const clients = Object.keys(confClient).concat(['core', 'test']);
|
|
546
|
+
|
|
547
|
+
if (absolutePath.match('src/api') && !confServer.apis.find((p) => absolutePath.match(`src/api/${p}/`))) {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
if (
|
|
551
|
+
absolutePath.match('src/client/services/') &&
|
|
552
|
+
!clients.find((p) => absolutePath.match(`src/client/services/${p}/`))
|
|
553
|
+
) {
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
if (absolutePath.match('src/client/public/') && !clients.find((p) => absolutePath.match(`src/client/public/${p}/`))) {
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
if (
|
|
560
|
+
absolutePath.match('src/client/components/') &&
|
|
561
|
+
!clients.find((p) => absolutePath.match(`src/client/components/${p}/`))
|
|
562
|
+
) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
if (absolutePath.match('src/client/sw/') && !clients.find((p) => absolutePath.match(`src/client/sw/${p}.sw.js`))) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
if (
|
|
569
|
+
absolutePath.match('src/client/ssr/body-components') &&
|
|
570
|
+
!confSsr.body.find((p) => absolutePath.match(`src/client/ssr/body-components/${p}.js`))
|
|
571
|
+
) {
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
if (
|
|
575
|
+
absolutePath.match('src/client/ssr/head-components') &&
|
|
576
|
+
!confSsr.head.find((p) => absolutePath.match(`src/client/ssr/head-components/${p}.js`))
|
|
577
|
+
) {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
if (
|
|
581
|
+
absolutePath.match('/client') &&
|
|
582
|
+
absolutePath.match('.index.js') &&
|
|
583
|
+
!clients.find((p) => absolutePath.match(`src/client/${capFirst(p)}.index.js`))
|
|
584
|
+
) {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
if (absolutePath.match('src/ws/') && !clients.find((p) => absolutePath.match(`src/ws/${p}/`))) {
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
return true;
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
export {
|
|
594
|
+
Config,
|
|
595
|
+
loadConf,
|
|
596
|
+
loadReplicas,
|
|
597
|
+
cloneConf,
|
|
598
|
+
getCapVariableName,
|
|
599
|
+
buildClientSrc,
|
|
600
|
+
buildApiSrc,
|
|
601
|
+
addApiConf,
|
|
602
|
+
addClientConf,
|
|
603
|
+
addWsConf,
|
|
604
|
+
buildWsSrc,
|
|
605
|
+
cloneSrcComponents,
|
|
606
|
+
buildProxyRouter,
|
|
607
|
+
cliBar,
|
|
608
|
+
cliSpinner,
|
|
609
|
+
getDataDeploy,
|
|
610
|
+
validateTemplatePath,
|
|
611
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
import { ip } from './network.js';
|
|
6
|
+
import { loggerFactory } from './logger.js';
|
|
7
|
+
import { isIPv4 } from 'is-ip';
|
|
8
|
+
|
|
9
|
+
dotenv.config();
|
|
10
|
+
|
|
11
|
+
const logger = loggerFactory(import.meta);
|
|
12
|
+
|
|
13
|
+
const Dns = {
|
|
14
|
+
ip: null,
|
|
15
|
+
ipDaemon: null,
|
|
16
|
+
InitIpDaemon: async function () {
|
|
17
|
+
// WAN | NAT-VPS | LAN
|
|
18
|
+
// enabled DMZ Host to proxy IP 80-443 (79-444) sometimes router block first port
|
|
19
|
+
// LAN server or device's local servers port -> 3000-3100 (2999-3101)
|
|
20
|
+
// DNS Records: [ANAME](Address Dynamic) -> [A](ipv4) host | [AAAA](ipv6) host -> [ip]
|
|
21
|
+
// DHCP (Dynamic Host Configuration Protocol) LAN reserver IP -> MAC ID
|
|
22
|
+
// Forward the router's TCP/UDP ports to the LAN device's IP address
|
|
23
|
+
|
|
24
|
+
const privateCronConfPath = `./engine-private/conf/${process.argv[2]}/conf.cron.json`;
|
|
25
|
+
|
|
26
|
+
const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
|
|
27
|
+
|
|
28
|
+
let confCronData = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
|
|
29
|
+
if (confCronData.ipDaemon.disabled) return;
|
|
30
|
+
this.ip = confCronData.ipDaemon.ip;
|
|
31
|
+
logger.info(`Current ip`, this.ip);
|
|
32
|
+
if (this.ipDaemon) clearInterval(this.ipDaemon);
|
|
33
|
+
const callback = async () => {
|
|
34
|
+
let testIp;
|
|
35
|
+
try {
|
|
36
|
+
testIp = await ip.public.ipv4();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
logger.error(error, { testIp, stack: error.stack });
|
|
39
|
+
}
|
|
40
|
+
if (testIp && typeof testIp === 'string' && isIPv4(testIp) && this.ip !== testIp) {
|
|
41
|
+
logger.info(`New ip`, testIp);
|
|
42
|
+
this.ip = testIp;
|
|
43
|
+
confCronData.ipDaemon.ip = this.ip;
|
|
44
|
+
fs.writeFileSync(confCronPath, JSON.stringify(confCronData, null, 4), 'utf8');
|
|
45
|
+
for (const recordType of Object.keys(confCronData.records)) {
|
|
46
|
+
switch (recordType) {
|
|
47
|
+
case 'A':
|
|
48
|
+
for (const dnsProvider of confCronData.records[recordType]) {
|
|
49
|
+
if (typeof this.services.updateIp[dnsProvider.dns] === 'function')
|
|
50
|
+
await this.services.updateIp[dnsProvider.dns](dnsProvider);
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
default:
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
await callback();
|
|
61
|
+
this.ipDaemon = setInterval(async () => await callback(), confCronData.ipDaemon.minutesTimeInterval * 1000 * 60);
|
|
62
|
+
},
|
|
63
|
+
services: {
|
|
64
|
+
updateIp: {
|
|
65
|
+
dondominio: (options) => {
|
|
66
|
+
const { user, api_key, host, dns } = options;
|
|
67
|
+
const url = `https://dondns.dondominio.com/json/?user=${user}&password=${api_key}&host=${host}&ip=${Dns.ip}`;
|
|
68
|
+
logger.info(`${dns} update ip url`, url);
|
|
69
|
+
if (process.env.NODE_ENV !== 'production') return false;
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
axios
|
|
72
|
+
.get(url)
|
|
73
|
+
.then((response) => {
|
|
74
|
+
logger.info(`${dns} update ip success`, response.data);
|
|
75
|
+
return resolve(true);
|
|
76
|
+
})
|
|
77
|
+
.catch((error) => {
|
|
78
|
+
logger.error(error, `${dns} update ip error`);
|
|
79
|
+
return resolve(false);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export { Dns };
|