underpost 2.8.1 → 2.8.7

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 (145) hide show
  1. package/.dockerignore +1 -0
  2. package/.github/workflows/ghpkg.yml +19 -49
  3. package/.github/workflows/npmpkg.yml +67 -0
  4. package/.github/workflows/publish.yml +5 -5
  5. package/.github/workflows/pwa-microservices-template.page.yml +12 -4
  6. package/.github/workflows/pwa-microservices-template.test.yml +2 -2
  7. package/.vscode/extensions.json +18 -71
  8. package/.vscode/settings.json +20 -3
  9. package/AUTHORS.md +16 -5
  10. package/CHANGELOG.md +123 -3
  11. package/Dockerfile +27 -70
  12. package/README.md +39 -29
  13. package/bin/build.js +186 -0
  14. package/bin/db.js +2 -24
  15. package/bin/deploy.js +1467 -236
  16. package/bin/file.js +67 -16
  17. package/bin/hwt.js +0 -10
  18. package/bin/index.js +1 -77
  19. package/bin/ssl.js +19 -11
  20. package/bin/util.js +9 -104
  21. package/bin/vs.js +26 -2
  22. package/cli.md +451 -0
  23. package/conf.js +29 -138
  24. package/docker-compose.yml +1 -1
  25. package/jsdoc.json +1 -1
  26. package/manifests/calico-custom-resources.yaml +25 -0
  27. package/manifests/deployment/adminer/deployment.yaml +32 -0
  28. package/manifests/deployment/adminer/kustomization.yaml +7 -0
  29. package/manifests/deployment/adminer/service.yaml +13 -0
  30. package/manifests/deployment/fastapi/backend-deployment.yml +120 -0
  31. package/manifests/deployment/fastapi/backend-service.yml +19 -0
  32. package/manifests/deployment/fastapi/frontend-deployment.yml +54 -0
  33. package/manifests/deployment/fastapi/frontend-service.yml +15 -0
  34. package/manifests/deployment/kafka/deployment.yaml +69 -0
  35. package/manifests/deployment/mongo-express/deployment.yaml +60 -0
  36. package/manifests/deployment/phpmyadmin/deployment.yaml +54 -0
  37. package/manifests/kind-config-dev.yaml +12 -0
  38. package/manifests/kind-config.yaml +12 -0
  39. package/manifests/kubeadm-calico-config.yaml +119 -0
  40. package/manifests/letsencrypt-prod.yaml +15 -0
  41. package/manifests/mariadb/config.yaml +10 -0
  42. package/manifests/mariadb/kustomization.yaml +9 -0
  43. package/manifests/mariadb/pv.yaml +12 -0
  44. package/manifests/mariadb/pvc.yaml +10 -0
  45. package/manifests/mariadb/secret.yaml +8 -0
  46. package/manifests/mariadb/service.yaml +10 -0
  47. package/manifests/mariadb/statefulset.yaml +55 -0
  48. package/manifests/mongodb/backup-access.yaml +16 -0
  49. package/manifests/mongodb/backup-cronjob.yaml +42 -0
  50. package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
  51. package/manifests/mongodb/configmap.yaml +26 -0
  52. package/manifests/mongodb/headless-service.yaml +10 -0
  53. package/manifests/mongodb/kustomization.yaml +11 -0
  54. package/manifests/mongodb/pv-pvc.yaml +23 -0
  55. package/manifests/mongodb/statefulset.yaml +125 -0
  56. package/manifests/mongodb-4.4/kustomization.yaml +7 -0
  57. package/manifests/mongodb-4.4/pv-pvc.yaml +23 -0
  58. package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
  59. package/manifests/postgresql/configmap.yaml +9 -0
  60. package/manifests/postgresql/kustomization.yaml +10 -0
  61. package/manifests/postgresql/pv.yaml +15 -0
  62. package/manifests/postgresql/pvc.yaml +13 -0
  63. package/manifests/postgresql/service.yaml +10 -0
  64. package/manifests/postgresql/statefulset.yaml +37 -0
  65. package/manifests/valkey/kustomization.yaml +7 -0
  66. package/manifests/valkey/service.yaml +17 -0
  67. package/manifests/valkey/statefulset.yaml +41 -0
  68. package/package.json +127 -136
  69. package/src/api/core/core.service.js +1 -1
  70. package/src/api/default/default.service.js +1 -1
  71. package/src/api/user/user.model.js +16 -3
  72. package/src/api/user/user.service.js +15 -12
  73. package/src/cli/cluster.js +389 -0
  74. package/src/cli/cron.js +121 -0
  75. package/src/cli/db.js +222 -0
  76. package/src/cli/deploy.js +487 -0
  77. package/src/cli/env.js +58 -0
  78. package/src/cli/fs.js +161 -0
  79. package/src/cli/image.js +66 -0
  80. package/src/cli/index.js +312 -0
  81. package/src/cli/monitor.js +236 -0
  82. package/src/cli/repository.js +128 -0
  83. package/src/cli/script.js +53 -0
  84. package/src/cli/secrets.js +37 -0
  85. package/src/cli/test.js +118 -0
  86. package/src/client/components/core/Account.js +28 -24
  87. package/src/client/components/core/Auth.js +22 -4
  88. package/src/client/components/core/Blockchain.js +1 -1
  89. package/src/client/components/core/CalendarCore.js +128 -121
  90. package/src/client/components/core/CommonJs.js +283 -19
  91. package/src/client/components/core/CssCore.js +16 -4
  92. package/src/client/components/core/Docs.js +1 -2
  93. package/src/client/components/core/DropDown.js +5 -1
  94. package/src/client/components/core/EventsUI.js +3 -3
  95. package/src/client/components/core/FileExplorer.js +86 -78
  96. package/src/client/components/core/Input.js +22 -6
  97. package/src/client/components/core/JoyStick.js +2 -2
  98. package/src/client/components/core/LoadingAnimation.js +3 -12
  99. package/src/client/components/core/LogIn.js +3 -3
  100. package/src/client/components/core/LogOut.js +1 -1
  101. package/src/client/components/core/Modal.js +54 -20
  102. package/src/client/components/core/Panel.js +109 -90
  103. package/src/client/components/core/PanelForm.js +23 -30
  104. package/src/client/components/core/Recover.js +3 -3
  105. package/src/client/components/core/RichText.js +1 -11
  106. package/src/client/components/core/Router.js +3 -1
  107. package/src/client/components/core/Scroll.js +1 -0
  108. package/src/client/components/core/SignUp.js +2 -2
  109. package/src/client/components/core/Translate.js +47 -9
  110. package/src/client/components/core/Validator.js +9 -1
  111. package/src/client/components/core/VanillaJs.js +0 -9
  112. package/src/client/components/core/Worker.js +34 -31
  113. package/src/client/components/default/RoutesDefault.js +3 -2
  114. package/src/client/services/core/core.service.js +15 -10
  115. package/src/client/services/default/default.management.js +46 -37
  116. package/src/client/ssr/Render.js +6 -1
  117. package/src/client/ssr/body/CacheControl.js +2 -3
  118. package/src/client/sw/default.sw.js +3 -3
  119. package/src/db/mongo/MongooseDB.js +29 -1
  120. package/src/index.js +101 -19
  121. package/src/mailer/MailerProvider.js +3 -0
  122. package/src/runtime/lampp/Dockerfile +65 -0
  123. package/src/runtime/lampp/Lampp.js +1 -13
  124. package/src/runtime/xampp/Xampp.js +0 -13
  125. package/src/server/auth.js +3 -3
  126. package/src/server/backup.js +49 -93
  127. package/src/server/client-build.js +49 -46
  128. package/src/server/client-formatted.js +6 -3
  129. package/src/server/conf.js +297 -55
  130. package/src/server/dns.js +75 -62
  131. package/src/server/downloader.js +0 -8
  132. package/src/server/json-schema.js +77 -0
  133. package/src/server/logger.js +15 -10
  134. package/src/server/network.js +20 -161
  135. package/src/server/peer.js +2 -2
  136. package/src/server/process.js +25 -2
  137. package/src/server/proxy.js +7 -29
  138. package/src/server/runtime.js +53 -40
  139. package/src/server/ssl.js +1 -1
  140. package/src/server/start.js +122 -0
  141. package/src/server/valkey.js +27 -11
  142. package/test/api.test.js +0 -8
  143. package/src/dns.js +0 -22
  144. package/src/server/prompt-optimizer.js +0 -28
  145. package/startup.js +0 -11
package/src/cli/fs.js ADDED
@@ -0,0 +1,161 @@
1
+ import { v2 as cloudinary } from 'cloudinary';
2
+ import { loggerFactory } from '../server/logger.js';
3
+ import dotenv from 'dotenv';
4
+ import AdmZip from 'adm-zip';
5
+ import * as dir from 'path';
6
+ import fs from 'fs-extra';
7
+ import { Downloader } from '../server/downloader.js';
8
+ import UnderpostRepository from './repository.js';
9
+ import { shellExec } from '../server/process.js';
10
+ dotenv.config();
11
+
12
+ const logger = loggerFactory(import.meta);
13
+
14
+ class UnderpostFileStorage {
15
+ static API = {
16
+ cloudinaryConfig() {
17
+ // https://console.cloudinary.com/
18
+ cloudinary.config({
19
+ cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
20
+ api_key: process.env.CLOUDINARY_API_KEY,
21
+ api_secret: process.env.CLOUDINARY_API_SECRET,
22
+ });
23
+ },
24
+ getStorageConf(options) {
25
+ let storage, storageConf;
26
+ if (options.deployId && typeof options.deployId === 'string') {
27
+ storageConf = options.storageFilePath ?? `./engine-private/conf/${options.deployId}/storage.json`;
28
+ if (!fs.existsSync(storageConf)) fs.writeFileSync(storageConf, JSON.stringify({}), 'utf8');
29
+ storage = JSON.parse(fs.readFileSync(storageConf, 'utf8'));
30
+ }
31
+ return { storage, storageConf };
32
+ },
33
+ writeStorageConf(storage, storageConf) {
34
+ if (storage) fs.writeFileSync(storageConf, JSON.stringify(storage, null, 4), 'utf8');
35
+ },
36
+ async recursiveCallback(
37
+ path,
38
+ options = {
39
+ rm: false,
40
+ recursive: false,
41
+ deployId: '',
42
+ force: false,
43
+ pull: false,
44
+ git: false,
45
+ storageFilePath: '',
46
+ },
47
+ ) {
48
+ const { storage, storageConf } = UnderpostFileStorage.API.getStorageConf(options);
49
+ const deleteFiles = options.pull === true ? [] : UnderpostRepository.API.getDeleteFiles(path);
50
+ for (const relativePath of deleteFiles) {
51
+ const _path = path + '/' + relativePath;
52
+ if (_path in storage) {
53
+ await UnderpostFileStorage.API.delete(_path);
54
+ delete storage[_path];
55
+ }
56
+ }
57
+ if (options.pull === true) {
58
+ for (const _path of Object.keys(storage)) {
59
+ if (!fs.existsSync(_path) || options.force === true) {
60
+ if (options.force === true && fs.existsSync(_path)) fs.removeSync(_path);
61
+ await UnderpostFileStorage.API.pull(_path, options);
62
+ } else logger.warn(`Pull path already exists`, _path);
63
+ }
64
+ } else {
65
+ const files =
66
+ options.git === true
67
+ ? UnderpostRepository.API.getChangedFiles(path)
68
+ : await fs.readdir(path, { recursive: true });
69
+ for (const relativePath of files) {
70
+ const _path = path + '/' + relativePath;
71
+ if (fs.statSync(_path).isDirectory()) {
72
+ if (options.pull === true && !fs.existsSync(_path)) fs.mkdirSync(_path, { recursive: true });
73
+ continue;
74
+ } else if (!(_path in storage) || options.force === true) {
75
+ await UnderpostFileStorage.API.upload(_path, options);
76
+ if (storage) storage[_path] = {};
77
+ } else logger.warn('File already exists', _path);
78
+ }
79
+ }
80
+ UnderpostFileStorage.API.writeStorageConf(storage, storageConf);
81
+ if (options.git === true) {
82
+ shellExec(`cd ${path} && git add .`);
83
+ shellExec(`underpost cmt ${path} feat`);
84
+ }
85
+ },
86
+ async callback(
87
+ path,
88
+ options = { rm: false, recursive: false, deployId: '', force: false, pull: false, git: false },
89
+ ) {
90
+ if (options.recursive === true || options.git === true)
91
+ return await UnderpostFileStorage.API.recursiveCallback(path, options);
92
+ if (options.pull === true) return await UnderpostFileStorage.API.pull(path, options);
93
+ if (options.rm === true) return await UnderpostFileStorage.API.delete(path, options);
94
+ return await UnderpostFileStorage.API.upload(path, options);
95
+ },
96
+ async upload(
97
+ path,
98
+ options = { rm: false, recursive: false, deployId: '', force: false, pull: false, storageFilePath: '' },
99
+ ) {
100
+ UnderpostFileStorage.API.cloudinaryConfig();
101
+ const { storage, storageConf } = UnderpostFileStorage.API.getStorageConf(options);
102
+ // path = UnderpostFileStorage.API.file2Zip(path);
103
+ const uploadResult = await cloudinary.uploader
104
+ .upload(path, {
105
+ public_id: path,
106
+ resource_type: 'raw',
107
+ overwrite: options.force === true ? true : false,
108
+ })
109
+ .catch((error) => {
110
+ logger.error(error, { path, stack: error.stack });
111
+ });
112
+ logger.info('upload result', uploadResult);
113
+ if (storage) storage[path] = {};
114
+ UnderpostFileStorage.API.writeStorageConf(storage, storageConf);
115
+ return uploadResult;
116
+ },
117
+ async pull(path) {
118
+ UnderpostFileStorage.API.cloudinaryConfig();
119
+ const folder = dir.dirname(path);
120
+ if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true });
121
+ const downloadResult = await cloudinary.utils.download_archive_url({
122
+ public_ids: [path],
123
+ resource_type: 'raw',
124
+ });
125
+ logger.info('download result', downloadResult);
126
+ await Downloader(downloadResult, path + '.zip');
127
+ path = UnderpostFileStorage.API.zip2File(path + '.zip');
128
+ fs.removeSync(path + '.zip');
129
+ },
130
+ async delete(path) {
131
+ UnderpostFileStorage.API.cloudinaryConfig();
132
+ const deleteResult = await cloudinary.api
133
+ .delete_resources([path], { type: 'upload', resource_type: 'raw' })
134
+ .catch((error) => {
135
+ logger.error(error, { path, stack: error.stack });
136
+ });
137
+ logger.info('delete result', deleteResult);
138
+ return deleteResult;
139
+ },
140
+ file2Zip(path) {
141
+ const zip = new AdmZip();
142
+ zip.addLocalFile(path, '/');
143
+ path = path + '.zip';
144
+ zip.writeZip(path);
145
+ return path;
146
+ },
147
+ zip2File(path) {
148
+ const zip = new AdmZip(path);
149
+ path = path.replaceAll('.zip', '');
150
+ zip.extractEntryTo(
151
+ /*entry name*/ path.split('/').pop(),
152
+ /*target path*/ dir.dirname(path),
153
+ /*maintainEntryPath*/ false,
154
+ /*overwrite*/ true,
155
+ );
156
+ return path;
157
+ },
158
+ };
159
+ }
160
+
161
+ export default UnderpostFileStorage;
@@ -0,0 +1,66 @@
1
+ import fs from 'fs-extra';
2
+ import { shellCd, shellExec } from '../server/process.js';
3
+ import dotenv from 'dotenv';
4
+ import { awaitDeployMonitor, getNpmRootPath } from '../server/conf.js';
5
+ import { loggerFactory } from '../server/logger.js';
6
+ import UnderpostMonitor from './monitor.js';
7
+
8
+ dotenv.config();
9
+
10
+ const logger = loggerFactory(import.meta);
11
+
12
+ class UnderpostImage {
13
+ static API = {
14
+ dockerfile: {
15
+ pullBaseImages() {
16
+ shellExec(`sudo podman pull docker.io/library/debian:buster`);
17
+ },
18
+ build(
19
+ options = {
20
+ path: '',
21
+ imageName: '',
22
+ imagePath: '',
23
+ dockerfileName: '',
24
+ podmanSave: false,
25
+ kindLoad: false,
26
+ secrets: false,
27
+ secretsPath: '',
28
+ noCache: false,
29
+ },
30
+ ) {
31
+ const { path, imageName, imagePath, dockerfileName, podmanSave, secrets, secretsPath, kindLoad, noCache } =
32
+ options;
33
+ const podManImg = `localhost/${imageName}`;
34
+ if (imagePath && typeof imagePath === 'string' && !fs.existsSync(imagePath))
35
+ fs.mkdirSync(imagePath, { recursive: true });
36
+ const tarFile = `${imagePath}/${imageName.replace(':', '_')}.tar`;
37
+ let secretsInput = ' ';
38
+ let secretDockerInput = '';
39
+ let cache = '';
40
+ if (secrets === true) {
41
+ const envObj = dotenv.parse(
42
+ fs.readFileSync(
43
+ secretsPath && typeof secretsPath === 'string' ? secretsPath : `${getNpmRootPath()}/underpost/.env`,
44
+ 'utf8',
45
+ ),
46
+ );
47
+ for (const key of Object.keys(envObj)) {
48
+ secretsInput += ` && export ${key}="${envObj[key]}" `; // $(cat gitlab-token.txt)
49
+ secretDockerInput += ` --secret id=${key},env=${key} \ `;
50
+ }
51
+ }
52
+ if (noCache === true) cache += ' --rm --no-cache';
53
+ if (path && typeof path === 'string')
54
+ shellExec(
55
+ `cd ${path}${secretsInput}&& sudo podman build -f ./${
56
+ dockerfileName && typeof dockerfileName === 'string' ? dockerfileName : 'Dockerfile'
57
+ } -t ${imageName} --pull=never --cap-add=CAP_AUDIT_WRITE${cache}${secretDockerInput} --network host`,
58
+ );
59
+
60
+ if (podmanSave === true) shellExec(`podman save -o ${tarFile} ${podManImg}`);
61
+ if (kindLoad === true) shellExec(`sudo kind load image-archive ${tarFile}`);
62
+ },
63
+ },
64
+ };
65
+ }
66
+ export default UnderpostImage;
@@ -0,0 +1,312 @@
1
+ import dotenv from 'dotenv';
2
+ import { Command } from 'commander';
3
+ import Underpost from '../index.js';
4
+ import { getUnderpostRootPath, loadConf } from '../server/conf.js';
5
+ import fs from 'fs-extra';
6
+ import { commitData } from '../client/components/core/CommonJs.js';
7
+ import { shellExec } from '../server/process.js';
8
+
9
+ const underpostRootPath = getUnderpostRootPath();
10
+ fs.existsSync(`${underpostRootPath}/.env`)
11
+ ? dotenv.config({ path: `${underpostRootPath}/.env`, override: true })
12
+ : dotenv.config();
13
+
14
+ const program = new Command();
15
+
16
+ program.name('underpost').description(`underpost ci/cd cli ${Underpost.version}`).version(Underpost.version);
17
+
18
+ program
19
+ .command('new')
20
+ .argument('<app-name>', 'Application name')
21
+ .description('Create a new project')
22
+ .action(Underpost.repo.new);
23
+
24
+ program
25
+ .command('start')
26
+ .argument('<deploy-id>', 'Deploy configuration id')
27
+ .argument('[env]', 'Optional environment, for default is development')
28
+ .option('--run', 'Run app servers and monitor health server')
29
+ .option('--build', 'Build app client')
30
+ .action(Underpost.start.callback)
31
+ .description('Start up server, build pipelines, or services');
32
+
33
+ program
34
+ .command('clone')
35
+ .argument(`<uri>`, 'e.g. username/repository')
36
+ .option('--bare', 'Clone only .git files')
37
+ .description('Clone github repository')
38
+ .action(Underpost.repo.clone);
39
+
40
+ program
41
+ .command('pull')
42
+ .argument('<path>', 'Absolute or relative directory')
43
+ .argument(`<uri>`, 'e.g. username/repository')
44
+ .description('Pull github repository')
45
+ .action(Underpost.repo.pull);
46
+
47
+ program
48
+ .command('cmt')
49
+ .argument('<path>', 'Absolute or relative directory')
50
+ .argument(`<commit-type>`, `Options: ${Object.keys(commitData)}`)
51
+ .argument(`[module-tag]`, 'Optional set module tag')
52
+ .argument(`[message]`, 'Optional set additional message')
53
+ .option('--empty', 'Allow empty files')
54
+ .option('--copy', 'Copy to clipboard message')
55
+ .option('--info', 'Info commit types')
56
+ .description('Commit github repository')
57
+ .action(Underpost.repo.commit);
58
+
59
+ program
60
+ .command('push')
61
+ .argument('<path>', 'Absolute or relative directory')
62
+ .argument(`<uri>`, 'e.g. username/repository')
63
+ .option('-f', 'Force push overwriting repository')
64
+ .description('Push github repository')
65
+ .action(Underpost.repo.push);
66
+
67
+ program
68
+ .command('env')
69
+ .argument('<deploy-id>', `deploy configuration id, if 'clean' restore default`)
70
+ .argument('[env]', 'Optional environment, for default is production')
71
+ .description('Set environment variables files and conf related to <deploy-id>')
72
+ .action(loadConf);
73
+
74
+ program
75
+ .command('config')
76
+ .argument('operator', `Options: ${Object.keys(Underpost.env)}`)
77
+ .argument('[key]', 'Config key')
78
+ .argument('[value]', 'Config value')
79
+ .description(`Manage configuration, operators`)
80
+ .action((...args) => Underpost.env[args[0]](args[1], args[2]));
81
+
82
+ program
83
+ .command('root')
84
+ .description('Get npm root path')
85
+ .action(() => console.log(getNpmRootPath()));
86
+
87
+ program
88
+ .command('cluster')
89
+ .argument('[pod-name]', 'Optional pod name filter')
90
+ .option('--reset', `Delete all clusters and prune all data and caches`)
91
+ .option('--mariadb', 'Init with mariadb statefulset')
92
+ .option('--mongodb', 'Init with mongodb statefulset')
93
+ .option('--postgresql', 'Init with postgresql statefulset')
94
+ .option('--mongodb4', 'Init with mongodb 4.4 service')
95
+ .option('--istio', 'Init base istio cluster')
96
+ .option('--valkey', 'Init with valkey service')
97
+ .option('--contour', 'Init with project contour base HTTPProxy and envoy')
98
+ .option('--cert-manager', 'Init with letsencrypt-prod ClusterIssuer')
99
+ .option('--info', 'Get all kinds objects deployed')
100
+ .option('--full', 'Init with all statefulsets and services available')
101
+ .option('--ns-use <ns-name>', 'Switches current context to namespace')
102
+ .option('--dev', 'init with dev cluster')
103
+ .option('--list-pods', 'Display list pods information')
104
+ .option('--info-capacity', 'display current total machine capacity info')
105
+ .option('--info-capacity-pod', 'display current machine capacity pod info')
106
+ .option('--pull-image', 'Set optional pull associated image')
107
+ .action(Underpost.cluster.init)
108
+ .description('Manage cluster, for default initialization base kind cluster');
109
+
110
+ program
111
+ .command('deploy')
112
+ .argument('<deploy-list>', 'Deploy id list, e.g. default-a,default-b')
113
+ .argument('[env]', 'Optional environment, for default is development')
114
+ .option('--remove', 'Delete deployments and services')
115
+ .option('--sync', 'Sync deployments env, ports, and replicas')
116
+ .option('--info-router', 'Display router structure')
117
+ .option('--expose', 'Expose service match deploy-list')
118
+ .option('--info-util', 'Display kubectl util management commands')
119
+ .option('--cert', 'Reset tls/ssl certificate secrets')
120
+ .option('--build-manifest', 'Build kind yaml manifests: deployments, services, proxy and secrets')
121
+ .option('--dashboard-update', 'Update dashboard instance data with current router config')
122
+ .option('--replicas <replicas>', 'Set custom number of replicas')
123
+ .option('--versions <deployment-versions>', 'Comma separated custom deployment versions')
124
+ .option('--traffic <traffic-versions>', 'Comma separated custom deployment traffic')
125
+ .option('--disable-update-deployment', 'Disable update deployments')
126
+ .option('--info-traffic', 'get traffic conf form current resources deployments')
127
+ .option(
128
+ '--rebuild-clients-bundle',
129
+ 'Inside container, rebuild clients bundle, only static public or storage client files',
130
+ )
131
+ .description('Manage deployment, for default deploy development pods')
132
+ .action(Underpost.deploy.callback);
133
+
134
+ program
135
+ .command('secret')
136
+ .argument('<platform>', `Options: ${Object.keys(Underpost.secret)}`)
137
+ .option('--init', 'Init secrets platform environment')
138
+ .option('--create-from-file <path-env-file>', 'Create secret from env file')
139
+ .option('--list', 'Lists secrets')
140
+ // .option('--delete [secret-key]', 'Delete key secret, if not set, are default delete all')
141
+ // .option('--create [secret-key] [secret-value]', 'Create secret key, with secret value')
142
+ .description(`Manage secrets`)
143
+ .action((...args) => {
144
+ if (args[1].createFromFile) return Underpost.secret[args[0]].createFromEnvFile(args[1].createFromFile);
145
+ if (args[1].list) return Underpost.secret[args[0]].list();
146
+ if (args[1].init) return Underpost.secret[args[0]].init();
147
+ });
148
+
149
+ program
150
+ .command('dockerfile-image-build')
151
+ .option('--path [path]', 'Dockerfile path')
152
+ .option('--image-name [image-name]', 'Set image name')
153
+ .option('--image-path [image-path]', 'Set tar image path')
154
+ .option('--dockerfile-name [dockerfile-name]', 'set Dockerfile name')
155
+ .option('--podman-save', 'Export tar file from podman')
156
+ .option('--kind-load', 'Import tar image to Kind cluster')
157
+ .option('--secrets', 'Dockerfile env secrets')
158
+ .option('--secrets-path [secrets-path]', 'Dockerfile custom path env secrets')
159
+ .option('--no-cache', 'Build without using cache')
160
+ .description('Build image from Dockerfile')
161
+ .action(Underpost.image.dockerfile.build);
162
+
163
+ program
164
+ .command('dockerfile-pull-base-images')
165
+ .description('Pull underpost dockerfile images requirements')
166
+ .action(Underpost.image.dockerfile.pullBaseImages);
167
+
168
+ program
169
+ .command('install')
170
+ .description('Fast import underpost npm dependencies')
171
+ .action(() => {
172
+ fs.copySync(`${underpostRootPath}/node_modules`, './node_modules');
173
+ });
174
+
175
+ program
176
+ .command('db')
177
+ .argument('<deploy-list>', 'Deploy id list, e.g. default-a,default-b')
178
+ .option('--import', 'Import container backups from repositories')
179
+ .option('--export', 'Export container backups to repositories')
180
+ .option('--pod-name <pod-name>', 'Optional pod context')
181
+ .option('--collections <collections>', 'Comma separated collections')
182
+ .option('--out-path <out-path>', 'Custom out path backup')
183
+ .option('--drop', 'Drop databases')
184
+ .option('--preserveUUID', 'Preserve Ids')
185
+ .option('--git', 'Upload to github')
186
+ .option('--hosts <hosts>', 'Comma separated hosts')
187
+ .option('--paths <paths>', 'Comma separated paths')
188
+ .option('--ns <ns-name>', 'Optional name space context')
189
+ .description('Manage databases')
190
+ .action(Underpost.db.callback);
191
+
192
+ program
193
+ .command('script')
194
+ .argument('operator', `Options: ${Object.keys(Underpost.script)}`)
195
+ .argument('<script-name>', 'Script name')
196
+ .argument('[script-value]', 'Literal command, or path')
197
+ .option('--itc', 'Inside container execution context')
198
+ .option('--itc-path', 'Inside container path options')
199
+ .option('--ns <ns-name>', 'Options name space context')
200
+ .option('--pod-name <pod-name>')
201
+ .description(
202
+ 'Supports a number of built-in underpost global scripts and their preset life cycle events as well as arbitrary scripts',
203
+ )
204
+ .action((...args) => Underpost.script[args[0]](args[1], args[2], args[3]));
205
+
206
+ program
207
+ .command('cron')
208
+ .argument('[deploy-list]', 'Deploy id list, e.g. default-a,default-b')
209
+ .argument('[job-list]', `Deploy id list, e.g. ${Object.keys(Underpost.cron)}, for default all available jobs`)
210
+ .option('--itc', 'Inside container execution context')
211
+ .option('--init', 'Init cron jobs for cron job default deploy id')
212
+ .option('--git', 'Upload to github')
213
+ .option('--dashboard-update', 'Update dashboard cron data with current jobs config')
214
+ .description('Cron jobs management')
215
+ .action(Underpost.cron.callback);
216
+
217
+ program
218
+ .command('fs')
219
+ .argument('[path]', 'Absolute or relative directory')
220
+ .option('--rm', 'Remove file')
221
+ .option('--git', 'Current git changes')
222
+ .option('--recursive', 'Upload files recursively')
223
+ .option('--deploy-id <deploy-id>', 'Deploy configuration id')
224
+ .option('--pull', 'Download file')
225
+ .option('--force', 'Force action')
226
+ .option('--storage-file-path <storage-file-path>', 'custom file storage path')
227
+ .description('File storage management, for default upload file')
228
+ .action(Underpost.fs.callback);
229
+
230
+ program
231
+ .command('test')
232
+ .argument('[deploy-list]', 'Deploy id list, e.g. default-a,default-b')
233
+ .description('Manage Test, for default run current underpost default test')
234
+ .option('--itc', 'Inside container execution context')
235
+ .option('--sh', 'Copy to clipboard, container entrypoint shell command')
236
+ .option('--logs', 'Display container logs')
237
+ .option('--pod-name <pod-name>')
238
+ .option('--pod-status <pod-status>')
239
+ .option('--kind-type <kind-type>')
240
+ .action(Underpost.test.callback);
241
+
242
+ program
243
+ .command('monitor')
244
+ .argument('<deploy-id>', 'Deploy configuration id')
245
+ .argument('[env]', 'Optional environment, for default is development')
246
+ .option('--ms-interval <ms-interval>', 'Custom ms interval delta time')
247
+ .option('--now', 'Exec immediately monitor script')
248
+ .option('--single', 'Disable recurrence')
249
+ .option('--replicas <replicas>', 'Set custom number of replicas')
250
+ .option('--type <type>', 'Set custom monitor type')
251
+ .option('--sync', 'Sync with current proxy deployments proxy traffic')
252
+ .description('Monitor health server management')
253
+ .action(Underpost.monitor.callback);
254
+
255
+ const buildCliDoc = () => {
256
+ let md = shellExec(`node bin help`, { silent: true, stdout: true }).split('Options:');
257
+ const baseOptions =
258
+ `## ${md[0].split(`\n`)[2]}
259
+
260
+ ### Usage: ` +
261
+ '`' +
262
+ md[0].split(`\n`)[0].split('Usage: ')[1] +
263
+ '`' +
264
+ `
265
+ ` +
266
+ '```\n Options:' +
267
+ md[1] +
268
+ ' \n```';
269
+ md =
270
+ baseOptions +
271
+ `
272
+
273
+ ## Commands:
274
+ `;
275
+ program.commands.map((o) => {
276
+ md +=
277
+ `
278
+
279
+ ` +
280
+ '### `' +
281
+ o._name +
282
+ '` :' +
283
+ `
284
+ ` +
285
+ '```\n ' +
286
+ shellExec(`node bin help ${o._name}`, { silent: true, stdout: true }) +
287
+ ' \n```' +
288
+ `
289
+ `;
290
+ });
291
+ fs.writeFileSync(`./src/client/public/nexodev/docs/references/Command Line Interface.md`, md, 'utf8');
292
+ fs.writeFileSync(`./cli.md`, md, 'utf8');
293
+ const readmeSplit = `pwa-microservices-template</a>`;
294
+ const readme = fs.readFileSync(`./README.md`, 'utf8').split(readmeSplit);
295
+ fs.writeFileSync(
296
+ './README.md',
297
+ readme[0] +
298
+ readmeSplit +
299
+ `
300
+
301
+ ` +
302
+ baseOptions +
303
+ `
304
+
305
+ <a target="_top" href="https://github.com/underpostnet/pwa-microservices-template/blob/master/cli.md">See complete CLI Docs here.</a>
306
+
307
+ `,
308
+ 'utf8',
309
+ );
310
+ };
311
+
312
+ export { program, buildCliDoc };