adminforth 1.0.8 → 1.0.10

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.
@@ -11,6 +11,11 @@ class PostgresConnector {
11
11
  });
12
12
  (async () => {
13
13
  await this.db.connect();
14
+ this.db.on('error', (err) => {
15
+ console.log('Postgres error: ', err.message, err.stack)
16
+ this.db.end();
17
+ this.db = new PostgresConnector({ url }).db;
18
+ });
14
19
  })();
15
20
  }
16
21
 
@@ -6,17 +6,19 @@ import { promisify } from 'util';
6
6
  import path from 'path';
7
7
  import { fileURLToPath } from 'url';
8
8
  import crypto from 'crypto';
9
+ import os from 'os';
9
10
 
10
11
 
11
12
  const __filename = fileURLToPath(import.meta.url);
12
13
  const __dirname = path.join(path.dirname(__filename), '..');
13
14
 
14
- // const SPA_TMP_PATH = path.join(__dirname, 'spa_tmp');
15
+ let TMP_DIR;
15
16
 
16
- // folder in /tmp directory to store SPA sources
17
- const SPA_TMP_PATH = path.join('/tmp', 'adminforth', 'spa_tmp');
18
- // make sure the folder exists
19
- fsExtra.ensureDirSync(SPA_TMP_PATH);
17
+ try {
18
+ TMP_DIR = os.tmpdir();
19
+ } catch (e) {
20
+ TMP_DIR = '/tmp';
21
+ }
20
22
 
21
23
 
22
24
  const execAsync = promisify(exec);
@@ -27,6 +29,9 @@ function hashify(obj) {
27
29
  }
28
30
 
29
31
  class CodeInjector {
32
+
33
+ static SPA_TMP_PATH = path.join(TMP_DIR, 'adminforth', 'spa_tmp');
34
+
30
35
  constructor(adminforth) {
31
36
  this.adminforth = adminforth;
32
37
  }
@@ -65,7 +70,7 @@ class CodeInjector {
65
70
 
66
71
  async rmTmpDir() {
67
72
  // remove spa_tmp folder if it is exists
68
- const spaTmpPath = SPA_TMP_PATH;
73
+ const spaTmpPath = CodeInjector.SPA_TMP_PATH;
69
74
  try {
70
75
  await fs.promises.rm(spaTmpPath, { recursive: true });
71
76
  } catch (e) {
@@ -74,7 +79,13 @@ class CodeInjector {
74
79
  }
75
80
 
76
81
  async prepareSources({ filesUpdated, verbose = false }) {
77
- const spaTmpPath = SPA_TMP_PATH;
82
+ const spaTmpPath = CodeInjector.SPA_TMP_PATH;
83
+ // check SPA_TMP_PATH exists and create if not
84
+ try {
85
+ await fs.promises.access(spaTmpPath, fs.constants.F_OK);
86
+ } catch (e) {
87
+ await fs.promises.mkdir(spaTmpPath, { recursive: true });
88
+ }
78
89
 
79
90
  const customFiles = [];
80
91
  const icons = [];
@@ -282,10 +293,11 @@ class CodeInjector {
282
293
  await this.watchForReprepare();
283
294
  console.log('AdminForth bundling');
284
295
 
285
- const cwd = SPA_TMP_PATH;
296
+ const cwd = CodeInjector.SPA_TMP_PATH;
286
297
 
287
298
  if (!hotReload) {
288
- await this.runNpmShell({command: 'run build', verbose, cwd});
299
+ // probably add option to build with tsh check (plain 'build')
300
+ await this.runNpmShell({command: 'run build-only', verbose, cwd});
289
301
  } else {
290
302
  const command = 'run dev';
291
303
  console.time(`Running npm ${command}...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,6 +2,7 @@
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
4
  import fs from 'fs';
5
+ import CodeInjector from '../modules/codeInjector.js';
5
6
 
6
7
  const __filename = fileURLToPath(import.meta.url);
7
8
  const __dirname = path.dirname(__filename);
@@ -104,11 +105,11 @@ class ExpressServer {
104
105
 
105
106
  } else {
106
107
  this.expressApp.get(`${slashedPrefix}assets/*`, (req, res) => {
107
- res.sendFile(path.join(__dirname, '..', 'spa', 'dist', replaceAtStart(req.url, prefix)))
108
+ res.sendFile(path.join(CodeInjector.SPA_TMP_PATH, 'dist', replaceAtStart(req.url, prefix)))
108
109
  })
109
110
 
110
111
  this.expressApp.get(`${prefix}*`, async (req, res) => {
111
- const fullPath = path.join(__dirname, '..', 'spa', 'dist', 'index.html');
112
+ const fullPath = path.join(CodeInjector.SPA_TMP_PATH, 'dist', 'index.html');
112
113
 
113
114
  let fileExists = true;
114
115
  try {
@@ -116,7 +117,6 @@ class ExpressServer {
116
117
  } catch (e) {
117
118
  fileExists = false;
118
119
  }
119
- console.log('fileExists', fileExists);
120
120
  if (!fileExists) {
121
121
  res.status(500).send(respondNoServer(`${this.adminforth.config.brandName} is still warming up`, 'Please wait a moment...'));
122
122
  return;