underpost 2.8.42 → 2.8.44

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.
@@ -113,5 +113,8 @@
113
113
  "editor.defaultFormatter": "foxundermoon.shell-format"
114
114
  },
115
115
  "docwriter.progress.trackTypes": true,
116
- "docwriter.hotkey.mac": "⌘ + ."
116
+ "docwriter.hotkey.mac": "⌘ + .",
117
+ "[dotenv]": {
118
+ "editor.defaultFormatter": "foxundermoon.shell-format"
119
+ }
117
120
  }
package/Dockerfile CHANGED
@@ -32,7 +32,7 @@ COPY supervisord-openssh-server.conf /etc/supervisor/conf.d/supervisord-openssh-
32
32
  RUN apt-get install -yq --no-install-recommends libssl-dev curl wget git gnupg
33
33
 
34
34
  # install nodejs https://github.com/nodesource/distributions/blob/master/README.md#deb
35
- RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
35
+ RUN curl -fsSL https://deb.nodesource.com/setup_23.x | bash -
36
36
  RUN apt-get install -y nodejs build-essential
37
37
  RUN node --version
38
38
  RUN npm --version
package/bin/deploy.js CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  restoreMacroDb,
27
27
  fixDependencies,
28
28
  setUpProxyMaintenanceServer,
29
+ writeEnv,
29
30
  } from '../src/server/conf.js';
30
31
  import { buildClient } from '../src/server/client-build.js';
31
32
  import { range, setPad, timer, uniqueArray } from '../src/client/components/core/CommonJs.js';
@@ -546,13 +547,7 @@ try {
546
547
  ? envInstanceObj.port
547
548
  : envInstanceObj.port + port - singleReplicaHosts.length - (replicaHost ? 1 : 0);
548
549
 
549
- fs.writeFileSync(
550
- envPath,
551
- Object.keys(envObj)
552
- .map((key) => `${key}=${envObj[key]}`)
553
- .join(`\n`),
554
- 'utf8',
555
- );
550
+ writeEnv(envPath, envObj);
556
551
  }
557
552
  const serverConf = loadReplicas(
558
553
  JSON.parse(fs.readFileSync(`${baseConfPath}/${deployId}/conf.server.json`, 'utf8')),
package/bin/index.js CHANGED
@@ -1,12 +1,24 @@
1
1
  #! /usr/bin/env node
2
2
 
3
3
  import dotenv from 'dotenv';
4
- import { shellCd, shellExec } from '../src/server/process.js';
5
4
  import { Command } from 'commander';
6
- import { actionInitLog, loggerFactory } from '../src/server/logger.js';
5
+ import { loggerFactory } from '../src/server/logger.js';
7
6
  import Underpost from '../src/index.js';
7
+ import {
8
+ getNpmRootPath,
9
+ loadConf,
10
+ newProject,
11
+ repoClone,
12
+ repoCommit,
13
+ repoPull,
14
+ repoPush,
15
+ UnderpostRootEnv,
16
+ } from '../src/server/conf.js';
17
+ import fs from 'fs-extra';
8
18
 
9
- dotenv.config();
19
+ const npmRoot = getNpmRootPath();
20
+ const underpostRoot = `${npmRoot}/underpost/.env`;
21
+ fs.existsSync(underpostRoot) ? dotenv.config({ path: underpostRoot, override: true }) : dotenv.config();
10
22
 
11
23
  const logger = loggerFactory(import.meta);
12
24
 
@@ -17,17 +29,17 @@ program.name('underpost').description(`underpost.net ci/cd cli ${Underpost.versi
17
29
  program
18
30
  .command('new <app-name>')
19
31
  .description('Create a new project')
20
- .action((...args) => ((args[1] = Underpost.version), new Underpost.project(...args)));
32
+ .action((...args) => ((args[1] = Underpost.version), newProject(...args)));
21
33
 
22
34
  program
23
35
  .command('clone <uri>')
24
36
  .description('Clone github repository, if your GITHUB_TOKEN environment exists, it will be used')
25
- .action(Underpost.project.clone);
37
+ .action(repoClone);
26
38
 
27
39
  program
28
40
  .command('pull <path> <uri>')
29
41
  .description('Pull github repository, if your GITHUB_TOKEN environment exists, it will be used')
30
- .action(Underpost.project.pull);
42
+ .action(repoPull);
31
43
 
32
44
  program
33
45
  .option('--copy')
@@ -37,17 +49,27 @@ program
37
49
  .description(
38
50
  'Commit github repository, if your GITHUB_TOKEN environment exists, it will be used, use --copy will copy to clipboard message, use --info will see info commit types, use --empty will allow empty files',
39
51
  )
40
- .action((...args) => ((args[4] = options), Underpost.project.commit(...args)));
52
+ .action((...args) => ((args[4] = options), repoCommit(...args)));
41
53
 
42
54
  program
43
55
  .command('push <path> <uri>')
44
56
  .description('Push github repository, if your GITHUB_TOKEN environment exists, it will be used')
45
- .action(Underpost.project.push);
57
+ .action(repoPush);
46
58
 
47
59
  program
48
60
  .command('env <deploy-id> [env]')
49
61
  .description('Set environment variables files and conf related to <deploy-id>')
50
- .action(Underpost.project.useEnv);
62
+ .action(loadConf);
63
+
64
+ program
65
+ .command('config <operator> [key] [value]')
66
+ .description(`Manage configuration, operators available: ${Object.keys(UnderpostRootEnv)}`)
67
+ .action((...args) => UnderpostRootEnv[args[0]](args[1], args[2]));
68
+
69
+ program
70
+ .command('root')
71
+ .description('Get npm root path')
72
+ .action(() => console.log(getNpmRootPath()));
51
73
 
52
74
  program.command('test').description('Run tests').action(Underpost.runTest);
53
75
 
@@ -58,7 +58,7 @@ services:
58
58
  cpus: '0.25'
59
59
  memory: 20M
60
60
  labels: # labels in Compose file instead of Dockerfile
61
- engine.version: '2.8.42'
61
+ engine.version: '2.8.44'
62
62
  networks:
63
63
  - load-balancer
64
64
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "main": "src/index.js",
4
4
  "name": "underpost",
5
- "version": "2.8.42",
5
+ "version": "2.8.44",
6
6
  "description": "pwa api rest template",
7
7
  "scripts": {
8
8
  "start": "env-cmd -f .env.production node --max-old-space-size=8192 src/server",
@@ -106,10 +106,10 @@ SrrComponent = ({ ttiLoadTimeLimit }) => {
106
106
  </style>
107
107
  ${borderChar(1, 'black', ['.clean-cache-container'])}
108
108
  <script>
109
- window._VERSION = '${process.env.npm_package_version}';
109
+ window._VERSION = '${npm_package_version}';
110
110
  const CacheControl = ${CacheControl};
111
111
  CacheControl({ ttiLoadTimeLimit: ${ttiLoadTimeLimit ? ttiLoadTimeLimit : 1000 * 70 * 1} });
112
112
  </script>
113
- <div class="clean-cache-container">${process.env.npm_package_version}</div>
113
+ <div class="clean-cache-container">${npm_package_version}</div>
114
114
  `;
115
115
  };
package/src/index.js CHANGED
@@ -6,7 +6,6 @@
6
6
 
7
7
  import { runTest } from './server/conf.js';
8
8
  import { loggerFactory, setUpInfo } from './server/logger.js';
9
- import Project from './server/project.js';
10
9
 
11
10
  const logger = loggerFactory(import.meta);
12
11
 
@@ -22,8 +21,7 @@ class Underpost {
22
21
  * @type {String}
23
22
  * @memberof Underpost
24
23
  */
25
- static version = 'v2.8.42';
26
- static project = Project;
24
+ static version = 'v2.8.44';
27
25
 
28
26
  constructor() {}
29
27
 
@@ -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 };
@@ -127,7 +127,11 @@ const loadConf = (deployId, envInput) => {
127
127
  ...env,
128
128
  };
129
129
  }
130
- fs.writeFileSync(`./package.json`, fs.readFileSync(`${folder}/package.json`, 'utf8'), 'utf8');
130
+ const originPackageJson = JSON.parse(fs.readFileSync(`./package.json`, 'utf8'));
131
+ const packageJson = JSON.parse(fs.readFileSync(`${folder}/package.json`, 'utf8'));
132
+ originPackageJson.scripts.start = packageJson.scripts.start;
133
+ packageJson.scripts = originPackageJson.scripts;
134
+ fs.writeFileSync(`./package.json`, JSON.stringify(packageJson, null, 4), 'utf8');
131
135
  return { folder, deployId };
132
136
  };
133
137
 
@@ -1164,6 +1168,8 @@ const repoPush = (repoPath = './', gitUri = 'underpostnet/pwa-microservices-temp
1164
1168
  const getNpmRootPath = () =>
1165
1169
  shellExec(`npm root -g`, {
1166
1170
  stdout: true,
1171
+ disableLog: true,
1172
+ silent: true,
1167
1173
  }).trim();
1168
1174
 
1169
1175
  const newProject = (repositoryName, version) => {
@@ -1197,6 +1203,55 @@ const runTest = (version) => {
1197
1203
  shellExec(`cd ${getNpmRootPath()}/underpost && npm run test`);
1198
1204
  };
1199
1205
 
1206
+ const writeEnv = (envPath, envObj) =>
1207
+ fs.writeFileSync(
1208
+ envPath,
1209
+ Object.keys(envObj)
1210
+ .map((key) => `${key}=${envObj[key]}`)
1211
+ .join(`\n`),
1212
+ 'utf8',
1213
+ );
1214
+
1215
+ const UnderpostRootEnv = {
1216
+ set: (key, value) => {
1217
+ const exeRootPath = `${getNpmRootPath()}/underpost`;
1218
+ const envPath = `${exeRootPath}/.env`;
1219
+ let env = {};
1220
+ if (fs.existsSync(envPath)) env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
1221
+ env[key] = value;
1222
+ writeEnv(envPath, env);
1223
+ },
1224
+ delete: (key, value) => {
1225
+ const exeRootPath = `${getNpmRootPath()}/underpost`;
1226
+ const envPath = `${exeRootPath}/.env`;
1227
+ let env = {};
1228
+ if (fs.existsSync(envPath)) env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
1229
+ delete env[key];
1230
+ writeEnv(envPath, env);
1231
+ },
1232
+ get: (key) => {
1233
+ const exeRootPath = `${getNpmRootPath()}/underpost`;
1234
+ const envPath = `${exeRootPath}/.env`;
1235
+ if (!fs.existsSync(envPath)) return logger.error(`Unable to find underpost root environment`);
1236
+ const env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
1237
+ logger.info('underpost root', { [key]: env[key] });
1238
+ return env[key];
1239
+ },
1240
+ list: () => {
1241
+ const exeRootPath = `${getNpmRootPath()}/underpost`;
1242
+ const envPath = `${exeRootPath}/.env`;
1243
+ if (!fs.existsSync(envPath)) return logger.error(`Unable to find underpost root environment`);
1244
+ const env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
1245
+ logger.info('underpost root', env);
1246
+ return env;
1247
+ },
1248
+ clean: () => {
1249
+ const exeRootPath = `${getNpmRootPath()}/underpost`;
1250
+ const envPath = `${exeRootPath}/.env`;
1251
+ fs.removeSync(envPath);
1252
+ },
1253
+ };
1254
+
1200
1255
  export {
1201
1256
  Cmd,
1202
1257
  Config,
@@ -1239,4 +1294,6 @@ export {
1239
1294
  newProject,
1240
1295
  runTest,
1241
1296
  getNpmRootPath,
1297
+ writeEnv,
1298
+ UnderpostRootEnv,
1242
1299
  };
@@ -112,10 +112,10 @@ const loggerFactory = (meta = { url: '' }) => {
112
112
  // Allow the use the terminal to print the messages
113
113
  new winston.transports.Console(),
114
114
  // Allow to print all the error level messages inside the error.log file
115
- new winston.transports.File({
116
- filename: `logs/${meta}/error.log`,
117
- level: 'error',
118
- }),
115
+ // new winston.transports.File({
116
+ // filename: `logs/${meta}/error.log`,
117
+ // level: 'error',
118
+ // }),
119
119
  // Allow to print all the error message inside the all.log file
120
120
  // (also the error log that are also printed inside the error.log(
121
121
  new winston.transports.File({ filename: `logs/${meta}/all.log` }),
@@ -15,7 +15,7 @@ import { getCapVariableName, newInstance } from '../client/components/core/Commo
15
15
  import { Xampp } from '../runtime/xampp/Xampp.js';
16
16
  import { MailerProvider } from '../mailer/MailerProvider.js';
17
17
  import { DataBaseProvider } from '../db/DataBaseProvider.js';
18
- import { createProxyMiddleware } from 'http-proxy-middleware';
18
+ // import { createProxyMiddleware } from 'http-proxy-middleware';
19
19
  import { createPeerServer } from './peer.js';
20
20
  import { Lampp } from '../runtime/lampp/Lampp.js';
21
21
  import { getDeployId } from './conf.js';
@@ -31,20 +31,6 @@ const buildRuntime = async () => {
31
31
  const collectDefaultMetrics = promClient.collectDefaultMetrics;
32
32
  collectDefaultMetrics();
33
33
 
34
- if (fs.existsSync(`/root/.bashrc`) && !fs.readFileSync(`/root/.bashrc`, 'utf8').match(`underpost-engine`)) {
35
- fs.writeFileSync(
36
- `/root/.bashrc`,
37
- `${fs.readFileSync(`/root/.bashrc`, 'utf8')}
38
- ` +
39
- `export NVM_DIR="$HOME/.nvm"
40
- [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
41
- [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm underpost-engine bash_completion
42
-
43
- export PATH=$PATH:/opt/lampp/bin`,
44
- 'utf8',
45
- );
46
- }
47
-
48
34
  const promCounterOption = {
49
35
  name: `${deployId.replaceAll('-', '_')}_http_requests_total`,
50
36
  help: 'Total number of HTTP requests',
@@ -54,7 +40,6 @@ export PATH=$PATH:/opt/lampp/bin`,
54
40
  // logger.info('promCounterOption', promCounterOption);
55
41
 
56
42
  const requestCounter = new promClient.Counter(promCounterOption);
57
-
58
43
  const ipInstance = ''; // await ip.public.ipv4();
59
44
  const initPort = parseInt(process.env.PORT) + 1;
60
45
  let currentPort = initPort;
@@ -101,12 +86,13 @@ export PATH=$PATH:/opt/lampp/bin`,
101
86
  apis,
102
87
  };
103
88
 
104
- let redirectUrl;
105
- let redirectTarget;
106
- if (redirect) {
107
- redirectUrl = new URL(redirect);
108
- redirectTarget = redirect[redirect.length - 1] === '/' ? redirect.slice(0, -1) : redirect;
109
- }
89
+ const redirectTarget = redirect
90
+ ? redirect[redirect.length - 1] === '/'
91
+ ? redirect.slice(0, -1)
92
+ : redirect
93
+ : undefined;
94
+
95
+ // if (redirect) logger.info('redirect', new URL(redirect));
110
96
 
111
97
  switch (runtime) {
112
98
  case 'lampp':
@@ -1,39 +0,0 @@
1
- import { loadConf, newProject, repoClone, repoCommit, repoPull, repoPush } from './conf.js';
2
-
3
- class Project {
4
- constructor(repositoryName, version) {
5
- return newProject(repositoryName, version);
6
- }
7
-
8
- static clone(gitUri = 'underpostnet/pwa-microservices-template') {
9
- return repoClone(gitUri);
10
- }
11
-
12
- static useEnv(deployId = 'default', env = 'production') {
13
- return loadConf(deployId, env);
14
- }
15
-
16
- static pull(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') {
17
- return repoPull(repoPath, gitUri);
18
- }
19
-
20
- static commit(
21
- repoPath = './',
22
- commitType = 'feat',
23
- subModule = '',
24
- message = '',
25
- options = {
26
- copy: false,
27
- info: false,
28
- empty: false,
29
- },
30
- ) {
31
- return repoCommit(repoPath, commitType, subModule, message, options);
32
- }
33
-
34
- static push(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') {
35
- return repoPush(repoPath, gitUri);
36
- }
37
- }
38
-
39
- export default Project;