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