underpost 2.8.86 → 2.8.88
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/.env.development +39 -2
- package/.env.production +42 -2
- package/.env.test +39 -2
- package/.github/workflows/ghpkg.ci.yml +1 -1
- package/.github/workflows/npmpkg.ci.yml +1 -1
- package/.github/workflows/pwa-microservices-template-page.cd.yml +6 -5
- package/.github/workflows/pwa-microservices-template-test.ci.yml +1 -1
- package/.github/workflows/release.cd.yml +3 -3
- package/README.md +76 -2
- package/bin/build.js +5 -0
- package/bin/deploy.js +93 -27
- package/bin/file.js +8 -4
- package/bin/util.js +1 -56
- package/cli.md +16 -5
- package/conf.js +33 -7
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/manifests/deployment/dd-test-development/deployment.yaml +174 -0
- package/manifests/deployment/dd-test-development/proxy.yaml +51 -0
- package/manifests/deployment/mongo-express/deployment.yaml +12 -12
- package/manifests/maas/nvim.sh +91 -0
- package/package.json +8 -15
- package/src/api/core/core.router.js +2 -1
- package/src/api/default/default.controller.js +6 -1
- package/src/api/default/default.router.js +6 -2
- package/src/api/default/default.service.js +10 -1
- package/src/api/document/document.controller.js +66 -0
- package/src/api/document/document.model.js +51 -0
- package/src/api/document/document.router.js +24 -0
- package/src/api/document/document.service.js +125 -0
- package/src/api/file/file.controller.js +15 -1
- package/src/api/file/file.router.js +2 -1
- package/src/api/file/file.service.js +28 -8
- package/src/api/test/test.router.js +1 -1
- package/src/api/user/postman_collection.json +216 -0
- package/src/api/user/user.controller.js +25 -60
- package/src/api/user/user.model.js +29 -7
- package/src/api/user/user.router.js +40 -8
- package/src/api/user/user.service.js +86 -35
- package/src/cli/baremetal.js +33 -3
- package/src/cli/cloud-init.js +11 -0
- package/src/cli/cluster.js +4 -23
- package/src/cli/cron.js +0 -1
- package/src/cli/db.js +0 -19
- package/src/cli/deploy.js +67 -52
- package/src/cli/fs.js +1 -0
- package/src/cli/index.js +9 -1
- package/src/cli/lxd.js +7 -0
- package/src/cli/repository.js +44 -6
- package/src/cli/run.js +56 -9
- package/src/cli/ssh.js +20 -6
- package/src/client/Default.index.js +42 -1
- package/src/client/components/core/Account.js +10 -2
- package/src/client/components/core/AgGrid.js +30 -8
- package/src/client/components/core/Auth.js +99 -56
- package/src/client/components/core/BtnIcon.js +3 -2
- package/src/client/components/core/CalendarCore.js +2 -3
- package/src/client/components/core/CommonJs.js +1 -2
- package/src/client/components/core/Content.js +15 -12
- package/src/client/components/core/Css.js +2 -1
- package/src/client/components/core/CssCore.js +18 -1
- package/src/client/components/core/Docs.js +5 -5
- package/src/client/components/core/FileExplorer.js +3 -3
- package/src/client/components/core/FullScreen.js +19 -28
- package/src/client/components/core/Input.js +22 -16
- package/src/client/components/core/JoyStick.js +2 -2
- package/src/client/components/core/LoadingAnimation.js +2 -2
- package/src/client/components/core/LogIn.js +16 -23
- package/src/client/components/core/LogOut.js +5 -1
- package/src/client/components/core/Logger.js +4 -1
- package/src/client/components/core/Modal.js +102 -87
- package/src/client/components/core/ObjectLayerEngine.js +229 -4
- package/src/client/components/core/ObjectLayerEngineModal.js +442 -0
- package/src/client/components/core/Pagination.js +207 -0
- package/src/client/components/core/Panel.js +10 -10
- package/src/client/components/core/PanelForm.js +130 -33
- package/src/client/components/core/Recover.js +2 -2
- package/src/client/components/core/Router.js +210 -34
- package/src/client/components/core/SignUp.js +1 -2
- package/src/client/components/core/Stream.js +1 -1
- package/src/client/components/core/ToggleSwitch.js +15 -1
- package/src/client/components/core/VanillaJs.js +3 -84
- package/src/client/components/core/Worker.js +2 -2
- package/src/client/components/default/LogInDefault.js +0 -6
- package/src/client/components/default/LogOutDefault.js +0 -16
- package/src/client/components/default/MenuDefault.js +97 -44
- package/src/client/components/default/RoutesDefault.js +5 -2
- package/src/client/public/default/assets/mailer/api-user-default-avatar.png +0 -0
- package/src/client/services/core/core.service.js +8 -20
- package/src/client/services/default/default.management.js +115 -18
- package/src/client/services/default/default.service.js +13 -4
- package/src/client/services/document/document.service.js +97 -0
- package/src/client/services/file/file.service.js +2 -0
- package/src/client/services/test/test.service.js +3 -0
- package/src/client/services/user/user.management.js +6 -0
- package/src/client/services/user/user.service.js +15 -4
- package/src/client/ssr/Render.js +1 -1
- package/src/client/ssr/head/DefaultScripts.js +3 -0
- package/src/client/ssr/head/Seo.js +1 -0
- package/src/index.js +24 -2
- package/src/runtime/lampp/Lampp.js +89 -2
- package/src/runtime/xampp/Xampp.js +48 -1
- package/src/server/auth.js +519 -155
- package/src/server/backup.js +2 -2
- package/src/server/client-build-docs.js +1 -1
- package/src/server/client-build.js +4 -12
- package/src/server/client-icons.js +6 -78
- package/src/server/conf.js +144 -141
- package/src/server/process.js +2 -1
- package/src/server/proxy.js +1 -1
- package/src/server/runtime.js +136 -288
- package/src/server/ssl.js +1 -2
- package/src/server/ssr.js +85 -0
- package/src/server/start.js +4 -4
- package/src/server/valkey.js +2 -1
- package/test/api.test.js +3 -2
- package/bin/cyberia0.js +0 -78
package/src/server/backup.js
CHANGED
|
@@ -61,10 +61,10 @@ class BackUp {
|
|
|
61
61
|
}
|
|
62
62
|
shellExec(
|
|
63
63
|
`cd ./engine-private/cron-backups` +
|
|
64
|
-
` && underpost pull .
|
|
64
|
+
` && underpost pull . ${process.env.GITHUB_USERNAME}/cron-backups` +
|
|
65
65
|
` && git add .` +
|
|
66
66
|
` && underpost cmt . backup cron-job '${new Date().toLocaleDateString()}'` +
|
|
67
|
-
` && underpost push .
|
|
67
|
+
` && underpost push . ${process.env.GITHUB_USERNAME}/cron-backups`,
|
|
68
68
|
{
|
|
69
69
|
disableLog: true,
|
|
70
70
|
},
|
|
@@ -159,7 +159,7 @@ const buildCoverage = async ({ host, path }) => {
|
|
|
159
159
|
shellExec(`npm test`);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
const coverageBuildPath = `${jsDocsConfig.opts.destination}
|
|
162
|
+
const coverageBuildPath = `${jsDocsConfig.opts.destination}coverage`;
|
|
163
163
|
fs.mkdirSync(coverageBuildPath, { recursive: true });
|
|
164
164
|
fs.copySync(`./coverage`, coverageBuildPath);
|
|
165
165
|
|
|
@@ -19,7 +19,7 @@ import * as dir from 'path';
|
|
|
19
19
|
import { shellExec } from './process.js';
|
|
20
20
|
import { SitemapStream, streamToPromise } from 'sitemap';
|
|
21
21
|
import { Readable } from 'stream';
|
|
22
|
-
import { buildIcons
|
|
22
|
+
import { buildIcons } from './client-icons.js';
|
|
23
23
|
import Underpost from '../index.js';
|
|
24
24
|
import { buildDocs } from './client-build-docs.js';
|
|
25
25
|
|
|
@@ -65,16 +65,8 @@ const fullBuild = async ({
|
|
|
65
65
|
fs.removeSync(rootClientPath);
|
|
66
66
|
|
|
67
67
|
if (fs.existsSync(`./src/client/public/${publicClientId}`)) {
|
|
68
|
-
if (iconsBuild) {
|
|
69
|
-
|
|
70
|
-
if (!fs.existsSync(defaultBaseIconFolderPath)) fs.mkdirSync(defaultBaseIconFolderPath, { recursive: true });
|
|
71
|
-
const defaultBaseIconPath = `${defaultBaseIconFolderPath}/base-icon.png`;
|
|
72
|
-
if (!fs.existsSync(defaultBaseIconPath))
|
|
73
|
-
await buildTextImg(metadata.title, { debugFilename: defaultBaseIconPath });
|
|
74
|
-
|
|
75
|
-
if (!fs.existsSync(`./src/client/public/${publicClientId}/site.webmanifest`))
|
|
76
|
-
await buildIcons({ publicClientId, metadata });
|
|
77
|
-
}
|
|
68
|
+
if (iconsBuild === true) await buildIcons({ publicClientId, metadata });
|
|
69
|
+
|
|
78
70
|
fs.copySync(
|
|
79
71
|
`./src/client/public/${publicClientId}`,
|
|
80
72
|
rootClientPath /* {
|
|
@@ -535,7 +527,7 @@ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
|
|
|
535
527
|
);
|
|
536
528
|
}
|
|
537
529
|
|
|
538
|
-
if (
|
|
530
|
+
if (fullBuildEnabled && !enableLiveRebuild && !process.argv.includes('l') && docsBuild) {
|
|
539
531
|
await buildDocs({
|
|
540
532
|
host,
|
|
541
533
|
path,
|
|
@@ -1,80 +1,17 @@
|
|
|
1
1
|
import { favicons } from 'favicons';
|
|
2
|
-
// TODO: search alternatives
|
|
3
|
-
// import textToImage from 'text-to-image';
|
|
4
2
|
import { loggerFactory } from './logger.js';
|
|
5
3
|
import fs from 'fs-extra';
|
|
6
|
-
import { getCapVariableName
|
|
7
|
-
import { FileFactory } from '../api/file/file.service.js';
|
|
8
|
-
import { svg, png, png3x } from 'font-awesome-assets';
|
|
4
|
+
import { getCapVariableName } from '../client/components/core/CommonJs.js';
|
|
9
5
|
|
|
10
6
|
const logger = loggerFactory(import.meta);
|
|
11
7
|
|
|
12
|
-
const faBase64Png = (faId = 'check', width = 100, height = 100, color = '#209e00') => {
|
|
13
|
-
const b64Src = png3x(faId, color, width, height);
|
|
14
|
-
return b64Src.split('src="data:image/png;base64,')[1].split('"')[0];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const defaultBaseTextImgOptions = {
|
|
18
|
-
debug: true,
|
|
19
|
-
fontFamily: 'Arial',
|
|
20
|
-
fontWeight: 'bold',
|
|
21
|
-
bgColor: 'black',
|
|
22
|
-
textColor: 'white',
|
|
23
|
-
debugFilename: 'src/client/public/text-image.png',
|
|
24
|
-
verticalAlign: 'center',
|
|
25
|
-
textAlign: 'center',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const defaultBaseTextImgOptionsSizes = {
|
|
29
|
-
'70x70': {
|
|
30
|
-
maxWidth: 70,
|
|
31
|
-
customHeight: 70,
|
|
32
|
-
fontSize: 25,
|
|
33
|
-
margin: 10,
|
|
34
|
-
},
|
|
35
|
-
'100x100': {
|
|
36
|
-
maxWidth: 100,
|
|
37
|
-
customHeight: 100,
|
|
38
|
-
fontSize: 30,
|
|
39
|
-
margin: 12,
|
|
40
|
-
},
|
|
41
|
-
'100x300': {
|
|
42
|
-
maxWidth: 300,
|
|
43
|
-
customHeight: 100,
|
|
44
|
-
fontSize: 30,
|
|
45
|
-
margin: 12,
|
|
46
|
-
},
|
|
47
|
-
'1200x1200': {
|
|
48
|
-
maxWidth: 1200,
|
|
49
|
-
customHeight: 1200,
|
|
50
|
-
fontSize: 500,
|
|
51
|
-
margin: 50,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const buildTextImg = async (text = 'APP', options, size = '1200x1200') => {
|
|
56
|
-
options = { ...defaultBaseTextImgOptions, ...defaultBaseTextImgOptionsSizes[size], ...options };
|
|
57
|
-
// await textToImage.generate(text, options);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const getBufferPngText = async ({ text, textColor, bgColor, size, debugFilename }) => {
|
|
61
|
-
if (!text) text = 'Hello World!';
|
|
62
|
-
if (!textColor) textColor = '#000000';
|
|
63
|
-
if (!bgColor) bgColor = '#ffffff';
|
|
64
|
-
if (!size) size = '100x300';
|
|
65
|
-
if (!debugFilename) debugFilename = `./${s4()}${s4()}${s4()}.png`;
|
|
66
|
-
await buildTextImg(text, { textColor, bgColor, size, debugFilename }, size);
|
|
67
|
-
if (!fs.existsSync(debugFilename)) return Buffer.alloc(0); // Return empty buffer if file not found
|
|
68
|
-
const bufferImage = fs.readFileSync(debugFilename);
|
|
69
|
-
fs.removeSync(debugFilename);
|
|
70
|
-
return bufferImage;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
8
|
const buildIcons = async ({
|
|
74
9
|
publicClientId,
|
|
75
|
-
metadata: { title, description, keywords, author, thumbnail, themeColor },
|
|
10
|
+
metadata: { title, description, keywords, author, thumbnail, themeColor, baseBuildIconReference },
|
|
76
11
|
}) => {
|
|
77
|
-
const source =
|
|
12
|
+
const source = baseBuildIconReference
|
|
13
|
+
? baseBuildIconReference
|
|
14
|
+
: `src/client/public/${publicClientId}/assets/logo/base-icon.png`; // Source image(s). `string`, `buffer` or array of `string`
|
|
78
15
|
|
|
79
16
|
const configuration = {
|
|
80
17
|
path: '/', // Path for overriding default icons path. `string`
|
|
@@ -149,13 +86,4 @@ const buildIcons = async ({
|
|
|
149
86
|
}
|
|
150
87
|
};
|
|
151
88
|
|
|
152
|
-
|
|
153
|
-
const faId = 'user';
|
|
154
|
-
const tmpFilePath = `./tmp/${faId}-${s4() + s4()}.svg`;
|
|
155
|
-
fs.writeFileSync(tmpFilePath, svg(faId, '#f5f5f5d1'), 'utf8');
|
|
156
|
-
const file = await new File(FileFactory.svg(fs.readFileSync(tmpFilePath), `${faId}.svg`)).save();
|
|
157
|
-
fs.removeSync(tmpFilePath);
|
|
158
|
-
return file._id;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export { buildIcons, buildTextImg, defaultBaseTextImgOptions, faBase64Png, getBufferPngText, getDefaultProfileImageId };
|
|
89
|
+
export { buildIcons };
|
package/src/server/conf.js
CHANGED
|
@@ -9,17 +9,12 @@ import {
|
|
|
9
9
|
timer,
|
|
10
10
|
} from '../client/components/core/CommonJs.js';
|
|
11
11
|
import * as dir from 'path';
|
|
12
|
-
import cliProgress from 'cli-progress';
|
|
13
|
-
import cliSpinners from 'cli-spinners';
|
|
14
|
-
import logUpdate from 'log-update';
|
|
15
12
|
import colors from 'colors';
|
|
16
13
|
import { loggerFactory } from './logger.js';
|
|
17
14
|
import { shellExec } from './process.js';
|
|
18
15
|
import { DefaultConf } from '../../conf.js';
|
|
19
|
-
import read from 'read';
|
|
20
16
|
import splitFile from 'split-file';
|
|
21
|
-
import
|
|
22
|
-
import { ssrFactory } from './client-formatted.js';
|
|
17
|
+
import UnderpostRootEnv from '../cli/env.js';
|
|
23
18
|
|
|
24
19
|
colors.enable();
|
|
25
20
|
|
|
@@ -27,68 +22,123 @@ dotenv.config();
|
|
|
27
22
|
|
|
28
23
|
const logger = loggerFactory(import.meta);
|
|
29
24
|
|
|
30
|
-
// monitoring: https://app.pm2.io/
|
|
31
|
-
|
|
32
25
|
const Config = {
|
|
33
26
|
default: DefaultConf,
|
|
34
|
-
build: async function (
|
|
35
|
-
if (
|
|
27
|
+
build: async function (deployContext = 'dd-default', deployList, subConf) {
|
|
28
|
+
if (typeof process.argv[2] === 'string' && process.argv[2].startsWith('dd-')) deployContext = process.argv[2];
|
|
36
29
|
if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
|
|
37
|
-
|
|
38
|
-
if (fs.existsSync(`./engine-private/conf/${deployContext}`))
|
|
39
|
-
return loadConf(deployContext, process.env.NODE_ENV, subConf);
|
|
30
|
+
UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
|
|
40
31
|
if (fs.existsSync(`./engine-private/replica/${deployContext}`))
|
|
41
32
|
return loadConf(deployContext, process.env.NODE_ENV, subConf);
|
|
33
|
+
else if (deployContext.startsWith('dd-')) return loadConf(deployContext, process.env.NODE_ENV, subConf);
|
|
34
|
+
if (deployContext === 'proxy') Config.buildProxy(deployContext, deployList, subConf);
|
|
35
|
+
},
|
|
36
|
+
deployIdFactory: function (deployId = 'dd-default', options = { cluster: false }) {
|
|
37
|
+
if (!deployId.startsWith('dd-')) deployId = `dd-${deployId}`;
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
folder: `./conf`,
|
|
79
|
-
};
|
|
80
|
-
if (!fs.existsSync(options.folder)) fs.mkdirSync(options.folder, { recursive: true });
|
|
81
|
-
for (const confType of Object.keys(this.default)) {
|
|
39
|
+
logger.info('Build deployId', deployId);
|
|
40
|
+
|
|
41
|
+
const folder = `./engine-private/conf/${deployId}`;
|
|
42
|
+
const repoName = `engine-${deployId.split('dd-')[1]}`;
|
|
43
|
+
|
|
44
|
+
if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true });
|
|
45
|
+
fs.writeFileSync(
|
|
46
|
+
`${folder}/.env.production`,
|
|
47
|
+
fs.readFileSync('./.env.production', 'utf8').replaceAll('dd-default', deployId),
|
|
48
|
+
'utf8',
|
|
49
|
+
);
|
|
50
|
+
fs.writeFileSync(
|
|
51
|
+
`${folder}/.env.development`,
|
|
52
|
+
fs.readFileSync('./.env.development', 'utf8').replaceAll('dd-default', deployId),
|
|
53
|
+
'utf8',
|
|
54
|
+
);
|
|
55
|
+
fs.writeFileSync(
|
|
56
|
+
`${folder}/.env.test`,
|
|
57
|
+
fs.readFileSync('./.env.test', 'utf8').replaceAll('dd-default', deployId),
|
|
58
|
+
'utf8',
|
|
59
|
+
);
|
|
60
|
+
fs.writeFileSync(
|
|
61
|
+
`${folder}/package.json`,
|
|
62
|
+
fs.readFileSync('./package.json', 'utf8').replaceAll('dd-default', deployId),
|
|
63
|
+
'utf8',
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
this.buildTmpConf(folder);
|
|
67
|
+
|
|
68
|
+
if (options.cluster === true) {
|
|
69
|
+
fs.writeFileSync(
|
|
70
|
+
`./.github/workflows/${repoName}.cd.yml`,
|
|
71
|
+
fs.readFileSync(`./.github/workflows/engine-test.cd.yml`, 'utf8').replaceAll('test', deployId.split('dd-')[1]),
|
|
72
|
+
'utf8',
|
|
73
|
+
);
|
|
82
74
|
fs.writeFileSync(
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
`./.github/workflows/${repoName}.ci.yml`,
|
|
76
|
+
fs.readFileSync(`./.github/workflows/engine-test.ci.yml`, 'utf8').replaceAll('test', deployId.split('dd-')[1]),
|
|
85
77
|
'utf8',
|
|
86
78
|
);
|
|
79
|
+
shellExec(`node bin/deploy update-default-conf ${deployId}`);
|
|
80
|
+
|
|
81
|
+
if (!fs.existsSync(`./engine-private/deploy/dd.router`))
|
|
82
|
+
fs.writeFileSync(`./engine-private/deploy/dd.router`, '', 'utf8');
|
|
83
|
+
|
|
84
|
+
fs.writeFileSync(
|
|
85
|
+
`./engine-private/deploy/dd.router`,
|
|
86
|
+
fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8').trim() + `,${deployId}`,
|
|
87
|
+
'utf8',
|
|
88
|
+
);
|
|
89
|
+
const updateRepo = (stage = 1) => {
|
|
90
|
+
shellExec(`git add . && git commit -m "Add base deployId ${deployId} cluster files stage:${stage}"`);
|
|
91
|
+
shellExec(
|
|
92
|
+
`cd engine-private && git add . && git commit -m "Add base deployId ${deployId} cluster files stage:${stage}"`,
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
updateRepo(1);
|
|
96
|
+
shellExec(`node bin run --build --dev sync`);
|
|
97
|
+
updateRepo(2);
|
|
98
|
+
shellExec(`node bin run --build sync`);
|
|
99
|
+
updateRepo(3);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { deployIdFolder: folder, deployId };
|
|
103
|
+
},
|
|
104
|
+
buildTmpConf: function (folder = './conf') {
|
|
105
|
+
for (const confType of Object.keys(this.default))
|
|
106
|
+
fs.writeFileSync(`${folder}/conf.${confType}.json`, JSON.stringify(this.default[confType], null, 4), 'utf8');
|
|
107
|
+
},
|
|
108
|
+
buildProxy: function (deployContext = 'dd-default', deployList, subConf) {
|
|
109
|
+
if (!deployList) deployList = process.argv[3];
|
|
110
|
+
if (!subConf) subConf = process.argv[4];
|
|
111
|
+
this.default.server = {};
|
|
112
|
+
for (const deployId of deployList.split(',')) {
|
|
113
|
+
let confPath = `./engine-private/conf/${deployId}/conf.server.json`;
|
|
114
|
+
const privateConfDevPath = fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
|
|
115
|
+
? `./engine-private/replica/${deployId}/conf.server.json`
|
|
116
|
+
: `./engine-private/conf/${deployId}/conf.server.dev.${subConf}.json`;
|
|
117
|
+
const confDevPath = fs.existsSync(privateConfDevPath)
|
|
118
|
+
? privateConfDevPath
|
|
119
|
+
: `./engine-private/conf/${deployId}/conf.server.dev.json`;
|
|
120
|
+
|
|
121
|
+
if (process.env.NODE_ENV === 'development' && fs.existsSync(confDevPath)) confPath = confDevPath;
|
|
122
|
+
const serverConf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
|
|
123
|
+
|
|
124
|
+
for (const host of Object.keys(loadReplicas(serverConf, deployContext, subConf))) {
|
|
125
|
+
if (serverConf[host]['/'])
|
|
126
|
+
this.default.server[host] = {
|
|
127
|
+
...this.default.server[host],
|
|
128
|
+
...serverConf[host],
|
|
129
|
+
};
|
|
130
|
+
else
|
|
131
|
+
this.default.server[host] = {
|
|
132
|
+
...serverConf[host],
|
|
133
|
+
...this.default.server[host],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
87
136
|
}
|
|
137
|
+
this.buildTmpConf();
|
|
88
138
|
},
|
|
89
139
|
};
|
|
90
140
|
|
|
91
|
-
const loadConf = (deployId, envInput, subConf) => {
|
|
141
|
+
const loadConf = (deployId = 'dd-default', envInput, subConf) => {
|
|
92
142
|
if (deployId === 'current') {
|
|
93
143
|
console.log(process.env.DEPLOY_ID);
|
|
94
144
|
return;
|
|
@@ -104,22 +154,15 @@ const loadConf = (deployId, envInput, subConf) => {
|
|
|
104
154
|
shellExec(`git checkout ${path}/package-lock.json`);
|
|
105
155
|
return;
|
|
106
156
|
}
|
|
107
|
-
if (!deployId.startsWith('dd-')) deployId = 'dd-default';
|
|
108
157
|
const folder = fs.existsSync(`./engine-private/replica/${deployId}`)
|
|
109
158
|
? `./engine-private/replica/${deployId}`
|
|
110
159
|
: `./engine-private/conf/${deployId}`;
|
|
160
|
+
if (!fs.existsSync(folder)) Config.deployIdFactory(deployId);
|
|
111
161
|
if (!fs.existsSync(`./conf`)) fs.mkdirSync(`./conf`);
|
|
112
|
-
if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp
|
|
113
|
-
|
|
114
|
-
if (!isValidDeployId) {
|
|
115
|
-
logger.info(`Save new deploy conf: '${deployId}'`);
|
|
116
|
-
shellExec(`node bin/deploy save ${deployId}`);
|
|
117
|
-
return loadConf(deployId);
|
|
118
|
-
}
|
|
162
|
+
if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`);
|
|
163
|
+
|
|
119
164
|
for (const typeConf of Object.keys(Config.default)) {
|
|
120
|
-
let srcConf =
|
|
121
|
-
? fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8')
|
|
122
|
-
: JSON.stringify(Config.default[typeConf]);
|
|
165
|
+
let srcConf = fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8');
|
|
123
166
|
if (process.env.NODE_ENV === 'development' && typeConf === 'server') {
|
|
124
167
|
if (!subConf) subConf = process.argv[3];
|
|
125
168
|
const devConfPath = `${folder}/conf.${typeConf}.dev${subConf ? `.${subConf}` : ''}.json`;
|
|
@@ -494,15 +537,6 @@ const buildProxyRouter = () => {
|
|
|
494
537
|
}
|
|
495
538
|
}
|
|
496
539
|
}
|
|
497
|
-
if (process.argv.includes('maintenance'))
|
|
498
|
-
(async () => {
|
|
499
|
-
globalThis.defaultHtmlSrcMaintenance = (await ssrFactory())({
|
|
500
|
-
title: 'Site in maintenance',
|
|
501
|
-
ssrPath: '/',
|
|
502
|
-
ssrHeadComponents: '',
|
|
503
|
-
ssrBodyComponents: (await ssrFactory(`./src/client/ssr/offline/Maintenance.js`))(),
|
|
504
|
-
});
|
|
505
|
-
})();
|
|
506
540
|
|
|
507
541
|
return proxyRouter;
|
|
508
542
|
};
|
|
@@ -562,16 +596,24 @@ const buildPortProxyRouter = (port, proxyRouter) => {
|
|
|
562
596
|
// build router
|
|
563
597
|
Object.keys(hosts).map((hostKey) => {
|
|
564
598
|
let { host, path, target, proxy, peer } = hosts[hostKey];
|
|
565
|
-
if (process.
|
|
599
|
+
if (process.env.NODE_ENV === 'development' && process.argv.includes('localhost')) host = `localhost`;
|
|
600
|
+
|
|
601
|
+
if (!proxy.includes(port)) {
|
|
602
|
+
logger.warn('Proxy port not set on conf', { port, host, path, proxy, target });
|
|
603
|
+
if (process.env.NODE_ENV === 'production') {
|
|
604
|
+
logger.warn('Omitting host', { host, path, target });
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
566
608
|
|
|
567
|
-
if (!proxy.includes(port)) return;
|
|
568
609
|
const absoluteHost = [80, 443].includes(port)
|
|
569
610
|
? `${host}${path === '/' ? '' : path}`
|
|
570
611
|
: `${host}:${port}${path === '/' ? '' : path}`;
|
|
571
612
|
|
|
572
|
-
if (
|
|
573
|
-
|
|
574
|
-
|
|
613
|
+
if (absoluteHost in router)
|
|
614
|
+
logger.warn('Overwrite: Absolute host already exists on router', { absoluteHost, target });
|
|
615
|
+
|
|
616
|
+
router[absoluteHost] = target;
|
|
575
617
|
}); // order router
|
|
576
618
|
|
|
577
619
|
if (Object.keys(router).length === 0) return router;
|
|
@@ -583,51 +625,6 @@ const buildPortProxyRouter = (port, proxyRouter) => {
|
|
|
583
625
|
return reOrderRouter;
|
|
584
626
|
};
|
|
585
627
|
|
|
586
|
-
const cliBar = async (time = 5000) => {
|
|
587
|
-
// create new progress bar
|
|
588
|
-
const b = new cliProgress.SingleBar({
|
|
589
|
-
format: 'Delay | {bar} | {percentage}% || {value}/{total} Chunks || Speed: {speed}',
|
|
590
|
-
barCompleteChar: '\u2588',
|
|
591
|
-
barIncompleteChar: '\u2591',
|
|
592
|
-
hideCursor: true,
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
const maxValueDisplay = 200;
|
|
596
|
-
const minValueDisplay = 0;
|
|
597
|
-
const steps = 10;
|
|
598
|
-
const incrementValue = 200 / steps;
|
|
599
|
-
const delayTime = time / steps;
|
|
600
|
-
// initialize the bar - defining payload token "speed" with the default value "N/A"
|
|
601
|
-
b.start(maxValueDisplay, minValueDisplay, {
|
|
602
|
-
speed: 'N/A',
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
// update values
|
|
606
|
-
// b1.increment();
|
|
607
|
-
// b1.update(20);
|
|
608
|
-
|
|
609
|
-
for (const step of range(1, steps)) {
|
|
610
|
-
b.increment(incrementValue);
|
|
611
|
-
await timer(delayTime);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// stop the bar
|
|
615
|
-
b.stop();
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
const cliSpinner = async (time = 5000, message0, message1, color, type = 'dots') => {
|
|
619
|
-
const { frames, interval } = cliSpinners[type];
|
|
620
|
-
const steps = parseInt(time / interval);
|
|
621
|
-
let index = 0;
|
|
622
|
-
for (const step of range(1, steps)) {
|
|
623
|
-
const msg = `${message0 ? message0 : ''}${frames[index]}${message1 ? message1 : ''}`;
|
|
624
|
-
logUpdate(color ? msg[color] : msg);
|
|
625
|
-
await timer(interval);
|
|
626
|
-
index++;
|
|
627
|
-
if (index === frames.length) index = 0;
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
|
|
631
628
|
const buildReplicaId = ({ deployId, replica }) => `${deployId}-${replica.slice(1)}`;
|
|
632
629
|
|
|
633
630
|
const getDataDeploy = (
|
|
@@ -636,7 +633,6 @@ const getDataDeploy = (
|
|
|
636
633
|
deployGroupId: '',
|
|
637
634
|
deployId: '',
|
|
638
635
|
disableSyncEnvPort: false,
|
|
639
|
-
deployIdConcat: [],
|
|
640
636
|
},
|
|
641
637
|
) => {
|
|
642
638
|
let dataDeploy =
|
|
@@ -649,8 +645,6 @@ const getDataDeploy = (
|
|
|
649
645
|
.map((deployId) => deployId.trim())
|
|
650
646
|
.filter((deployId) => deployId);
|
|
651
647
|
|
|
652
|
-
if (options.deployIdConcat) dataDeploy = dataDeploy.concat(options.deployIdConcat);
|
|
653
|
-
|
|
654
648
|
if (options.deployId) dataDeploy = dataDeploy.filter((d) => d === options.deployId);
|
|
655
649
|
|
|
656
650
|
dataDeploy = dataDeploy.map((deployId) => {
|
|
@@ -702,7 +696,7 @@ const validateTemplatePath = (absolutePath = '') => {
|
|
|
702
696
|
const confServer = DefaultConf.server[host][path];
|
|
703
697
|
const confClient = DefaultConf.client[client];
|
|
704
698
|
const confSsr = DefaultConf.ssr[ssr];
|
|
705
|
-
const clients =
|
|
699
|
+
const clients = DefaultConf.client.default.services;
|
|
706
700
|
|
|
707
701
|
if (absolutePath.match('src/api') && !confServer.apis.find((p) => absolutePath.match(`src/api/${p}/`))) {
|
|
708
702
|
return false;
|
|
@@ -772,15 +766,9 @@ const validateTemplatePath = (absolutePath = '') => {
|
|
|
772
766
|
};
|
|
773
767
|
|
|
774
768
|
const awaitDeployMonitor = async (init = false, deltaMs = 1000) => {
|
|
775
|
-
if (init)
|
|
769
|
+
if (init) UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
|
|
776
770
|
await timer(deltaMs);
|
|
777
|
-
if (
|
|
778
|
-
};
|
|
779
|
-
|
|
780
|
-
const getDeployId = () => {
|
|
781
|
-
const deployIndexArg = process.argv.findIndex((a) => a.match(`deploy-id:`));
|
|
782
|
-
if (deployIndexArg > -1) return process.argv[deployIndexArg].split(':')[1].trim();
|
|
783
|
-
return 'dd-default';
|
|
771
|
+
if (UnderpostRootEnv.API.get('await-deploy')) return await awaitDeployMonitor();
|
|
784
772
|
};
|
|
785
773
|
|
|
786
774
|
const getCronBackUpFolder = (host = '', path = '') => {
|
|
@@ -969,7 +957,7 @@ const buildCliDoc = (program, oldVersion, newVersion) => {
|
|
|
969
957
|
baseOptions +
|
|
970
958
|
`
|
|
971
959
|
|
|
972
|
-
<a target="_top" href="https://github.com/
|
|
960
|
+
<a target="_top" href="https://github.com/${process.env.GITHUB_USERNAME}/pwa-microservices-template/blob/master/cli.md">See complete CLI Docs here.</a>
|
|
973
961
|
|
|
974
962
|
`
|
|
975
963
|
).replaceAll(oldVersion, newVersion),
|
|
@@ -977,6 +965,23 @@ const buildCliDoc = (program, oldVersion, newVersion) => {
|
|
|
977
965
|
);
|
|
978
966
|
};
|
|
979
967
|
|
|
968
|
+
const getInstanceContext = async (options = { singleReplica, replicas, redirect: '' }) => {
|
|
969
|
+
const { singleReplica, replicas, redirect } = options;
|
|
970
|
+
|
|
971
|
+
if (singleReplica && replicas && replicas.length > 0)
|
|
972
|
+
return {
|
|
973
|
+
singleReplicaHost: true,
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
const redirectTarget = redirect
|
|
977
|
+
? redirect[redirect.length - 1] === '/'
|
|
978
|
+
? redirect.slice(0, -1)
|
|
979
|
+
: redirect
|
|
980
|
+
: undefined;
|
|
981
|
+
|
|
982
|
+
return { redirectTarget };
|
|
983
|
+
};
|
|
984
|
+
|
|
980
985
|
export {
|
|
981
986
|
Cmd,
|
|
982
987
|
Config,
|
|
@@ -992,14 +997,11 @@ export {
|
|
|
992
997
|
buildWsSrc,
|
|
993
998
|
cloneSrcComponents,
|
|
994
999
|
buildProxyRouter,
|
|
995
|
-
cliBar,
|
|
996
|
-
cliSpinner,
|
|
997
1000
|
getDataDeploy,
|
|
998
1001
|
validateTemplatePath,
|
|
999
1002
|
buildReplicaId,
|
|
1000
1003
|
getCronBackUpFolder,
|
|
1001
1004
|
mergeFile,
|
|
1002
|
-
getDeployId,
|
|
1003
1005
|
getPathsSSR,
|
|
1004
1006
|
buildKindPorts,
|
|
1005
1007
|
buildPortProxyRouter,
|
|
@@ -1012,4 +1014,5 @@ export {
|
|
|
1012
1014
|
awaitDeployMonitor,
|
|
1013
1015
|
rebuildConfFactory,
|
|
1014
1016
|
buildCliDoc,
|
|
1017
|
+
getInstanceContext,
|
|
1015
1018
|
};
|
package/src/server/process.js
CHANGED
|
@@ -5,6 +5,7 @@ import dotenv from 'dotenv';
|
|
|
5
5
|
import fs from 'fs-extra';
|
|
6
6
|
import { loggerFactory } from './logger.js';
|
|
7
7
|
import clipboard from 'clipboardy';
|
|
8
|
+
import UnderpostRootEnv from '../cli/env.js';
|
|
8
9
|
|
|
9
10
|
dotenv.config();
|
|
10
11
|
|
|
@@ -47,7 +48,7 @@ const ProcessController = {
|
|
|
47
48
|
this.logger.info(`process on exit`, args);
|
|
48
49
|
});
|
|
49
50
|
this.onSigListen();
|
|
50
|
-
|
|
51
|
+
UnderpostRootEnv.API.delete('await-deploy');
|
|
51
52
|
},
|
|
52
53
|
};
|
|
53
54
|
|
package/src/server/proxy.js
CHANGED
|
@@ -55,7 +55,7 @@ const buildProxy = async () => {
|
|
|
55
55
|
// '^/target-path': '/',
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
|
-
|
|
58
|
+
options.router = buildPortProxyRouter(port, proxyRouter);
|
|
59
59
|
|
|
60
60
|
const filter = false
|
|
61
61
|
? (pathname, req) => {
|