@underpostnet/underpost 2.8.4 → 2.8.5

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 (61) hide show
  1. package/.github/workflows/ghpkg.yml +13 -46
  2. package/.github/workflows/npmpkg.yml +67 -0
  3. package/.github/workflows/publish.yml +5 -5
  4. package/.github/workflows/pwa-microservices-template.page.yml +3 -2
  5. package/.github/workflows/pwa-microservices-template.test.yml +2 -2
  6. package/.vscode/settings.json +6 -1
  7. package/CHANGELOG.md +16 -0
  8. package/Dockerfile +6 -27
  9. package/bin/build.js +52 -169
  10. package/bin/deploy.js +6 -27
  11. package/bin/file.js +29 -15
  12. package/bin/index.js +158 -30
  13. package/bin/util.js +0 -8
  14. package/docker-compose.yml +1 -1
  15. package/manifests/mongodb/backup-access.yaml +16 -0
  16. package/manifests/mongodb/backup-cronjob.yaml +42 -0
  17. package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
  18. package/manifests/mongodb/configmap.yaml +26 -0
  19. package/manifests/mongodb/headless-service.yaml +10 -0
  20. package/manifests/mongodb/kustomization.yaml +11 -0
  21. package/manifests/mongodb/pv-pvc.yaml +23 -0
  22. package/manifests/mongodb/statefulset.yaml +125 -0
  23. package/manifests/valkey/kustomization.yaml +2 -2
  24. package/manifests/valkey/service.yaml +17 -0
  25. package/manifests/valkey/statefulset.yaml +39 -0
  26. package/package.json +21 -5
  27. package/src/api/core/core.service.js +1 -1
  28. package/src/cli/cluster.js +154 -0
  29. package/src/cli/cron.js +90 -0
  30. package/src/cli/db.js +148 -0
  31. package/src/cli/deploy.js +277 -0
  32. package/src/cli/env.js +52 -0
  33. package/src/cli/image.js +125 -0
  34. package/src/cli/repository.js +104 -0
  35. package/src/cli/script.js +29 -0
  36. package/src/cli/secrets.js +37 -0
  37. package/src/cli/test.js +83 -0
  38. package/src/client/components/core/Auth.js +22 -4
  39. package/src/client/components/core/CommonJs.js +82 -1
  40. package/src/client/components/core/Css.js +1 -0
  41. package/src/client/components/core/Input.js +1 -1
  42. package/src/client/components/core/Modal.js +0 -1
  43. package/src/client/components/core/Scroll.js +1 -0
  44. package/src/client/components/core/Translate.js +4 -0
  45. package/src/client/components/core/VanillaJs.js +0 -9
  46. package/src/client/components/core/Worker.js +34 -31
  47. package/src/client/ssr/body/CacheControl.js +2 -2
  48. package/src/index.js +77 -26
  49. package/src/server/backup.js +49 -93
  50. package/src/server/client-build.js +1 -10
  51. package/src/server/client-formatted.js +5 -3
  52. package/src/server/conf.js +68 -187
  53. package/src/server/dns.js +48 -65
  54. package/src/server/logger.js +7 -7
  55. package/src/server/network.js +17 -7
  56. package/src/server/runtime.js +8 -22
  57. package/src/dns.js +0 -22
  58. package/src/server/project.js +0 -39
  59. package/startup.cjs +0 -12
  60. /package/manifests/deployment/{mongo-express.yaml → mongo-express/deployment.yaml} +0 -0
  61. /package/manifests/deployment/{phpmyadmin.yaml → phpmyadmin/deployment.yaml} +0 -0
@@ -1,120 +1,76 @@
1
1
  import fs from 'fs-extra';
2
2
  import { loggerFactory } from './logger.js';
3
- import { shellCd, shellExec } from './process.js';
4
- import { getCronBackUpFolder, getDataDeploy } from './conf.js';
3
+ import { shellExec } from './process.js';
4
+ import { getCronBackUpFolder } from './conf.js';
5
5
  import dotenv from 'dotenv';
6
6
 
7
7
  dotenv.config();
8
8
 
9
9
  const logger = loggerFactory(import.meta);
10
10
 
11
- const BackUpManagement = {
12
- repoUrl: `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USERNAME}/${process.env.GITHUB_BACKUP_REPO}.git`,
13
- Init: async function ({ deployId }) {
14
- const Callback = async function () {
15
- const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
11
+ class BackUp {
12
+ static callback = async function (deployList, options = { disableKindCluster: false }) {
13
+ if ((!deployList || deployList === 'dd') && fs.existsSync(`./engine-private/deploy/dd.router`))
14
+ deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
16
15
 
17
- const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
16
+ logger.info('init backups callback', deployList);
17
+ await logger.setUpInfo();
18
+ const currentDate = new Date().getTime();
19
+ const maxBackupRetention = 5;
18
20
 
19
- const { backups } = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
21
+ if (!fs.existsSync('./engine-private/cron-backups'))
22
+ fs.mkdirSync('./engine-private/cron-backups', { recursive: true });
20
23
 
21
- if (!backups) return;
24
+ for (const _deployId of deployList.split(',')) {
25
+ const deployId = _deployId.trim();
26
+ if (!deployId) continue;
22
27
 
23
- logger.info('init backups callback');
24
- await logger.setUpInfo();
25
-
26
- const currentDate = new Date().getTime();
27
-
28
- if (!fs.existsSync('./engine-private/cron-backups'))
29
- fs.mkdirSync('./engine-private/cron-backups', { recursive: true });
30
-
31
- for (const deployGroupData of backups) {
32
- const { deployGroupId } = deployGroupData;
33
- const dataDeploy = getDataDeploy({ deployGroupId });
34
-
35
- for (const deployObj of dataDeploy) {
36
- const { deployId, replicaHost } = deployObj;
37
-
38
- if (replicaHost) continue;
39
-
40
- const confServer = JSON.parse(
41
- fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
42
- ? fs.readFileSync(`./engine-private/replica/${deployId}/conf.server.json`, 'utf8')
43
- : fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'),
44
- );
45
-
46
- for (const host of Object.keys(confServer))
47
- for (const path of Object.keys(confServer[host])) {
48
- // retention policy
49
- let { db, backupFrequency, maxBackupRetention, singleReplica, wp, git, directory } =
50
- confServer[host][path];
51
-
52
- if (!db || singleReplica) continue;
53
-
54
- if (!backupFrequency) backupFrequency = 'daily';
55
- if (!maxBackupRetention) maxBackupRetention = 5;
56
-
57
- const backUpPath = `${process.cwd()}/engine-private/cron-backups/${getCronBackUpFolder(host, path)}`;
58
- if (!fs.existsSync(backUpPath)) fs.mkdirSync(`${backUpPath}`, { recursive: true });
59
- // .isDirectory()
60
- const files = await fs.readdir(backUpPath, { withFileTypes: true });
61
-
62
- const currentBackupsDirs = files
63
- .map((fileObj) => parseInt(fileObj.name))
64
- .sort((a, b) => a - b)
65
- .reverse();
28
+ if (options.disableKindCluster !== true) {
29
+ shellExec(`underpost db --export ${deployId}`);
30
+ continue;
31
+ }
66
32
 
67
- switch (backupFrequency) {
68
- case 'daily':
33
+ const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'));
69
34
 
70
- default:
71
- // if (currentBackupsDirs[0] && currentDate - currentBackupsDirs[0] < 1000 * 60 * 60 * 24) continue;
72
- break;
73
- }
35
+ for (const host of Object.keys(confServer))
36
+ for (const path of Object.keys(confServer[host])) {
37
+ // retention policy
38
+ const { db } = confServer[host][path];
39
+ if (!db) continue;
40
+ logger.info('Init backup', { host, path, db });
74
41
 
75
- for (const retentionPath of currentBackupsDirs.filter((t, i) => i >= maxBackupRetention - 1)) {
76
- const removePathRetention = `${backUpPath}/${retentionPath}`;
77
- logger.info('Remove backup folder', removePathRetention);
78
- fs.removeSync(removePathRetention);
79
- }
42
+ const backUpPath = `${process.cwd()}/engine-private/cron-backups/${getCronBackUpFolder(host, path)}`;
43
+ if (!fs.existsSync(backUpPath)) fs.mkdirSync(`${backUpPath}`, { recursive: true });
44
+ // .isDirectory()
45
+ const files = await fs.readdir(backUpPath, { withFileTypes: true });
80
46
 
81
- fs.mkdirSync(`${backUpPath}/${currentDate}`, { recursive: true });
47
+ const currentBackupsDirs = files
48
+ .map((fileObj) => parseInt(fileObj.name))
49
+ .sort((a, b) => a - b)
50
+ .reverse();
82
51
 
83
- shellExec(`node bin/db ${host}${path} export ${deployId} ${backUpPath}/${currentDate}`);
52
+ for (const retentionPath of currentBackupsDirs.filter((t, i) => i >= maxBackupRetention - 1)) {
53
+ const removePathRetention = `${backUpPath}/${retentionPath}`;
54
+ logger.info('Remove backup folder', removePathRetention);
55
+ fs.removeSync(removePathRetention);
56
+ }
84
57
 
85
- if (wp) {
86
- const repoUrl = `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USERNAME}/${git
87
- .split('/')
88
- .pop()}.git`;
58
+ fs.mkdirSync(`${backUpPath}/${currentDate}`, { recursive: true });
89
59
 
90
- shellExec(
91
- `cd ${directory}` +
92
- ` && git pull ${repoUrl}` +
93
- ` && git add . && git commit -m "backup ${new Date().toLocaleDateString()}"` +
94
- ` && git push ${repoUrl}`,
95
- {
96
- disableLog: true,
97
- },
98
- );
99
- }
100
- }
60
+ shellExec(`node bin/db ${host}${path} export ${deployId} ${backUpPath}/${currentDate}`);
101
61
  }
102
- }
103
62
  shellExec(
104
63
  `cd ./engine-private/cron-backups` +
105
- ` && git pull ${BackUpManagement.repoUrl}` +
106
- ` && git add . && git commit -m "backup ${new Date().toLocaleDateString()}"` +
107
- ` && git push ${BackUpManagement.repoUrl}`,
64
+ ` && underpost pull . underpostnet/cron-backups` +
65
+ ` && git add .` +
66
+ ` && underpost cmt . backup cron-job '${new Date().toLocaleDateString()}'` +
67
+ ` && underpost push . underpostnet/cron-backups`,
108
68
  {
109
69
  disableLog: true,
110
70
  },
111
71
  );
112
- };
113
- await Callback();
114
- BackUpManagement.Callback = Callback;
115
- return Callback;
116
- },
117
- Callback: async function (params) {},
118
- };
72
+ }
73
+ };
74
+ }
119
75
 
120
- export { BackUpManagement };
76
+ export default BackUp;
@@ -191,8 +191,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
191
191
 
192
192
  if (redirect || disabledRebuild) continue;
193
193
 
194
- if (fullBuildEnabled) {
195
- // !(confServer[host]['/'] && confServer[host]['/'].liteBuild)
194
+ if (fullBuildEnabled)
196
195
  await fullBuild({
197
196
  path,
198
197
  logger,
@@ -205,14 +204,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
205
204
  iconsBuild,
206
205
  metadata,
207
206
  });
208
- if (apis && false)
209
- for (const apiBuildScript of apis) {
210
- const scriptPath = `src/api/${apiBuildScript}/${apiBuildScript}.build.js`;
211
- if (fs.existsSync(`./${scriptPath}`)) {
212
- shellExec(`node ${scriptPath}`);
213
- }
214
- }
215
- }
216
207
 
217
208
  if (components)
218
209
  for (const module of Object.keys(components)) {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import fs from 'fs-extra';
4
+ import vm from 'node:vm';
4
5
 
5
6
  const srcFormatted = (src) =>
6
7
  src
@@ -48,9 +49,10 @@ const viewFormatted = (src, dists, proxyPath, baseHost = '') => {
48
49
  };
49
50
 
50
51
  const ssrFactory = async (componentPath = `./src/client/ssr/Render.js`) => {
51
- let SrrComponent = () => {};
52
- eval(await srcFormatted(fs.readFileSync(componentPath, 'utf8')));
53
- return SrrComponent;
52
+ const context = { SrrComponent: () => {}, npm_package_version: process.env.npm_package_version };
53
+ vm.createContext(context);
54
+ vm.runInContext(await srcFormatted(fs.readFileSync(componentPath, 'utf8')), context);
55
+ return context.SrrComponent;
54
56
  };
55
57
 
56
58
  export { srcFormatted, JSONweb, componentFormatted, viewFormatted, ssrFactory };
@@ -13,8 +13,8 @@ import cliProgress from 'cli-progress';
13
13
  import cliSpinners from 'cli-spinners';
14
14
  import logUpdate from 'log-update';
15
15
  import colors from 'colors';
16
- import { actionInitLog, loggerFactory } from './logger.js';
17
- import { pbcopy, shellExec } from './process.js';
16
+ import { loggerFactory } from './logger.js';
17
+ import { shellExec } from './process.js';
18
18
  import { DefaultConf } from '../../conf.js';
19
19
  import read from 'read';
20
20
  import splitFile from 'split-file';
@@ -40,21 +40,26 @@ const logger = loggerFactory(import.meta);
40
40
 
41
41
  const Config = {
42
42
  default: DefaultConf,
43
- build: async function (options = { folder: '' }) {
43
+ build: async function (options = { folder: '' }, deployContext, deployList, subConf) {
44
+ if (!deployContext) deployContext = process.argv[2];
44
45
  if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
45
46
  fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
46
- if (fs.existsSync(`./engine-private/conf/${process.argv[2]}`)) return loadConf(process.argv[2]);
47
- if (fs.existsSync(`./engine-private/replica/${process.argv[2]}`)) return loadConf(process.argv[2]);
47
+ if (fs.existsSync(`./engine-private/conf/${deployContext}`))
48
+ return loadConf(deployContext, process.env.NODE_ENV, subConf);
49
+ if (fs.existsSync(`./engine-private/replica/${deployContext}`))
50
+ return loadConf(deployContext, process.env.NODE_ENV, subConf);
48
51
 
49
- if (process.argv[2] === 'deploy') return;
52
+ if (deployContext === 'deploy') return;
50
53
 
51
- if (process.argv[2] === 'proxy') {
54
+ if (deployContext === 'proxy') {
55
+ if (!deployList) deployList = process.argv[3];
56
+ if (!subConf) subConf = process.argv[4];
52
57
  this.default.server = {};
53
- for (const deployId of process.argv[3].split(',')) {
58
+ for (const deployId of deployList.split(',')) {
54
59
  let confPath = `./engine-private/conf/${deployId}/conf.server.json`;
55
60
  const privateConfDevPath = fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
56
61
  ? `./engine-private/replica/${deployId}/conf.server.json`
57
- : `./engine-private/conf/${deployId}/conf.server.dev.${process.argv[4]}.json`;
62
+ : `./engine-private/conf/${deployId}/conf.server.dev.${subConf}.json`;
58
63
  const confDevPath = fs.existsSync(privateConfDevPath)
59
64
  ? privateConfDevPath
60
65
  : `./engine-private/conf/${deployId}/conf.server.dev.json`;
@@ -62,7 +67,7 @@ const Config = {
62
67
  if (process.env.NODE_ENV === 'development' && fs.existsSync(confDevPath)) confPath = confDevPath;
63
68
  const serverConf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
64
69
 
65
- for (const host of Object.keys(loadReplicas(serverConf))) {
70
+ for (const host of Object.keys(loadReplicas(serverConf, deployContext, subConf))) {
66
71
  if (serverConf[host]['/'])
67
72
  this.default.server[host] = {
68
73
  ...this.default.server[host],
@@ -92,7 +97,15 @@ const Config = {
92
97
  },
93
98
  };
94
99
 
95
- const loadConf = (deployId, envInput) => {
100
+ const loadConf = (deployId, envInput, subConf) => {
101
+ if (deployId === 'clean') {
102
+ shellExec(`git checkout package.json`);
103
+ shellExec(`git checkout .env.production`);
104
+ shellExec(`git checkout .env.development`);
105
+ shellExec(`git checkout .env.test`);
106
+ shellExec(`git checkout jsdoc.json`);
107
+ return;
108
+ }
96
109
  const folder = fs.existsSync(`./engine-private/replica/${deployId}`)
97
110
  ? `./engine-private/replica/${deployId}`
98
111
  : `./engine-private/conf/${deployId}`;
@@ -109,7 +122,8 @@ const loadConf = (deployId, envInput) => {
109
122
  ? fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8')
110
123
  : JSON.stringify(Config.default[typeConf]);
111
124
  if (process.env.NODE_ENV === 'development' && typeConf === 'server') {
112
- const devConfPath = `${folder}/conf.${typeConf}.dev${process.argv[3] ? `.${process.argv[3]}` : ''}.json`;
125
+ if (!subConf) subConf = process.argv[3];
126
+ const devConfPath = `${folder}/conf.${typeConf}.dev${subConf ? `.${subConf}` : ''}.json`;
113
127
  if (fs.existsSync(devConfPath)) srcConf = fs.readFileSync(devConfPath, 'utf8');
114
128
  }
115
129
  if (typeConf === 'server') srcConf = JSON.stringify(loadReplicas(JSON.parse(srcConf)), null, 4);
@@ -127,19 +141,25 @@ const loadConf = (deployId, envInput) => {
127
141
  ...env,
128
142
  };
129
143
  }
130
- fs.writeFileSync(`./package.json`, fs.readFileSync(`${folder}/package.json`, 'utf8'), 'utf8');
144
+ const originPackageJson = JSON.parse(fs.readFileSync(`./package.json`, 'utf8'));
145
+ const packageJson = JSON.parse(fs.readFileSync(`${folder}/package.json`, 'utf8'));
146
+ originPackageJson.scripts.start = packageJson.scripts.start;
147
+ packageJson.scripts = originPackageJson.scripts;
148
+ fs.writeFileSync(`./package.json`, JSON.stringify(packageJson, null, 4), 'utf8');
131
149
  return { folder, deployId };
132
150
  };
133
151
 
134
- const loadReplicas = (confServer) => {
152
+ const loadReplicas = (confServer, deployContext, subConf) => {
153
+ if (!deployContext) deployContext = process.argv[2];
154
+ if (!subConf) subConf = process.argv[3];
135
155
  for (const host of Object.keys(confServer)) {
136
156
  for (const path of Object.keys(confServer[host])) {
137
157
  const { replicas, singleReplica } = confServer[host][path];
138
158
  if (
139
159
  replicas &&
140
- (process.argv[2] === 'proxy' ||
160
+ (deployContext === 'proxy' ||
141
161
  !singleReplica ||
142
- (singleReplica && process.env.NODE_ENV === 'development' && !process.argv[3]))
162
+ (singleReplica && process.env.NODE_ENV === 'development' && !subConf))
143
163
  )
144
164
  for (const replicaPath of replicas) {
145
165
  confServer[host][replicaPath] = newInstance(confServer[host][path]);
@@ -509,21 +529,25 @@ const buildPortProxyRouter = (port, proxyRouter) => {
509
529
  // build router
510
530
  Object.keys(hosts).map((hostKey) => {
511
531
  let { host, path, target, proxy, peer } = hosts[hostKey];
512
- if (process.env.NODE_ENV === 'development') host = `localhost`;
532
+ if (process.argv.includes('localhost') && process.env.NODE_ENV === 'development') host = `localhost`;
513
533
 
514
534
  if (!proxy.includes(port)) return;
515
535
  const absoluteHost = [80, 443].includes(port)
516
536
  ? `${host}${path === '/' ? '' : path}`
517
537
  : `${host}:${port}${path === '/' ? '' : path}`;
518
538
 
519
- if (!(absoluteHost in router)) router[absoluteHost] = target;
539
+ if (process.argv.includes('localhost')) {
540
+ if (!(absoluteHost in router)) router[absoluteHost] = target;
541
+ } else router[absoluteHost] = target;
520
542
  }); // order router
521
543
 
522
544
  if (Object.keys(router).length === 0) return router;
523
545
 
546
+ const reOrderRouter = {};
524
547
  for (const absoluteHostKey of orderArrayFromAttrInt(Object.keys(router), 'length'))
525
- router[absoluteHostKey] = router[absoluteHostKey];
526
- return router;
548
+ reOrderRouter[absoluteHostKey] = router[absoluteHostKey];
549
+
550
+ return reOrderRouter;
527
551
  };
528
552
 
529
553
  const cliBar = async (time = 5000) => {
@@ -576,7 +600,15 @@ const buildReplicaId = ({ deployId, replica }) => `${deployId}-${replica.slice(1
576
600
  const getDataDeploy = (
577
601
  options = { buildSingleReplica: false, deployGroupId: '', deployId: '', disableSyncEnvPort: false },
578
602
  ) => {
579
- let dataDeploy = JSON.parse(fs.readFileSync(`./engine-private/deploy/${options.deployGroupId}.json`, 'utf8'));
603
+ let dataDeploy =
604
+ options.deployGroupId === 'dd'
605
+ ? fs.readFileSync(`./engine-private/deploy/${options.deployGroupId}.router`, 'utf8')
606
+ : fs.readFileSync(`./engine-private/deploy/${options.deployGroupId}`, 'utf8');
607
+
608
+ dataDeploy = dataDeploy
609
+ .split(',')
610
+ .map((deployId) => deployId.trim())
611
+ .filter((deployId) => deployId);
580
612
 
581
613
  if (options.deployId) dataDeploy = dataDeploy.filter((d) => d === options.deployId);
582
614
 
@@ -962,10 +994,10 @@ const Cmd = {
962
994
  conf: (deployId, env) => `node bin/deploy conf ${deployId} ${env ? env : 'production'}`,
963
995
  replica: (deployId, host, path) => `node bin/deploy build-single-replica ${deployId} ${host} ${path}`,
964
996
  syncPorts: (deployGroupId) => `node bin/deploy sync-env-port ${deployGroupId}`,
965
- cron: (deployId, job, expression) => {
966
- shellExec(Cmd.delete(`${deployId}-${job}`));
967
- return `env-cmd -f .env.production pm2 start bin/cron.js --no-autorestart --instances 1 --cron "${expression}" --name ${deployId}-${job} -- ${job} ${deployId}`;
968
- },
997
+ cron: (deployList, jobList, name, expression, options) =>
998
+ `pm2 start ./bin/index.js --no-autorestart --instances 1 --cron "${expression}" --name ${name} -- cron ${
999
+ options?.disableKindCluster ? `--disable-kind-cluster ` : ''
1000
+ }${deployList} ${jobList}`,
969
1001
  };
970
1002
 
971
1003
  const fixDependencies = async () => {
@@ -1035,167 +1067,21 @@ const setUpProxyMaintenanceServer = ({ deployGroupId }) => {
1035
1067
  shellExec(`node bin/deploy run ${proxyDeployId} maintenance`);
1036
1068
  };
1037
1069
 
1038
- const repoClone = (gitUri = 'underpostnet/pwa-microservices-template') => {
1039
- const repoName = gitUri.split('/').pop();
1040
- if (fs.existsSync(`./${repoName}`)) fs.removeSync(`./${repoName}`);
1041
- shellExec(
1042
- `git clone https://${process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN}@` : ''}github.com/${gitUri}.git`,
1043
- );
1044
- if (process.env.GITHUB_TOKEN) {
1045
- shellExec(
1046
- `git clone https://${
1047
- process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN}@` : ''
1048
- }github.com/${gitUri}-private.git`,
1049
- );
1050
- fs.moveSync(`./${repoName}-private`, `./${repoName}/engine-private`, {
1051
- overwrite: true,
1052
- });
1053
- }
1054
- };
1055
-
1056
- const repoPull = (repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') => {
1057
- shellExec(`cd ${repoPath} && git pull https://${process.env.GITHUB_TOKEN}@github.com/${gitUri}.git`, {
1058
- disableLog: true,
1059
- });
1060
- };
1061
-
1062
- const commitData = {
1063
- feat: {
1064
- description: 'A new feature',
1065
- title: 'Features',
1066
- emoji: '✨',
1067
- },
1068
- fix: {
1069
- description: 'A bug fix',
1070
- title: 'Bug Fixes',
1071
- emoji: '🐛',
1072
- },
1073
- docs: {
1074
- description: 'Documentation only changes',
1075
- title: 'Documentation',
1076
- emoji: '📚',
1077
- },
1078
- style: {
1079
- description:
1080
- 'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
1081
- title: 'Styles',
1082
- emoji: '💎',
1083
- },
1084
- refactor: {
1085
- description: 'A code change that neither fixes a bug nor adds a feature',
1086
- title: 'Code Refactoring',
1087
- emoji: '📦',
1088
- },
1089
- perf: {
1090
- description: 'A code change that improves performance',
1091
- title: 'Performance Improvements',
1092
- emoji: '⚡️',
1093
- },
1094
- cd: {
1095
- description:
1096
- 'Changes to our Continuous Delivery configuration files and scripts (example scopes: Jenkins, Spinnaker, ArgoCD)',
1097
- title: 'Continuous Delivery',
1098
- emoji: '🚀',
1099
- },
1100
- test: {
1101
- description: 'Adding missing tests or correcting existing tests',
1102
- title: 'Tests',
1103
- emoji: '🚨',
1104
- },
1105
- build: {
1106
- description: 'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
1107
- title: 'Builds',
1108
- emoji: '🛠',
1109
- },
1110
- ci: {
1111
- description:
1112
- 'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
1113
- title: 'Continuous Integrations',
1114
- emoji: '⚙️',
1115
- },
1116
- chore: {
1117
- description: "Other changes that don't modify src or test files",
1118
- title: 'Chores',
1119
- emoji: '♻️',
1120
- },
1121
- revert: {
1122
- description: 'Reverts a previous commit',
1123
- title: 'Reverts',
1124
- emoji: '🗑',
1125
- },
1126
- backup: {
1127
- description: 'Changes related to backups, including creation, restoration, and maintenance.',
1128
- title: 'Backups',
1129
- emoji: '💾',
1130
- },
1131
- };
1132
-
1133
- const repoCommit = (
1134
- repoPath = './',
1135
- commitType = 'feat',
1136
- subModule = '',
1137
- message = '',
1138
- options = {
1139
- copy: false,
1140
- info: false,
1141
- empty: false,
1142
- },
1143
- ) => {
1144
- if (options.info) return logger.info('', commitData);
1145
- const _message = `${commitType}${subModule ? `(${subModule})` : ''}${process.argv.includes('!') ? '!' : ''}: ${
1146
- commitData[commitType].emoji
1147
- } ${message ? message : commitData[commitType].description}`;
1148
- if (options.copy) return pbcopy(_message);
1149
- shellExec(`cd ${repoPath} && git commit ${options?.empty ? `--allow-empty ` : ''}-m "${_message}"`);
1150
- };
1151
-
1152
- const repoPush = (repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') => {
1153
- shellExec(`cd ${repoPath} && git push https://${process.env.GITHUB_TOKEN}@github.com/${gitUri}.git`, {
1154
- disableLog: true,
1155
- });
1156
- logger.info(
1157
- 'commit url',
1158
- `http://github.com/${gitUri}/commit/${shellExec(`cd ${repoPath} && git rev-parse --verify HEAD`, {
1159
- stdout: true,
1160
- }).trim()}`,
1161
- );
1162
- };
1163
-
1164
1070
  const getNpmRootPath = () =>
1165
1071
  shellExec(`npm root -g`, {
1166
1072
  stdout: true,
1073
+ disableLog: true,
1074
+ silent: true,
1167
1075
  }).trim();
1168
1076
 
1169
- const newProject = (repositoryName, version) => {
1170
- return new Promise(async (resolve, reject) => {
1171
- try {
1172
- const exeRootPath = `${getNpmRootPath()}/underpost`;
1173
- // const exeRootPath = '/home/dd/pwa-microservices-template';
1174
- actionInitLog(version);
1175
- await logger.setUpInfo();
1176
- const destFolder = `${process.cwd()}/${repositoryName}`;
1177
- logger.info('Note: This process may take several minutes to complete');
1178
- logger.info('build app', { destFolder });
1179
- fs.mkdirSync(destFolder, { recursive: true });
1180
- fs.copySync(exeRootPath, destFolder);
1181
- if (fs.existsSync(`${destFolder}/node_modules`)) fs.removeSync(`${destFolder}/node_modules`);
1182
- fs.writeFileSync(`${destFolder}/.gitignore`, fs.readFileSync(`${exeRootPath}/.dockerignore`, 'utf8'), 'utf8');
1183
- shellExec(`cd ${destFolder} && git init && git add . && git commit -m "Base template implementation"`);
1184
- shellExec(`cd ${destFolder} && npm install`);
1185
- shellExec(`cd ${destFolder} && npm run build`);
1186
- shellExec(`cd ${destFolder} && npm run dev`);
1187
- return resolve();
1188
- } catch (error) {
1189
- logger.error(error, error.stack);
1190
- return reject(error.message);
1191
- }
1192
- });
1193
- };
1194
-
1195
- const runTest = (version) => {
1196
- actionInitLog(version);
1197
- shellExec(`cd ${getNpmRootPath()}/underpost && npm run test`);
1198
- };
1077
+ const writeEnv = (envPath, envObj) =>
1078
+ fs.writeFileSync(
1079
+ envPath,
1080
+ Object.keys(envObj)
1081
+ .map((key) => `${key}=${envObj[key]}`)
1082
+ .join(`\n`),
1083
+ 'utf8',
1084
+ );
1199
1085
 
1200
1086
  export {
1201
1087
  Cmd,
@@ -1232,11 +1118,6 @@ export {
1232
1118
  buildKindPorts,
1233
1119
  buildPortProxyRouter,
1234
1120
  splitFileFactory,
1235
- repoClone,
1236
- repoPull,
1237
- repoCommit,
1238
- repoPush,
1239
- newProject,
1240
- runTest,
1241
1121
  getNpmRootPath,
1122
+ writeEnv,
1242
1123
  };