@underpostnet/underpost 2.8.1 → 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.
- package/.dockerignore +1 -0
- package/.github/workflows/ghpkg.yml +20 -50
- package/.github/workflows/npmpkg.yml +67 -0
- package/.github/workflows/publish.yml +5 -5
- package/.github/workflows/pwa-microservices-template.page.yml +13 -5
- package/.github/workflows/pwa-microservices-template.test.yml +2 -2
- package/.vscode/extensions.json +17 -71
- package/.vscode/settings.json +14 -3
- package/AUTHORS.md +16 -5
- package/CHANGELOG.md +79 -3
- package/Dockerfile +24 -66
- package/README.md +1 -28
- package/bin/build.js +161 -0
- package/bin/db.js +2 -24
- package/bin/deploy.js +111 -82
- package/bin/file.js +59 -16
- package/bin/index.js +168 -58
- package/bin/ssl.js +19 -11
- package/bin/util.js +9 -97
- package/bin/vs.js +25 -2
- package/conf.js +31 -138
- package/docker-compose.yml +1 -1
- package/manifests/core/kustomization.yaml +11 -0
- package/manifests/core/underpost-engine-backup-access.yaml +16 -0
- package/manifests/core/underpost-engine-backup-pv-pvc.yaml +22 -0
- package/manifests/core/underpost-engine-headless-service.yaml +10 -0
- package/manifests/core/underpost-engine-mongodb-backup-cronjob.yaml +40 -0
- package/manifests/core/underpost-engine-mongodb-configmap.yaml +26 -0
- package/manifests/core/underpost-engine-pv-pvc.yaml +23 -0
- package/manifests/core/underpost-engine-statefulset.yaml +91 -0
- package/manifests/deployment/mongo-express/deployment.yaml +60 -0
- package/manifests/deployment/phpmyadmin/deployment.yaml +54 -0
- package/manifests/kind-config.yaml +12 -0
- package/manifests/letsencrypt-prod.yaml +15 -0
- package/manifests/mariadb/config.yaml +10 -0
- package/manifests/mariadb/kustomization.yaml +9 -0
- package/manifests/mariadb/pv.yaml +12 -0
- package/manifests/mariadb/pvc.yaml +10 -0
- package/manifests/mariadb/secret.yaml +8 -0
- package/manifests/mariadb/service.yaml +10 -0
- package/manifests/mariadb/statefulset.yaml +55 -0
- package/manifests/mongodb/backup-access.yaml +16 -0
- package/manifests/mongodb/backup-cronjob.yaml +42 -0
- package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
- package/manifests/mongodb/configmap.yaml +26 -0
- package/manifests/mongodb/headless-service.yaml +10 -0
- package/manifests/mongodb/kustomization.yaml +11 -0
- package/manifests/mongodb/pv-pvc.yaml +23 -0
- package/manifests/mongodb/statefulset.yaml +125 -0
- package/manifests/valkey/kustomization.yaml +7 -0
- package/manifests/valkey/service.yaml +17 -0
- package/manifests/valkey/statefulset.yaml +39 -0
- package/manifests/valkey/underpost-engine-valkey-service.yaml +17 -0
- package/manifests/valkey/underpost-engine-valkey-statefulset.yaml +39 -0
- package/package.json +26 -31
- package/src/api/core/core.service.js +1 -1
- package/src/api/user/user.model.js +16 -3
- package/src/api/user/user.service.js +1 -1
- package/src/cli/cluster.js +154 -0
- package/src/cli/cron.js +90 -0
- package/src/cli/db.js +148 -0
- package/src/cli/deploy.js +277 -0
- package/src/cli/env.js +52 -0
- package/src/cli/image.js +125 -0
- package/src/cli/repository.js +104 -0
- package/src/cli/script.js +29 -0
- package/src/cli/secrets.js +37 -0
- package/src/cli/test.js +83 -0
- package/src/client/components/core/Auth.js +22 -4
- package/src/client/components/core/CalendarCore.js +115 -49
- package/src/client/components/core/CommonJs.js +231 -19
- package/src/client/components/core/Css.js +1 -0
- package/src/client/components/core/CssCore.js +6 -0
- package/src/client/components/core/DropDown.js +5 -1
- package/src/client/components/core/Input.js +18 -4
- package/src/client/components/core/Modal.js +10 -6
- package/src/client/components/core/Panel.js +84 -25
- package/src/client/components/core/PanelForm.js +4 -18
- package/src/client/components/core/Scroll.js +1 -0
- package/src/client/components/core/Translate.js +47 -9
- package/src/client/components/core/Validator.js +9 -1
- package/src/client/components/core/VanillaJs.js +0 -9
- package/src/client/components/core/Worker.js +34 -31
- package/src/client/services/default/default.management.js +4 -2
- package/src/client/ssr/body/CacheControl.js +2 -2
- package/src/db/mongo/MongooseDB.js +13 -1
- package/src/index.js +77 -19
- package/src/runtime/lampp/Lampp.js +1 -13
- package/src/runtime/xampp/Xampp.js +0 -13
- package/src/server/auth.js +3 -3
- package/src/server/backup.js +49 -93
- package/src/server/client-build.js +4 -23
- package/src/server/client-formatted.js +5 -3
- package/src/server/conf.js +193 -45
- package/src/server/dns.js +49 -67
- package/src/server/logger.js +15 -10
- package/src/server/network.js +17 -43
- package/src/server/process.js +25 -2
- package/src/server/proxy.js +4 -26
- package/src/server/runtime.js +14 -29
- package/src/server/ssl.js +1 -1
- package/src/server/valkey.js +2 -0
- package/src/dns.js +0 -22
- package/src/server/prompt-optimizer.js +0 -28
- package/startup.js +0 -11
package/bin/file.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
|
|
3
3
|
import { loggerFactory } from '../src/server/logger.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cap,
|
|
6
|
+
getCapVariableName,
|
|
7
|
+
getDirname,
|
|
8
|
+
newInstance,
|
|
9
|
+
uniqueArray,
|
|
10
|
+
} from '../src/client/components/core/CommonJs.js';
|
|
5
11
|
import { shellCd, shellExec } from '../src/server/process.js';
|
|
6
12
|
import walk from 'ignore-walk';
|
|
7
13
|
import { validateTemplatePath } from '../src/server/conf.js';
|
|
@@ -25,16 +31,8 @@ let name = getCapVariableName(file.split('.')[0]);
|
|
|
25
31
|
logger.info('File metadata', { path, file, ext, name });
|
|
26
32
|
|
|
27
33
|
try {
|
|
28
|
-
// throw '';
|
|
29
|
-
// let cmd;
|
|
30
34
|
let content = '';
|
|
31
35
|
switch (type) {
|
|
32
|
-
case 'create-js-module':
|
|
33
|
-
// node bin/file './src/client/components/core/progress bar.js'
|
|
34
|
-
content = `const ${name} = {}; export { ${name} }`;
|
|
35
|
-
setTimeout(() => shellExec(`prettier --write ${buildPath}`));
|
|
36
|
-
break;
|
|
37
|
-
|
|
38
36
|
case 'update-template':
|
|
39
37
|
case 'copy-src':
|
|
40
38
|
console.log({ rawPath, toPath });
|
|
@@ -77,22 +75,67 @@ try {
|
|
|
77
75
|
fs.copySync(`./.github`, `../pwa-microservices-template/.github`);
|
|
78
76
|
fs.copySync(`./src/client/public/default`, `../pwa-microservices-template/src/client/public/default`);
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
78
|
+
for (const checkoutPath of ['README.md', 'package-lock.json', 'package.json'])
|
|
79
|
+
shellExec(`cd ../pwa-microservices-template && git checkout ${checkoutPath}`);
|
|
80
|
+
|
|
84
81
|
for (const deletePath of [
|
|
85
82
|
'.github/workflows/coverall.yml',
|
|
86
83
|
'.github/workflows/docker-image.yml',
|
|
87
84
|
'.github/workflows/deploy.ssh.yml',
|
|
88
85
|
'.github/workflows/deploy.api-rest.yml',
|
|
86
|
+
'.github/workflows/engine.lampp.ci.yml',
|
|
87
|
+
'.github/workflows/engine.core.ci.yml',
|
|
88
|
+
'.github/workflows/engine.cyberia.ci.yml',
|
|
89
|
+
'./manifests/deployment/dd-lampp-development',
|
|
90
|
+
'./manifests/deployment/dd-cyberia-development',
|
|
91
|
+
'./manifests/deployment/dd-core-development',
|
|
89
92
|
'bin/web3.js',
|
|
90
93
|
'bin/cyberia.js',
|
|
91
|
-
'src/ipfs.js',
|
|
92
|
-
'src/k8s.js',
|
|
93
94
|
]) {
|
|
94
|
-
fs.removeSync('../pwa-microservices-template/' + deletePath);
|
|
95
|
+
if (fs.existsSync(deletePath)) fs.removeSync('../pwa-microservices-template/' + deletePath);
|
|
95
96
|
}
|
|
97
|
+
const originPackageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
98
|
+
const templatePackageJson = JSON.parse(fs.readFileSync('../pwa-microservices-template/package.json', 'utf8'));
|
|
99
|
+
|
|
100
|
+
const name = templatePackageJson.name;
|
|
101
|
+
const description = templatePackageJson.description;
|
|
102
|
+
const dev = templatePackageJson.scripts.dev;
|
|
103
|
+
const build = templatePackageJson.scripts.build;
|
|
104
|
+
|
|
105
|
+
templatePackageJson.dependencies = originPackageJson.dependencies;
|
|
106
|
+
templatePackageJson.devDependencies = originPackageJson.devDependencies;
|
|
107
|
+
templatePackageJson.version = originPackageJson.version;
|
|
108
|
+
templatePackageJson.scripts = originPackageJson.scripts;
|
|
109
|
+
templatePackageJson.name = name;
|
|
110
|
+
templatePackageJson.description = description;
|
|
111
|
+
templatePackageJson.scripts.dev = dev;
|
|
112
|
+
templatePackageJson.scripts.build = build;
|
|
113
|
+
templatePackageJson.keywords = uniqueArray(
|
|
114
|
+
['pwa', 'microservices', 'template', 'builder'].concat(templatePackageJson.keywords),
|
|
115
|
+
);
|
|
116
|
+
delete templatePackageJson.scripts['update-template'];
|
|
117
|
+
fs.writeFileSync(
|
|
118
|
+
'../pwa-microservices-template/package.json',
|
|
119
|
+
JSON.stringify(templatePackageJson, null, 4),
|
|
120
|
+
'utf8',
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const originPackageLockJson = JSON.parse(fs.readFileSync('./package-lock.json', 'utf8'));
|
|
124
|
+
const templatePackageLockJson = JSON.parse(
|
|
125
|
+
fs.readFileSync('../pwa-microservices-template/package-lock.json', 'utf8'),
|
|
126
|
+
);
|
|
127
|
+
const originBasePackageLock = newInstance(templatePackageLockJson.packages['']);
|
|
128
|
+
templatePackageLockJson.version = originPackageLockJson.version;
|
|
129
|
+
templatePackageLockJson.packages = originPackageLockJson.packages;
|
|
130
|
+
templatePackageLockJson.packages[''].name = originBasePackageLock.name;
|
|
131
|
+
templatePackageLockJson.packages[''].version = originPackageLockJson.version;
|
|
132
|
+
templatePackageLockJson.packages[''].hasInstallScript = originBasePackageLock.hasInstallScript;
|
|
133
|
+
templatePackageLockJson.packages[''].license = originBasePackageLock.license;
|
|
134
|
+
fs.writeFileSync(
|
|
135
|
+
'../pwa-microservices-template/package-lock.json',
|
|
136
|
+
JSON.stringify(templatePackageLockJson, null, 4),
|
|
137
|
+
'utf8',
|
|
138
|
+
);
|
|
96
139
|
}
|
|
97
140
|
|
|
98
141
|
break;
|
package/bin/index.js
CHANGED
|
@@ -1,81 +1,191 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import dotenv from 'dotenv';
|
|
4
|
-
import { shellCd, shellExec } from '../src/server/process.js';
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
4
|
import { Command } from 'commander';
|
|
7
|
-
import {
|
|
8
|
-
import { loggerFactory, underpostASCI } from '../src/server/logger.js';
|
|
5
|
+
import { loggerFactory } from '../src/server/logger.js';
|
|
9
6
|
import Underpost from '../src/index.js';
|
|
7
|
+
import { getNpmRootPath, loadConf } from '../src/server/conf.js';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import { commitData } from '../src/client/components/core/CommonJs.js';
|
|
10
|
+
import UnderpostScript from '../src/cli/script.js';
|
|
11
|
+
import UnderpostDB from '../src/cli/db.js';
|
|
12
|
+
import UnderpostCron from '../src/cli/cron.js';
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
const npmRoot = getNpmRootPath();
|
|
15
|
+
const underpostRoot = `${npmRoot}/underpost/.env`;
|
|
16
|
+
fs.existsSync(underpostRoot) ? dotenv.config({ path: underpostRoot, override: true }) : dotenv.config();
|
|
12
17
|
|
|
13
18
|
const logger = loggerFactory(import.meta);
|
|
14
19
|
|
|
15
|
-
const globalBinFolder = `${shellExec(`npm root -g`, {
|
|
16
|
-
stdout: true,
|
|
17
|
-
silent: true,
|
|
18
|
-
disableLog: true,
|
|
19
|
-
}).trim()}/underpost`;
|
|
20
|
-
|
|
21
20
|
const program = new Command();
|
|
22
21
|
|
|
23
|
-
program.name('underpost').description(`underpost
|
|
22
|
+
program.name('underpost').description(`underpost ci/cd cli ${Underpost.version}`).version(Underpost.version);
|
|
24
23
|
|
|
25
24
|
program
|
|
26
|
-
.command('new
|
|
25
|
+
.command('new')
|
|
26
|
+
.argument('<app-name>', 'Application name')
|
|
27
27
|
.description('Create a new project')
|
|
28
|
-
.action(
|
|
29
|
-
console.log(
|
|
30
|
-
underpostASCI() +
|
|
31
|
-
`
|
|
32
|
-
${Underpost.version} https://www.nexodev.org/docs
|
|
33
|
-
`,
|
|
34
|
-
);
|
|
35
|
-
await logger.setUpInfo();
|
|
36
|
-
const destFolder = `${process.cwd()}/${appName}`;
|
|
37
|
-
logger.info('Note: This process may take several minutes to complete');
|
|
38
|
-
logger.info('build app', { destFolder });
|
|
39
|
-
fs.mkdirSync(destFolder, { recursive: true });
|
|
40
|
-
fs.copySync(globalBinFolder, destFolder);
|
|
41
|
-
fs.writeFileSync(`${destFolder}/.gitignore`, fs.readFileSync(`${globalBinFolder}/.dockerignore`, 'utf8'), 'utf8');
|
|
42
|
-
shellCd(`${destFolder}`);
|
|
43
|
-
shellExec(`git init && git add . && git commit -m "Base template implementation"`);
|
|
44
|
-
shellExec(`npm run install-template`);
|
|
45
|
-
switch (process.platform) {
|
|
46
|
-
case 'linux':
|
|
47
|
-
try {
|
|
48
|
-
await MongooseDB.server();
|
|
49
|
-
} catch (error) {
|
|
50
|
-
logger.error(error, 'failed to start mongodb server');
|
|
51
|
-
}
|
|
52
|
-
break;
|
|
53
|
-
|
|
54
|
-
default:
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
shellExec(`npm run dev`);
|
|
58
|
-
});
|
|
28
|
+
.action(Underpost.repo.new);
|
|
59
29
|
|
|
60
30
|
program
|
|
61
|
-
.command('
|
|
62
|
-
.
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
31
|
+
.command('clone')
|
|
32
|
+
.argument(`<uri>`, 'e.g. username/repository')
|
|
33
|
+
.option('--bare', 'Clone only .git files')
|
|
34
|
+
.description('Clone github repository')
|
|
35
|
+
.action(Underpost.repo.clone);
|
|
36
|
+
|
|
37
|
+
program
|
|
38
|
+
.command('pull')
|
|
39
|
+
.argument('<path>', 'Absolute or relative directory')
|
|
40
|
+
.argument(`<uri>`, 'e.g. username/repository')
|
|
41
|
+
.description('Pull github repository')
|
|
42
|
+
.action(Underpost.repo.pull);
|
|
43
|
+
|
|
44
|
+
program
|
|
45
|
+
.command('cmt')
|
|
46
|
+
.argument('<path>', 'Absolute or relative directory')
|
|
47
|
+
.argument(`<commit-type>`, `Options: ${Object.keys(commitData)}`)
|
|
48
|
+
.argument(`[module-tag]`, 'Optional set module tag')
|
|
49
|
+
.argument(`[message]`, 'Optional set additional message')
|
|
50
|
+
.option('--empty', 'Allow empty files')
|
|
51
|
+
.option('--copy', 'Copy to clipboard message')
|
|
52
|
+
.option('--info', 'Info commit types')
|
|
53
|
+
.description('Commit github repository')
|
|
54
|
+
.action(Underpost.repo.commit);
|
|
55
|
+
|
|
56
|
+
program
|
|
57
|
+
.command('push')
|
|
58
|
+
.argument('<path>', 'Absolute or relative directory')
|
|
59
|
+
.argument(`<uri>`, 'e.g. username/repository')
|
|
60
|
+
.option('-f', 'Force push overwriting repository')
|
|
61
|
+
.description('Push github repository')
|
|
62
|
+
.action(Underpost.repo.push);
|
|
63
|
+
|
|
64
|
+
program
|
|
65
|
+
.command('env')
|
|
66
|
+
.argument('<deploy-id>', `deploy configuration id, if 'clean' restore default`)
|
|
67
|
+
.argument('[env]', 'Optional environment, for default is production')
|
|
68
|
+
.description('Set environment variables files and conf related to <deploy-id>')
|
|
69
|
+
.action(loadConf);
|
|
70
|
+
|
|
71
|
+
program
|
|
72
|
+
.command('config')
|
|
73
|
+
.argument('operator', `Options: ${Object.keys(Underpost.env)}`)
|
|
74
|
+
.argument('[key]', 'Config key')
|
|
75
|
+
.argument('[value]', 'Config value')
|
|
76
|
+
.description(`Manage configuration, operators`)
|
|
77
|
+
.action((...args) => Underpost.env[args[0]](args[1], args[2]));
|
|
78
|
+
|
|
79
|
+
program
|
|
80
|
+
.command('root')
|
|
81
|
+
.description('Get npm root path')
|
|
82
|
+
.action(() => console.log(getNpmRootPath()));
|
|
83
|
+
|
|
84
|
+
program
|
|
85
|
+
.command('cluster')
|
|
86
|
+
.option('--reset', `Delete all clusters and prune all data and caches`)
|
|
87
|
+
.option('--mariadb', 'Init with mariadb statefulset')
|
|
88
|
+
.option('--mongodb', 'Init with mongodb statefulset')
|
|
89
|
+
.option('--valkey', 'Init with valkey service')
|
|
90
|
+
.option('--contour', 'Init with project contour base HTTPProxy and envoy')
|
|
91
|
+
.option('--info', 'Get all kinds objects deployed')
|
|
92
|
+
.option('--full', 'Init with all statefulsets and services available')
|
|
93
|
+
.option('--ns-use <ns-name>', 'Switches current context to namespace')
|
|
94
|
+
.action((...args) => {
|
|
95
|
+
if (args[0].reset) return Underpost.cluster.reset();
|
|
96
|
+
return Underpost.cluster.init(args[0]);
|
|
97
|
+
})
|
|
98
|
+
.description('Manage cluster, for default initialization base kind cluster');
|
|
99
|
+
|
|
100
|
+
program
|
|
101
|
+
.command('deploy')
|
|
102
|
+
.argument('<deploy-list>', 'Deploy id list, e.g. default-a,default-b')
|
|
103
|
+
.argument('[env]', 'Optional environment, for default is development')
|
|
104
|
+
.option('--remove', 'Delete deployments and services')
|
|
105
|
+
.option('--sync', 'Sync deployments env, ports, and replicas')
|
|
106
|
+
.option('--info-router', 'Display router structure')
|
|
107
|
+
.option('--build-manifest', 'Build kind yaml manifests: deployments, services, proxy and secrets')
|
|
108
|
+
.description('Manage deployment, for default deploy development pods')
|
|
109
|
+
.action(Underpost.deploy.callback);
|
|
110
|
+
|
|
111
|
+
program
|
|
112
|
+
.command('secret')
|
|
113
|
+
.argument('<platform>', `Options: ${Object.keys(Underpost.secret)}`)
|
|
114
|
+
.option('--init', 'Init secrets platform environment')
|
|
115
|
+
.option('--create-from-file <path-env-file>', 'Create secret from env file')
|
|
116
|
+
.option('--list', 'Lists secrets')
|
|
117
|
+
// .option('--delete [secret-key]', 'Delete key secret, if not set, are default delete all')
|
|
118
|
+
// .option('--create [secret-key] [secret-value]', 'Create secret key, with secret value')
|
|
119
|
+
.description(`Manage secrets`)
|
|
120
|
+
.action((...args) => {
|
|
121
|
+
if (args[1].createFromFile) return Underpost.secret[args[0]].createFromEnvFile(args[1].createFromFile);
|
|
122
|
+
if (args[1].list) return Underpost.secret[args[0]].list();
|
|
123
|
+
if (args[1].init) return Underpost.secret[args[0]].init();
|
|
72
124
|
});
|
|
73
125
|
|
|
74
126
|
program
|
|
75
|
-
.command('
|
|
76
|
-
.
|
|
127
|
+
.command('dockerfile-node-script')
|
|
128
|
+
.argument('<deploy-id>', 'Deploy configuration id')
|
|
129
|
+
.argument('[env]', 'Optional environment, for default is development')
|
|
130
|
+
.option('--run', 'Run custom entry point script')
|
|
131
|
+
.description('Dockerfile custom node build script')
|
|
132
|
+
.action(Underpost.image.dockerfile.script);
|
|
133
|
+
|
|
134
|
+
program
|
|
135
|
+
.command('dockerfile-image-build')
|
|
136
|
+
.argument('<deploy-id>', 'Deploy configuration id')
|
|
137
|
+
.argument('[env]', 'Optional environment, for default is development')
|
|
138
|
+
.argument('[path]', 'Absolute or relative directory, for default is current')
|
|
139
|
+
.option('--image-archive', 'Only load tar image from /images')
|
|
140
|
+
.description('Build image from Dockerfile')
|
|
141
|
+
.action(Underpost.image.dockerfile.build);
|
|
142
|
+
|
|
143
|
+
program
|
|
144
|
+
.command('dockerfile-pull-base-images')
|
|
145
|
+
.description('Pull underpost dockerfile images requirements')
|
|
146
|
+
.action(Underpost.image.dockerfile.pullBaseImages);
|
|
147
|
+
|
|
148
|
+
program
|
|
149
|
+
.command('install')
|
|
150
|
+
.description('Fast import underpost npm dependencies')
|
|
77
151
|
.action(() => {
|
|
78
|
-
|
|
152
|
+
fs.copySync(`${npmRoot}/underpost/node_modules`, './node_modules');
|
|
79
153
|
});
|
|
80
154
|
|
|
155
|
+
program
|
|
156
|
+
.command('db')
|
|
157
|
+
.argument('<deploy-list>', 'Deploy id list, e.g. default-a,default-b')
|
|
158
|
+
.option('--import', 'Import container backups from repositories')
|
|
159
|
+
.option('--export', 'Export container backups to repositories')
|
|
160
|
+
.description('Manage databases')
|
|
161
|
+
.action(UnderpostDB.API.callback);
|
|
162
|
+
|
|
163
|
+
program
|
|
164
|
+
.command('script')
|
|
165
|
+
.argument('operator', `Options: ${Object.keys(UnderpostScript.API)}`)
|
|
166
|
+
.argument('<script-name>', 'Script name')
|
|
167
|
+
.argument('[script-value]', 'Literal command')
|
|
168
|
+
.description(
|
|
169
|
+
'Supports a number of built-in underpost global scripts and their preset life cycle events as well as arbitrary scripts',
|
|
170
|
+
)
|
|
171
|
+
.action((...args) => Underpost.script[args[0]](args[1], args[2]));
|
|
172
|
+
|
|
173
|
+
program
|
|
174
|
+
.command('cron')
|
|
175
|
+
.argument('[deploy-list]', 'Deploy id list, e.g. default-a,default-b')
|
|
176
|
+
.argument('[job-list]', `Deploy id list, e.g. ${Object.keys(UnderpostCron.JOB)}, for default all available jobs`)
|
|
177
|
+
.option('--disable-kind-cluster', 'Disable kind cluster configuration')
|
|
178
|
+
.option('--init', 'Init cron jobs for cron job default deploy id')
|
|
179
|
+
.description('Cron jobs management')
|
|
180
|
+
.action(Underpost.cron.callback);
|
|
181
|
+
|
|
182
|
+
program
|
|
183
|
+
.command('test')
|
|
184
|
+
.argument('[deploy-list]', 'Deploy id list, e.g. default-a,default-b')
|
|
185
|
+
.description('Manage Test, for default run current underpost default test')
|
|
186
|
+
.option('--inside-container', 'Inside container execution context')
|
|
187
|
+
.option('--sh', 'Copy to clipboard, container entrypoint shell command')
|
|
188
|
+
.option('--logs', 'Display container logs')
|
|
189
|
+
.action(Underpost.test.callback);
|
|
190
|
+
|
|
81
191
|
program.parse();
|
package/bin/ssl.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import read from 'read';
|
|
3
|
-
import ncp from 'copy-paste';
|
|
4
3
|
import dotenv from 'dotenv';
|
|
5
|
-
|
|
6
|
-
import { getRootDirectory, shellExec } from '../src/server/process.js';
|
|
4
|
+
import { getRootDirectory, pbcopy, shellExec } from '../src/server/process.js';
|
|
7
5
|
import { loggerFactory } from '../src/server/logger.js';
|
|
8
6
|
import { Cmd, loadConf } from '../src/server/conf.js';
|
|
9
7
|
import { buildSSL } from '../src/server/ssl.js';
|
|
@@ -24,9 +22,9 @@ try {
|
|
|
24
22
|
for (const host of hosts.split(',')) {
|
|
25
23
|
if (host in confServer) {
|
|
26
24
|
const directory = confServer[host]['/']?.['directory'] ? confServer[host]['/']['directory'] : undefined;
|
|
27
|
-
cmd = `certbot certonly --webroot --webroot-path ${
|
|
25
|
+
cmd = `sudo certbot certonly --webroot --webroot-path ${
|
|
28
26
|
directory ? directory : `${getRootDirectory()}/public/${host}`
|
|
29
|
-
} -d ${host}`;
|
|
27
|
+
} --cert-name ${host} -d ${host}`;
|
|
30
28
|
// directory ? directory : `${getRootDirectory()}/public/${host}`
|
|
31
29
|
// directory ? directory : `${getRootDirectory()}/public/www.${host.split('.').slice(-2).join('.')}`
|
|
32
30
|
|
|
@@ -38,16 +36,26 @@ try {
|
|
|
38
36
|
// certbot delete --cert-name <domain>
|
|
39
37
|
|
|
40
38
|
logger.info(`Run the following command`, cmd);
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
try {
|
|
40
|
+
await pbcopy(cmd);
|
|
41
|
+
await read({ prompt: 'Command copy to clipboard, press enter to continue.\n' });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
logger.error(error);
|
|
44
|
+
}
|
|
43
45
|
// Certificate
|
|
44
|
-
await buildSSL(host);
|
|
46
|
+
if (process.argv.includes('build')) await buildSSL(host);
|
|
45
47
|
logger.info('Certificate saved', host);
|
|
46
48
|
} else throw new Error(`host not found: ${host}`);
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
// check for renewal conf:
|
|
51
|
+
// /etc/letsencrypt/renewal
|
|
52
|
+
// /etc/letsencrypt/live
|
|
53
|
+
cmd = `sudo certbot renew --dry-run`;
|
|
54
|
+
try {
|
|
55
|
+
await pbcopy(cmd);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
logger.error(error);
|
|
58
|
+
}
|
|
51
59
|
logger.info(`run the following command for renewal. Command copy to clipboard`, cmd);
|
|
52
60
|
logger.info(`success install SLL`, hosts);
|
|
53
61
|
} catch (error) {
|
package/bin/util.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
|
-
import merge from 'deepmerge';
|
|
3
2
|
import si from 'systeminformation';
|
|
4
3
|
import * as dir from 'path';
|
|
5
4
|
import { svg } from 'font-awesome-assets';
|
|
@@ -7,12 +6,10 @@ import axios from 'axios';
|
|
|
7
6
|
import https from 'https';
|
|
8
7
|
|
|
9
8
|
import { loggerFactory } from '../src/server/logger.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { network } from '../src/server/network.js';
|
|
13
|
-
import { Config } from '../src/server/conf.js';
|
|
9
|
+
import { pbcopy, shellExec } from '../src/server/process.js';
|
|
10
|
+
import { buildKindPorts } from '../src/server/conf.js';
|
|
14
11
|
import { FileFactory } from '../src/api/file/file.service.js';
|
|
15
|
-
import {
|
|
12
|
+
import { faBase64Png, getBufferPngText } from '../src/server/client-icons.js';
|
|
16
13
|
import keyword_extractor from 'keyword-extractor';
|
|
17
14
|
|
|
18
15
|
const httpsAgent = new https.Agent({
|
|
@@ -29,35 +26,10 @@ const operator = process.argv[2];
|
|
|
29
26
|
try {
|
|
30
27
|
// let cmd;
|
|
31
28
|
switch (operator) {
|
|
32
|
-
case 'cls':
|
|
33
|
-
fs.removeSync('./public');
|
|
34
|
-
fs.removeSync('./logs');
|
|
35
|
-
fs.removeSync('./conf');
|
|
36
|
-
// fs.removeSync('./engine-private');
|
|
37
|
-
// fs.removeSync('./node_modules');
|
|
38
|
-
break;
|
|
39
29
|
case 'log':
|
|
40
|
-
(()
|
|
41
|
-
const logPath = `./logs/${process.argv[3]}/${process.argv[4]}.log`;
|
|
42
|
-
logger.info('Read', logPath);
|
|
43
|
-
console.log(fs.readFileSync(logPath, 'utf8'));
|
|
44
|
-
})();
|
|
45
|
-
break;
|
|
46
|
-
case 'kill-ports':
|
|
47
|
-
if (!process.argv[3]) process.argv[3] = '22,80,443,3000-3020';
|
|
48
|
-
for (const port of process.argv[3].split(',')) {
|
|
49
|
-
const rangePort = port.split('-');
|
|
50
|
-
if (rangePort[1])
|
|
51
|
-
for (const port of range(parseInt(rangePort[0]), parseInt(rangePort[1]))) {
|
|
52
|
-
logger.info('clean port', port);
|
|
53
|
-
await network.port.portClean(port);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
logger.info('clean port', parseInt(port));
|
|
57
|
-
await network.port.portClean(port);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
30
|
+
console.log(fs.readFileSync(process.argv[3], 'utf8'));
|
|
60
31
|
break;
|
|
32
|
+
|
|
61
33
|
case 'system-info':
|
|
62
34
|
await (async () => {
|
|
63
35
|
for (const infoKey of Object.keys(si)) {
|
|
@@ -74,56 +46,6 @@ try {
|
|
|
74
46
|
}
|
|
75
47
|
})();
|
|
76
48
|
break;
|
|
77
|
-
case 'export-git-changes':
|
|
78
|
-
{
|
|
79
|
-
const baseFrom = process.argv[3];
|
|
80
|
-
const baseTo = process.argv[4];
|
|
81
|
-
// if (fs.existsSync(baseTo)) fs.removeSync(baseTo);
|
|
82
|
-
shellCd(baseFrom);
|
|
83
|
-
{
|
|
84
|
-
try {
|
|
85
|
-
let output = shellExec('git status', { silent: true, stdout: true });
|
|
86
|
-
console.log('output:', output);
|
|
87
|
-
output = output
|
|
88
|
-
.split(`to discard changes in working directory)`)[1]
|
|
89
|
-
.split(`Untracked files:`)[0]
|
|
90
|
-
.split('modified:')
|
|
91
|
-
.map((c) => c.trim().replaceAll(`\n`, ''));
|
|
92
|
-
output[output.length - 1] = output[output.length - 1].split('no changes added to commit')[0];
|
|
93
|
-
output.shift();
|
|
94
|
-
for (const fromPath of output) {
|
|
95
|
-
const from = `${baseFrom}/${fromPath}`;
|
|
96
|
-
const to = `${baseTo}/${fromPath}`;
|
|
97
|
-
logger.info('Copy path', { from, to });
|
|
98
|
-
fs.copySync(from, to);
|
|
99
|
-
}
|
|
100
|
-
} catch (error) {
|
|
101
|
-
logger.error(error);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
{
|
|
105
|
-
try {
|
|
106
|
-
let output = shellExec('git status', { silent: true, stdout: true });
|
|
107
|
-
console.log('output:', output);
|
|
108
|
-
output = output
|
|
109
|
-
.split(`to include in what will be committed)`)[1]
|
|
110
|
-
.split(`no changes added to commit`)[0]
|
|
111
|
-
.split(`\n`)
|
|
112
|
-
.map((l) => l.trim())
|
|
113
|
-
.filter((l) => l);
|
|
114
|
-
|
|
115
|
-
for (const fromPath of output) {
|
|
116
|
-
const from = `${baseFrom}/${fromPath}`;
|
|
117
|
-
const to = `${baseTo}/${fromPath}`;
|
|
118
|
-
logger.info('Copy path', { from, to });
|
|
119
|
-
fs.copySync(from, to);
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
logger.error(error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
break;
|
|
127
49
|
case 'delete-empty-folder':
|
|
128
50
|
function cleanEmptyFoldersRecursively(folder) {
|
|
129
51
|
if (!fs.existsSync(folder)) {
|
|
@@ -190,20 +112,6 @@ try {
|
|
|
190
112
|
fs.writeFileSync('b64-image', `data:image/jpg;base64,${fs.readFileSync(process.argv[3]).toString('base64')}`);
|
|
191
113
|
break;
|
|
192
114
|
|
|
193
|
-
case 'get-ip': {
|
|
194
|
-
const response = await axios.get(process.argv[3]);
|
|
195
|
-
logger.info(process.argv[3] + ' IP', response.request.socket.remoteAddress);
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
case 'clean-env': {
|
|
200
|
-
shellExec(`git checkout package.json`);
|
|
201
|
-
shellExec(`git checkout .env.production`);
|
|
202
|
-
shellExec(`git checkout .env.development`);
|
|
203
|
-
shellExec(`git checkout .env.test`);
|
|
204
|
-
shellExec(`git checkout jsdoc.json`);
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
115
|
case 'get-keys': {
|
|
208
116
|
const sentence = fs.existsSync('./_')
|
|
209
117
|
? fs.readFileSync('./_', 'utf8')
|
|
@@ -222,6 +130,10 @@ try {
|
|
|
222
130
|
console.log(extraction_result.join(', '));
|
|
223
131
|
break;
|
|
224
132
|
}
|
|
133
|
+
|
|
134
|
+
case 'build-ports': {
|
|
135
|
+
pbcopy(buildKindPorts(process.argv[3], process.argv[4]));
|
|
136
|
+
}
|
|
225
137
|
default:
|
|
226
138
|
break;
|
|
227
139
|
}
|
package/bin/vs.js
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import { shellExec } from '../src/server/process.js';
|
|
3
|
+
import { loggerFactory } from '../src/server/logger.js';
|
|
4
|
+
|
|
5
|
+
const logger = loggerFactory(import.meta);
|
|
3
6
|
|
|
4
7
|
switch (process.argv[2]) {
|
|
8
|
+
case 'info': {
|
|
9
|
+
logger.info('Formatted', 'Ctrl shift I');
|
|
10
|
+
logger.info('Command', 'Ctrl shift P');
|
|
11
|
+
logger.info('Search', 'Ctrl shift F');
|
|
12
|
+
logger.info('Debug', 'Ctrl shift D');
|
|
13
|
+
logger.info('New File', 'Ctrl N');
|
|
14
|
+
logger.info('Change tab', 'Ctrl Tab');
|
|
15
|
+
logger.info('Fold All', 'Ctrl K + Ctrl 0');
|
|
16
|
+
logger.info('Unfold All', 'Ctrl K + Ctrl J');
|
|
17
|
+
logger.info('Close All tabs', 'Ctrl K + W');
|
|
18
|
+
logger.info('Go to line number', 'Ctrl G');
|
|
19
|
+
logger.info('Change current project folder', 'Ctrl K + Ctrl O');
|
|
20
|
+
logger.info('Open new vs windows', 'Ctrl Shift N');
|
|
21
|
+
logger.info('Close current vs windows', 'Ctrl Shift W');
|
|
22
|
+
logger.info('Preview md', 'Ctrl shift V');
|
|
23
|
+
logger.warn('Terminal shortcut configure with command pallette', 'Ctl shift T');
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
5
26
|
case 'import':
|
|
6
27
|
{
|
|
7
28
|
const extensions = JSON.parse(fs.readFileSync(`./.vscode/extensions.json`, 'utf8'));
|
|
8
29
|
extensions.recommendations.map((extension) => {
|
|
9
|
-
if (extension)
|
|
30
|
+
if (extension)
|
|
31
|
+
shellExec(`sudo code --user-data-dir="/root/.vscode-root" --no-sandbox --install-extension ${extension}`);
|
|
10
32
|
});
|
|
11
33
|
}
|
|
12
34
|
break;
|
|
13
35
|
case 'export':
|
|
14
36
|
{
|
|
15
|
-
shellExec(`code --list-extensions > vs-extensions.txt`);
|
|
37
|
+
shellExec(`sudo code --user-data-dir="/root/.vscode-root" --no-sandbox --list-extensions > vs-extensions.txt`);
|
|
16
38
|
fs.writeFileSync(
|
|
17
39
|
`./.vscode/extensions.json`,
|
|
18
40
|
JSON.stringify(
|
|
@@ -31,5 +53,6 @@ switch (process.argv[2]) {
|
|
|
31
53
|
}
|
|
32
54
|
break;
|
|
33
55
|
default:
|
|
56
|
+
shellExec(`sudo code ${process.argv[2]} --user-data-dir="/root/.vscode-root" --no-sandbox`);
|
|
34
57
|
break;
|
|
35
58
|
}
|