@opengis/admin 0.1.7 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -16,14 +16,14 @@ async function plugin(fastify) {
16
16
  server: {
17
17
  middlewareMode: true,
18
18
  },
19
- });
19
+ });
20
20
  // hot reload
21
- viteServer.watcher.on('all', function (d, t) {
22
- if (!t.includes('module')) return;
21
+ viteServer.watcher.on('all', function (d, t) {
22
+ if (!t.includes('module')) return;
23
23
  console.log(d, t);
24
- viteServer.ws.send({type: 'full-reload' });
24
+ viteServer.ws.send({ type: 'full-reload' });
25
25
  });
26
-
26
+
27
27
  // this is middleware for vite's dev servert
28
28
  fastify.addHook('onRequest', async (req, reply) => {
29
29
  const { user } = req.session?.passport || {};
@@ -1,8 +1,9 @@
1
- import { readdir, readFile } from 'fs/promises';
1
+
2
2
  import { join } from 'path';
3
+ import { readFile } from 'fs/promises';
3
4
  import userTemplateDir from '@opengis/fastify-table/table/controllers/utils/userTemplateDir.js'
4
- import { existsSync, readdirSync } from 'fs';
5
-
5
+ import { existsSync, readdirSync, readFileSync } from 'fs';
6
+ const menuCache = [];
6
7
  // check module dir
7
8
  const moduleDir = join(process.cwd(), 'module');
8
9
  const dirs = existsSync(moduleDir) ?
@@ -15,10 +16,11 @@ const menuList = dirs.concat(userTemplateDir)
15
16
 
16
17
 
17
18
  const isProduction = process.env.NODE_ENV === 'production';
18
- const menuCache = []
19
+ readMenu();
19
20
 
20
21
  async function readMenu() {
21
- const list = await Promise.all(menuList.map(el => readFile(el, 'utf-8')));
22
+ // const list = menuList.map(el => readFileSync(el, 'utf-8')); // sync
23
+ const list = await Promise.all(menuList.map(el => readFileSync(el, 'utf-8'))); // sync
22
24
  const menus = list.reduce((p, el) => p.concat(JSON.parse(el)), [])
23
25
  .map(el => ({ order: 0, ...el }))
24
26
  .sort((a, b) => (a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0))
@@ -28,6 +30,5 @@ async function readMenu() {
28
30
  }
29
31
  export default async function adminMenu() {
30
32
  const menus = isProduction && menuCache.length ? menuCache : await readMenu();
31
-
32
33
  return menus;
33
34
  }