underpost 2.8.1 → 2.8.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.dockerignore +1 -0
  2. package/.github/workflows/ghpkg.yml +14 -11
  3. package/.github/workflows/pwa-microservices-template.page.yml +10 -3
  4. package/.vscode/extensions.json +17 -71
  5. package/.vscode/settings.json +10 -4
  6. package/AUTHORS.md +16 -5
  7. package/CHANGELOG.md +63 -3
  8. package/Dockerfile +41 -62
  9. package/README.md +1 -28
  10. package/bin/build.js +278 -0
  11. package/bin/db.js +2 -24
  12. package/bin/deploy.js +105 -55
  13. package/bin/file.js +33 -4
  14. package/bin/index.js +33 -51
  15. package/bin/ssl.js +19 -11
  16. package/bin/util.js +9 -89
  17. package/bin/vs.js +25 -2
  18. package/conf.js +31 -138
  19. package/docker-compose.yml +1 -1
  20. package/manifests/core/kustomization.yaml +11 -0
  21. package/manifests/core/underpost-engine-backup-access.yaml +16 -0
  22. package/manifests/core/underpost-engine-backup-pv-pvc.yaml +22 -0
  23. package/manifests/core/underpost-engine-headless-service.yaml +10 -0
  24. package/manifests/core/underpost-engine-mongodb-backup-cronjob.yaml +40 -0
  25. package/manifests/core/underpost-engine-mongodb-configmap.yaml +26 -0
  26. package/manifests/core/underpost-engine-pv-pvc.yaml +23 -0
  27. package/manifests/core/underpost-engine-statefulset.yaml +91 -0
  28. package/manifests/deployment/mongo-express.yaml +60 -0
  29. package/manifests/deployment/phpmyadmin.yaml +54 -0
  30. package/manifests/kind-config.yaml +12 -0
  31. package/manifests/letsencrypt-prod.yaml +15 -0
  32. package/manifests/mariadb/config.yaml +10 -0
  33. package/manifests/mariadb/kustomization.yaml +9 -0
  34. package/manifests/mariadb/pv.yaml +12 -0
  35. package/manifests/mariadb/pvc.yaml +10 -0
  36. package/manifests/mariadb/secret.yaml +8 -0
  37. package/manifests/mariadb/service.yaml +10 -0
  38. package/manifests/mariadb/statefulset.yaml +55 -0
  39. package/manifests/valkey/kustomization.yaml +7 -0
  40. package/manifests/valkey/underpost-engine-valkey-service.yaml +17 -0
  41. package/manifests/valkey/underpost-engine-valkey-statefulset.yaml +39 -0
  42. package/package.json +115 -136
  43. package/src/api/user/user.model.js +16 -3
  44. package/src/api/user/user.service.js +1 -1
  45. package/src/client/components/core/CalendarCore.js +115 -49
  46. package/src/client/components/core/CommonJs.js +150 -19
  47. package/src/client/components/core/CssCore.js +6 -0
  48. package/src/client/components/core/DropDown.js +5 -1
  49. package/src/client/components/core/Input.js +17 -3
  50. package/src/client/components/core/Modal.js +10 -5
  51. package/src/client/components/core/Panel.js +84 -25
  52. package/src/client/components/core/PanelForm.js +4 -18
  53. package/src/client/components/core/Translate.js +43 -9
  54. package/src/client/components/core/Validator.js +9 -1
  55. package/src/client/services/default/default.management.js +4 -2
  56. package/src/db/mongo/MongooseDB.js +13 -1
  57. package/src/index.js +8 -1
  58. package/src/runtime/lampp/Lampp.js +1 -13
  59. package/src/runtime/xampp/Xampp.js +0 -13
  60. package/src/server/auth.js +3 -3
  61. package/src/server/client-build.js +3 -13
  62. package/src/server/conf.js +296 -29
  63. package/src/server/dns.js +2 -3
  64. package/src/server/logger.js +10 -5
  65. package/src/server/network.js +0 -36
  66. package/src/server/process.js +25 -2
  67. package/src/server/project.js +39 -0
  68. package/src/server/proxy.js +4 -26
  69. package/src/server/runtime.js +6 -7
  70. package/src/server/ssl.js +1 -1
  71. package/src/server/valkey.js +2 -0
  72. package/startup.cjs +12 -0
  73. package/src/server/prompt-optimizer.js +0 -28
  74. package/startup.js +0 -11
package/bin/build.js ADDED
@@ -0,0 +1,278 @@
1
+ import fs from 'fs-extra';
2
+ import { loggerFactory } from '../src/server/logger.js';
3
+ import { shellExec } from '../src/server/process.js';
4
+ import dotenv from 'dotenv';
5
+ import { getCapVariableName } from '../src/client/components/core/CommonJs.js';
6
+ import { buildProxyRouter, buildPortProxyRouter, Config, getPathsSSR, buildKindPorts } from '../src/server/conf.js';
7
+
8
+ const baseConfPath = './engine-private/conf/dd-cron/.env.production';
9
+ if (fs.existsSync(baseConfPath)) dotenv.config({ path: baseConfPath, override: true });
10
+
11
+ const logger = loggerFactory(import.meta);
12
+
13
+ // (async () => {
14
+ // return;
15
+ // const files = await fs.readdir(`./src`);
16
+ // for (const relativePath of files) {
17
+ // }
18
+ // })();
19
+
20
+ const confName = process.argv[2];
21
+ const basePath = '../pwa-microservices-template';
22
+ const repoName = `engine-${confName.split('dd-')[1]}-private`;
23
+ const repoNameBackUp = `engine-${confName.split('dd-')[1]}-cron-backups`;
24
+ const gitUrl = `https://${process.env.GITHUB_TOKEN}@github.com/underpostnet/${repoName}.git`;
25
+ const gitBackUpUrl = `https://${process.env.GITHUB_TOKEN}@github.com/underpostnet/${repoNameBackUp}.git`;
26
+
27
+ logger.info('', {
28
+ confName,
29
+ // gitUrl,
30
+ repoName,
31
+ repoNameBackUp,
32
+ basePath,
33
+ });
34
+
35
+ if (process.argv.includes('info')) process.exit(0);
36
+
37
+ if (process.argv.includes('proxy')) {
38
+ const env = process.argv.includes('development') ? 'development' : 'production';
39
+ process.env.NODE_ENV = env;
40
+ process.env.PORT = process.env.NODE_ENV === 'development' ? 4000 : 3000;
41
+ process.argv[2] = 'proxy';
42
+ process.argv[3] = fs.readFileSync('./engine-private/deploy/dd-router', 'utf8').trim();
43
+
44
+ await Config.build();
45
+ process.env.NODE_ENV = 'production';
46
+ const router = buildPortProxyRouter(443, buildProxyRouter());
47
+ const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.server.json`, 'utf8'));
48
+ const confHosts = Object.keys(confServer);
49
+
50
+ for (const host of Object.keys(router)) {
51
+ if (!confHosts.find((_host) => host.match(_host))) {
52
+ delete router[host];
53
+ }
54
+ }
55
+
56
+ const ports = Object.values(router).map((p) => p.split(':')[2]);
57
+
58
+ const fromPort = ports[0];
59
+ const toPort = ports[ports.length - 1];
60
+
61
+ logger.info('port range', { fromPort, toPort, router });
62
+
63
+ const deploymentYamlFilePath = `./engine-private/conf/${confName}/build/${env}/deployment.yaml`;
64
+
65
+ const deploymentYamlParts = fs.readFileSync(deploymentYamlFilePath, 'utf8').split('ports:');
66
+ deploymentYamlParts[1] =
67
+ buildKindPorts(fromPort, toPort) +
68
+ ` type: LoadBalancer
69
+ `;
70
+
71
+ fs.writeFileSync(
72
+ deploymentYamlFilePath,
73
+ deploymentYamlParts.join(`ports:
74
+ `),
75
+ );
76
+
77
+ let proxyYaml = '';
78
+ let secretYaml = '';
79
+
80
+ for (const host of Object.keys(confServer)) {
81
+ if (env === 'production')
82
+ secretYaml += `
83
+ ---
84
+ apiVersion: cert-manager.io/v1
85
+ kind: Certificate
86
+ metadata:
87
+ name: ${host}
88
+ spec:
89
+ commonName: ${host}
90
+ dnsNames:
91
+ - ${host}
92
+ issuerRef:
93
+ name: letsencrypt-prod
94
+ kind: ClusterIssuer
95
+ secretName: ${host}`;
96
+
97
+ const pathPortConditions = [];
98
+ for (const path of Object.keys(confServer[host])) {
99
+ const { peer } = confServer[host][path];
100
+ const port = parseInt(router[`${host}${path === '/' ? '' : path}`].split(':')[2]);
101
+ // logger.info('', { host, port, path });
102
+ pathPortConditions.push({
103
+ port,
104
+ path,
105
+ });
106
+
107
+ if (peer) {
108
+ // logger.info('', { host, port: port + 1, path: '/peer' });
109
+ pathPortConditions.push({
110
+ port: port + 1,
111
+ path: '/peer',
112
+ });
113
+ }
114
+ }
115
+ // logger.info('', { host, pathPortConditions });
116
+ proxyYaml += `
117
+ ---
118
+ apiVersion: projectcontour.io/v1
119
+ kind: HTTPProxy
120
+ metadata:
121
+ name: ${host}
122
+ spec:
123
+ virtualhost:
124
+ fqdn: ${host}${
125
+ env === 'development'
126
+ ? ''
127
+ : `
128
+ tls:
129
+ secretName: ${host}`
130
+ }
131
+ routes:`;
132
+ for (const conditionObj of pathPortConditions) {
133
+ const { path, port } = conditionObj;
134
+ proxyYaml += `
135
+ - conditions:
136
+ - prefix: ${path}
137
+ enableWebsockets: true
138
+ services:
139
+ - name: ${confName}-${env}-service
140
+ port: ${port}`;
141
+ }
142
+ }
143
+ const yamlPath = `./engine-private/conf/${confName}/build/${env}/proxy.yaml`;
144
+ fs.writeFileSync(yamlPath, proxyYaml, 'utf8');
145
+ if (env === 'production') {
146
+ const yamlPath = `./engine-private/conf/${confName}/build/${env}/secret.yaml`;
147
+ fs.writeFileSync(yamlPath, secretYaml, 'utf8');
148
+ }
149
+
150
+ process.exit(0);
151
+ }
152
+ if (process.argv.includes('conf')) {
153
+ if (!fs.existsSync(`../${repoName}`)) {
154
+ shellExec(`cd .. && git clone ${gitUrl}`, { silent: true });
155
+ } else {
156
+ shellExec(`cd ../${repoName} && git pull`);
157
+ }
158
+ const toPath = `../${repoName}/conf/${confName}`;
159
+ fs.removeSync(toPath);
160
+ fs.mkdirSync(toPath, { recursive: true });
161
+ fs.copySync(`./engine-private/conf/${confName}`, toPath);
162
+ shellExec(
163
+ `cd ../${repoName}` +
164
+ ` && git add .` +
165
+ ` && git commit -m "ci(engine-core-conf): ⚙️ Update ${confName} conf"` +
166
+ ` && git push`,
167
+ );
168
+ process.exit(0);
169
+ }
170
+
171
+ if (process.argv.includes('cron-backups')) {
172
+ if (!fs.existsSync(`../${repoNameBackUp}`)) {
173
+ shellExec(`cd .. && git clone ${gitBackUpUrl}`, { silent: true });
174
+ } else {
175
+ shellExec(`cd ../${repoNameBackUp} && git pull`);
176
+ }
177
+ const serverConf = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.server.json`, 'utf8'));
178
+ for (const host of Object.keys(serverConf)) {
179
+ for (let path of Object.keys(serverConf[host])) {
180
+ path = path.replaceAll('/', '-');
181
+ const toPath = `../${repoNameBackUp}/${host}${path}`;
182
+ const fromPath = `./engine-private/cron-backups/${host}${path}`;
183
+ if (fs.existsSync(fromPath)) {
184
+ if (fs.existsSync(toPath)) fs.removeSync(toPath);
185
+ logger.info('Build', { fromPath, toPath });
186
+ fs.copySync(fromPath, toPath);
187
+ }
188
+ }
189
+ }
190
+ shellExec(
191
+ `cd ../${repoNameBackUp}` +
192
+ ` && git add .` +
193
+ ` && git commit -m "ci(engine-core-cron-backups): ⚙️ Update ${confName} cron backups"` +
194
+ ` && git push`,
195
+ );
196
+ process.exit(0);
197
+ }
198
+
199
+ if (process.argv.includes('test')) {
200
+ fs.mkdirSync(`${basePath}/engine-private/conf`, { recursive: true });
201
+ fs.copySync(`./engine-private/conf/${confName}`, `${basePath}/engine-private/conf/${confName}`);
202
+ }
203
+
204
+ const { DefaultConf } = await import(`../conf.${confName}.js`);
205
+
206
+ {
207
+ for (const host of Object.keys(DefaultConf.server)) {
208
+ for (const path of Object.keys(DefaultConf.server[host])) {
209
+ const { apis, ws } = DefaultConf.server[host][path];
210
+ if (apis)
211
+ for (const api of apis) {
212
+ {
213
+ const originPath = `./src/api/${api}`;
214
+ logger.info(`Build`, originPath);
215
+ fs.copySync(originPath, `${basePath}/src/api/${api}`);
216
+ }
217
+ {
218
+ const originPath = `./src/client/services/${api}`;
219
+ logger.info(`Build`, originPath);
220
+ fs.copySync(originPath, `${basePath}/src/client/services/${api}`);
221
+ }
222
+ }
223
+
224
+ if (ws && ws !== 'core' && ws !== 'default') {
225
+ fs.copySync(`./src/ws/${ws}`, `${basePath}/src/ws/${ws}`);
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+ {
232
+ for (const client of Object.keys(DefaultConf.client)) {
233
+ const capName = getCapVariableName(client);
234
+ for (const component of Object.keys(DefaultConf.client[client].components)) {
235
+ const originPath = `./src/client/components/${component}`;
236
+ if (fs.existsSync(originPath)) {
237
+ logger.info(`Build`, originPath);
238
+ fs.copySync(originPath, `${basePath}/src/client/components/${component}`);
239
+ }
240
+ }
241
+ {
242
+ const originPath = `./src/client/${capName}.index.js`;
243
+ if (fs.existsSync(originPath)) {
244
+ logger.info(`Build`, originPath);
245
+ fs.copyFileSync(originPath, `${basePath}/src/client/${capName}.index.js`);
246
+ }
247
+ }
248
+ {
249
+ const originPath = `./src/client/public/${client}`;
250
+ if (fs.existsSync(originPath)) {
251
+ logger.info(`Build`, originPath);
252
+ fs.copySync(originPath, `${basePath}/src/client/public/${client}`);
253
+ }
254
+ }
255
+ }
256
+ }
257
+
258
+ {
259
+ for (const client of Object.keys(DefaultConf.ssr)) {
260
+ const ssrPaths = getPathsSSR(DefaultConf.ssr[client]);
261
+ for (const originPath of ssrPaths) {
262
+ if (fs.existsSync(originPath)) {
263
+ logger.info(`Build`, originPath);
264
+ fs.copySync(originPath, `${basePath}/${originPath}`);
265
+ }
266
+ }
267
+ }
268
+
269
+ fs.copyFileSync(`./conf.${confName}.js`, `${basePath}/conf.js`);
270
+ fs.copyFileSync(
271
+ `./.github/workflows/engine.${confName.split('dd-')[1]}.ci.yml`,
272
+ `${basePath}/.github/workflows/engine.${confName.split('dd-')[1]}.ci.yml`,
273
+ );
274
+
275
+ const packageJson = JSON.parse(fs.readFileSync(`${basePath}/package.json`, 'utf8'));
276
+ packageJson.name = repoName;
277
+ fs.writeFileSync(`${basePath}/package.json`, JSON.stringify(packageJson, null, 4), 'utf8');
278
+ }
package/bin/db.js CHANGED
@@ -4,10 +4,9 @@ import { loggerFactory } from '../src/server/logger.js';
4
4
  import { MariaDB } from '../src/db/mariadb/MariaDB.js';
5
5
  import { Xampp } from '../src/runtime/xampp/Xampp.js';
6
6
  import { Lampp } from '../src/runtime/lampp/Lampp.js';
7
- import { getCapVariableName, getRestoreCronCmd, loadConf } from '../src/server/conf.js';
7
+ import { getCapVariableName, getRestoreCronCmd, loadConf, splitFileFactory } from '../src/server/conf.js';
8
8
  import { DataBaseProvider } from '../src/db/DataBaseProvider.js';
9
9
  import { hashPassword } from '../src/server/auth.js';
10
- import splitFile from 'split-file';
11
10
 
12
11
  const logger = loggerFactory(import.meta);
13
12
 
@@ -101,28 +100,7 @@ try {
101
100
 
102
101
  cmd = `mysqldump -u ${user} -p${password} ${name} > ${cmdBackupPath}`;
103
102
  shellExec(cmd);
104
- const stats = fs.statSync(cmdBackupPath);
105
- const maxSizeInBytes = 1024 * 1024 * 50; // 50 mb
106
- const fileSizeInBytes = stats.size;
107
- if (fileSizeInBytes > maxSizeInBytes) {
108
- await new Promise((resolve) => {
109
- splitFile
110
- .splitFileBySize(cmdBackupPath, maxSizeInBytes) // 50 mb
111
- .then((names) => {
112
- fs.writeFileSync(
113
- `${cmdBackupPath.split('/').slice(0, -1).join('/')}/${name}-parths.json`,
114
- JSON.stringify(names, null, 4),
115
- 'utf8',
116
- );
117
- resolve();
118
- })
119
- .catch((err) => {
120
- console.log('Error: ', err);
121
- resolve();
122
- });
123
- });
124
- fs.removeSync(cmdBackupPath);
125
- }
103
+ await splitFileFactory(name, cmdBackupPath);
126
104
  }
127
105
  break;
128
106
  case 'import':
package/bin/deploy.js CHANGED
@@ -4,7 +4,7 @@ import axios from 'axios';
4
4
  import dotenv from 'dotenv';
5
5
  import plantuml from 'plantuml';
6
6
 
7
- import { shellCd, shellExec } from '../src/server/process.js';
7
+ import { pbcopy, shellCd, shellExec } from '../src/server/process.js';
8
8
  import { loggerFactory } from '../src/server/logger.js';
9
9
  import {
10
10
  Config,
@@ -29,7 +29,6 @@ import {
29
29
  } from '../src/server/conf.js';
30
30
  import { buildClient } from '../src/server/client-build.js';
31
31
  import { range, setPad, timer, uniqueArray } from '../src/client/components/core/CommonJs.js';
32
- import simpleGit from 'simple-git';
33
32
  import { MongooseDB } from '../src/db/mongo/MongooseDB.js';
34
33
  import { Lampp } from '../src/runtime/lampp/Lampp.js';
35
34
  import { DefaultConf } from '../conf.js';
@@ -139,8 +138,7 @@ try {
139
138
  }
140
139
  break;
141
140
  case 'conf': {
142
- loadConf(process.argv[3]);
143
- if (process.argv[4]) fs.writeFileSync(`.env`, fs.readFileSync(`.env.${process.argv[4]}`, 'utf8'), 'utf8');
141
+ loadConf(process.argv[3], process.argv[4]);
144
142
  break;
145
143
  }
146
144
  case 'run':
@@ -307,7 +305,7 @@ try {
307
305
  }
308
306
 
309
307
  case 'adminer': {
310
- const directory = '/dd/engine/public/adminer';
308
+ const directory = '/home/dd/engine/public/adminer';
311
309
  // const host = '127.0.0.1';
312
310
  const host = 'localhost';
313
311
  const port = 80;
@@ -337,7 +335,7 @@ try {
337
335
 
338
336
  case 'pma':
339
337
  {
340
- const directory = '/dd/engine/public/phpmyadmin';
338
+ const directory = '/home/dd/engine/public/phpmyadmin';
341
339
  // const host = '127.0.0.1';
342
340
  const host = 'localhost';
343
341
  const port = 80;
@@ -454,14 +452,16 @@ try {
454
452
  }
455
453
  break;
456
454
 
457
- case 'update-package':
455
+ case 'update-dependencies':
458
456
  const files = await fs.readdir(`./engine-private/conf`, { recursive: true });
459
457
  const originPackage = JSON.parse(fs.readFileSync(`./package.json`, 'utf8'));
460
458
  for (const relativePath of files) {
461
459
  const filePah = `./engine-private/conf/${relativePath.replaceAll(`\\`, '/')}`;
462
460
  if (filePah.split('/').pop() === 'package.json') {
463
- originPackage.scripts.start = JSON.parse(fs.readFileSync(filePah), 'utf8').scripts.start;
464
- fs.writeFileSync(filePah, JSON.stringify(originPackage, null, 4), 'utf8');
461
+ const deployPackage = JSON.parse(fs.readFileSync(filePah), 'utf8');
462
+ deployPackage.dependencies = originPackage.dependencies;
463
+ deployPackage.devDependencies = originPackage.devDependencies;
464
+ fs.writeFileSync(filePah, JSON.stringify(deployPackage, null, 4), 'utf8');
465
465
  }
466
466
  }
467
467
  break;
@@ -731,6 +731,16 @@ try {
731
731
  originPackage.version = newVersion;
732
732
  fs.writeFileSync(filePah, JSON.stringify(originPackage, null, 4), 'utf8');
733
733
  }
734
+ if (filePah.split('/').pop() === 'deployment.yaml') {
735
+ fs.writeFileSync(
736
+ filePah,
737
+ fs
738
+ .readFileSync(filePah, 'utf8')
739
+ .replaceAll(`v${version}`, `v${newVersion}`)
740
+ .replaceAll(`engine.version: ${version}`, `engine.version: ${newVersion}`),
741
+ 'utf8',
742
+ );
743
+ }
734
744
  }
735
745
  }
736
746
 
@@ -757,41 +767,32 @@ try {
757
767
  'utf8',
758
768
  );
759
769
 
760
- shellExec(`node bin/deploy update-package`);
770
+ shellExec(`node bin/deploy update-dependencies`);
761
771
  shellExec(`auto-changelog`);
762
772
  }
763
773
  break;
764
774
 
765
775
  case 'update-authors': {
766
- // shellExec(`git log --reverse --format='%aN (<%aE>)' | sort -u`, { stdout: true });
767
- const logs = await simpleGit().log();
768
-
776
+ // #### Ordered by first contribution.
769
777
  fs.writeFileSync(
770
778
  './AUTHORS.md',
771
779
  `# Authors
772
780
 
773
- #### Ordered by first contribution.
774
781
 
775
- ${uniqueArray(logs.all.map((log) => `- ${log.author_name} ([${log.author_email}](mailto:${log.author_email}))`)).join(`
776
- `)}
782
+ ${shellExec(`git log | grep Author: | sort -u`, { stdout: true }).split(`\n`).join(`\n\n\n`)}
777
783
 
778
784
  #### Generated by [underpost.net](https://underpost.net)`,
779
785
  'utf8',
780
786
  );
781
787
 
782
- // hash: '1c7418ad2f49c7798a6d28d370b34c69d31dce46',
783
- // date: '2024-09-16T17:10:13-03:00',
784
- // message: 'update',
785
- // refs: '',
786
- // body: '',
787
- // author_name: 'fcoverdugo',
788
- // author_email: 'fcoverdugoa@underpost.net'
788
+ break;
789
789
  }
790
790
 
791
791
  case 'restore-macro-db':
792
792
  {
793
793
  const deployGroupId = process.argv[3];
794
- await restoreMacroDb(deployGroupId);
794
+ const deployId = process.argv[4];
795
+ await restoreMacroDb(deployGroupId, deployId);
795
796
  }
796
797
 
797
798
  break;
@@ -826,10 +827,10 @@ ${uniqueArray(logs.all.map((log) => `- ${log.author_name} ([${log.author_email}]
826
827
  shellExec(`bin/besu --help`);
827
828
 
828
829
  // Set env path
829
- // export PATH=$PATH:/dd/besu-24.9.1/bin
830
+ // export PATH=$PATH:/home/dd/besu-24.9.1/bin
830
831
 
831
832
  // Open src
832
- // shellExec(`sudo code /dd/besu-24.9.1 --user-data-dir="/root/.vscode-root" --no-sandbox`);
833
+ // shellExec(`sudo code /home/dd/besu-24.9.1 --user-data-dir="/root/.vscode-root" --no-sandbox`);
833
834
  }
834
835
 
835
836
  break;
@@ -847,23 +848,43 @@ ${uniqueArray(logs.all.map((log) => `- ${log.author_name} ([${log.author_email}]
847
848
  }
848
849
 
849
850
  case 'update-default-conf': {
850
- const host = process.argv[3] ? process.argv[3] : 'underpostnet.github.io';
851
- const path = process.argv[4] ? process.argv[4] : '/pwa-microservices-template-ghpkg';
852
- DefaultConf.server = {
853
- [host]: { [path]: DefaultConf.server['default.net']['/'] },
854
- };
855
- DefaultConf.server[host][path].apiBaseProxyPath = '/';
856
- DefaultConf.server[host][path].apiBaseHost = 'www.nexodev.org';
857
- fs.writeFileSync(
858
- './conf.js',
859
- `
860
- const DefaultConf = ${JSONweb(DefaultConf)};
861
-
862
- export { DefaultConf }
863
-
864
- `,
865
- 'utf8',
866
- );
851
+ const defaultServer = DefaultConf.server['default.net']['/'];
852
+ let confName = process.argv[3];
853
+ if (confName === 'ghpkg') {
854
+ confName = undefined;
855
+ const host = 'underpostnet.github.io';
856
+ const path = '/pwa-microservices-template-ghpkg';
857
+ DefaultConf.server = {
858
+ [host]: { [path]: defaultServer },
859
+ };
860
+ DefaultConf.server[host][path].apiBaseProxyPath = '/';
861
+ DefaultConf.server[host][path].apiBaseHost = 'www.nexodev.org';
862
+ } else if (confName) {
863
+ DefaultConf.client = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.client.json`, 'utf8'));
864
+ DefaultConf.server = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.server.json`, 'utf8'));
865
+ DefaultConf.ssr = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.ssr.json`, 'utf8'));
866
+ DefaultConf.cron = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.cron.json`, 'utf8'));
867
+
868
+ for (const host of Object.keys(DefaultConf.server)) {
869
+ for (const path of Object.keys(DefaultConf.server[host])) {
870
+ DefaultConf.server[host][path].db = defaultServer.db;
871
+ DefaultConf.server[host][path].mailer = defaultServer.mailer;
872
+
873
+ delete DefaultConf.server[host][path]._wp_client;
874
+ delete DefaultConf.server[host][path]._wp_git;
875
+ delete DefaultConf.server[host][path]._wp_directory;
876
+ delete DefaultConf.server[host][path].wp;
877
+ delete DefaultConf.server[host][path].git;
878
+ delete DefaultConf.server[host][path].directory;
879
+ }
880
+ }
881
+ }
882
+ const sepRender = '/**/';
883
+ const confRawPaths = fs.readFileSync('./conf.js', 'utf8').split(sepRender);
884
+ confRawPaths[1] = `${JSON.stringify(DefaultConf)};`;
885
+ const targetConfPath = `./conf${confName ? `.${confName}` : ''}.js`;
886
+ fs.writeFileSync(targetConfPath, confRawPaths.join(sepRender), 'utf8');
887
+ shellExec(`prettier --write ${targetConfPath}`);
867
888
 
868
889
  break;
869
890
  }
@@ -879,7 +900,11 @@ ${uniqueArray(logs.all.map((log) => `- ${log.author_name} ([${log.author_email}]
879
900
  }
880
901
  case 'ssh-import-client-keys': {
881
902
  const host = process.argv[3];
882
- shellExec(`node bin/deploy set-ssh-keys ./engine-private/deploy/ssh_host_rsa_key${host ? ` ${host}` : ``} clean`);
903
+ shellExec(
904
+ `node bin/deploy set-ssh-keys ./engine-private/deploy/ssh_host_rsa_key ${host ? ` ${host}` : ``} ${
905
+ process.argv.includes('clean') ? 'clean' : ''
906
+ }`,
907
+ );
883
908
  break;
884
909
  }
885
910
  case 'ssh-keys': {
@@ -944,14 +969,24 @@ ${uniqueArray(logs.all.map((log) => `- ${log.author_name} ([${log.author_email}]
944
969
  }
945
970
 
946
971
  case 'ssh': {
947
- if (!process.argv.includes('server')) {
948
- shellExec(`sudo apt update`);
949
- shellExec(`sudo apt install openssh-server -y`);
950
- shellExec(`sudo apt install ssh-askpass`);
972
+ if (process.argv.includes('rocky')) {
973
+ shellExec(`sudo systemctl enable sshd`);
974
+
975
+ shellExec(`sudo systemctl start sshd`);
976
+
977
+ shellExec(`sudo systemctl status sshd`);
978
+
979
+ shellExec(`sudo ss -lt`);
980
+ } else {
981
+ if (!process.argv.includes('server')) {
982
+ shellExec(`sudo apt update`);
983
+ shellExec(`sudo apt install openssh-server -y`);
984
+ shellExec(`sudo apt install ssh-askpass`);
985
+ }
986
+ shellExec(`sudo systemctl enable ssh`);
987
+ shellExec(`sudo systemctl restart ssh`);
988
+ shellExec(`sudo systemctl status ssh`);
951
989
  }
952
- shellExec(`sudo systemctl enable ssh`);
953
- shellExec(`sudo systemctl restart ssh`);
954
- shellExec(`sudo systemctl status ssh`);
955
990
  // sudo service ssh restart
956
991
  shellExec(`ip a`);
957
992
 
@@ -1009,11 +1044,26 @@ ${uniqueArray(logs.all.map((log) => `- ${log.author_name} ([${log.author_email}]
1009
1044
 
1010
1045
  case 'valkey': {
1011
1046
  if (!process.argv.includes('server')) {
1012
- shellExec(`cd /dd && git clone https://github.com/valkey-io/valkey.git`);
1013
- shellExec(`cd /dd/valkey && make`);
1014
- shellExec(`apt install valkey-tools`); // valkey-cli
1047
+ if (process.argv.includes('rocky')) {
1048
+ // shellExec(`yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm`);
1049
+ // shellExec(`sudo percona-release enable valkey experimental`);
1050
+ shellExec(`sudo dnf install valkey`);
1051
+ shellExec(`chown -R valkey:valkey /etc/valkey`);
1052
+ shellExec(`chown -R valkey:valkey /var/lib/valkey`);
1053
+ shellExec(`chown -R valkey:valkey /var/log/valkey`);
1054
+ shellExec(`sudo systemctl enable valkey.service`);
1055
+ shellExec(`sudo systemctl start valkey`);
1056
+ shellExec(`valkey-cli ping`);
1057
+ } else {
1058
+ shellExec(`cd /home/dd && git clone https://github.com/valkey-io/valkey.git`);
1059
+ shellExec(`cd /home/dd/valkey && make`);
1060
+ shellExec(`apt install valkey-tools`); // valkey-cli
1061
+ }
1015
1062
  }
1016
- shellExec(`cd /dd/valkey && ./src/valkey-server`);
1063
+ if (process.argv.includes('rocky')) {
1064
+ shellExec(`sudo systemctl stop valkey`);
1065
+ shellExec(`sudo systemctl start valkey`);
1066
+ } else shellExec(`cd /home/dd/valkey && ./src/valkey-server`);
1017
1067
 
1018
1068
  break;
1019
1069
  }
package/bin/file.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
 
3
3
  import { loggerFactory } from '../src/server/logger.js';
4
- import { cap, getCapVariableName, getDirname } from '../src/client/components/core/CommonJs.js';
4
+ import { cap, getCapVariableName, getDirname, newInstance } from '../src/client/components/core/CommonJs.js';
5
5
  import { shellCd, shellExec } from '../src/server/process.js';
6
6
  import walk from 'ignore-walk';
7
7
  import { validateTemplatePath } from '../src/server/conf.js';
@@ -78,7 +78,7 @@ try {
78
78
  fs.copySync(`./src/client/public/default`, `../pwa-microservices-template/src/client/public/default`);
79
79
 
80
80
  shellCd('../pwa-microservices-template');
81
- for (const deletePath of ['CHANGELOG.md', 'README.md', 'package-lock.json', 'package.json']) {
81
+ for (const deletePath of ['README.md', 'package-lock.json', 'package.json']) {
82
82
  shellExec(`git checkout ${deletePath}`);
83
83
  }
84
84
  for (const deletePath of [
@@ -86,13 +86,42 @@ try {
86
86
  '.github/workflows/docker-image.yml',
87
87
  '.github/workflows/deploy.ssh.yml',
88
88
  '.github/workflows/deploy.api-rest.yml',
89
+ '.github/workflows/engine.lampp.ci.yml',
90
+ '.github/workflows/engine.core.ci.yml',
91
+ '.github/workflows/engine.cyberia.ci.yml',
89
92
  'bin/web3.js',
90
93
  'bin/cyberia.js',
91
- 'src/ipfs.js',
92
- 'src/k8s.js',
93
94
  ]) {
94
95
  fs.removeSync('../pwa-microservices-template/' + deletePath);
95
96
  }
97
+ shellCd('../engine');
98
+ const originPackageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
99
+ const templatePackageJson = JSON.parse(fs.readFileSync('../pwa-microservices-template/package.json', 'utf8'));
100
+ templatePackageJson.dependencies = originPackageJson.dependencies;
101
+ templatePackageJson.devDependencies = originPackageJson.devDependencies;
102
+ templatePackageJson.version = originPackageJson.version;
103
+ fs.writeFileSync(
104
+ '../pwa-microservices-template/package.json',
105
+ JSON.stringify(templatePackageJson, null, 4),
106
+ 'utf8',
107
+ );
108
+
109
+ const originPackageLockJson = JSON.parse(fs.readFileSync('./package-lock.json', 'utf8'));
110
+ const templatePackageLockJson = JSON.parse(
111
+ fs.readFileSync('../pwa-microservices-template/package-lock.json', 'utf8'),
112
+ );
113
+ const originBasePackageLock = newInstance(templatePackageLockJson.packages['']);
114
+ templatePackageLockJson.version = originPackageLockJson.version;
115
+ templatePackageLockJson.packages = originPackageLockJson.packages;
116
+ templatePackageLockJson.packages[''].name = originBasePackageLock.name;
117
+ templatePackageLockJson.packages[''].version = originPackageLockJson.version;
118
+ templatePackageLockJson.packages[''].hasInstallScript = originBasePackageLock.hasInstallScript;
119
+ templatePackageLockJson.packages[''].license = originBasePackageLock.license;
120
+ fs.writeFileSync(
121
+ '../pwa-microservices-template/package-lock.json',
122
+ JSON.stringify(templatePackageLockJson, null, 4),
123
+ 'utf8',
124
+ );
96
125
  }
97
126
 
98
127
  break;