adminforth 1.0.59 → 1.0.61

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.
@@ -84,17 +84,49 @@ class CodeInjector {
84
84
  }
85
85
  const icons = [];
86
86
  let routes = '';
87
+ let routerComponents = '';
87
88
  const collectAssetsFromMenu = (menu) => {
88
89
  menu.forEach((item) => {
89
90
  if (item.icon) {
90
91
  icons.push(item.icon);
91
92
  }
92
93
  if (item.component) {
93
- routes += `{
94
- path: '${item.path}',
95
- name: '${item.path}',
96
- component: () => import('${item.component}'),
97
- },\n`;
94
+ if (Object.keys(item).includes('isStaticRoute')) {
95
+ if (!item.isStaticRoute) {
96
+ routes += `{
97
+ path: '${item.path}',
98
+ name: '${item.path}',
99
+ component: () => import('${item.component}'),
100
+ },\n`;
101
+ }
102
+ else {
103
+ routes += `{
104
+ path: '${item.path}',
105
+ name: '${item.path}',
106
+ component: ${getComponentNameFromPath(item.component)},
107
+ },\n`;
108
+ const componentName = `${getComponentNameFromPath(item.component)}`;
109
+ routerComponents += `import ${componentName} from '${item.component}';\n`;
110
+ }
111
+ }
112
+ else {
113
+ if (item.homepage) {
114
+ routes += `{
115
+ path: '${item.path}',
116
+ name: '${item.path}',
117
+ component: ${getComponentNameFromPath(item.component)},
118
+ },\n`;
119
+ const componentName = `${getComponentNameFromPath(item.component)}`;
120
+ routerComponents += `import ${componentName} from '${item.component}';\n`;
121
+ }
122
+ else {
123
+ routes += `{
124
+ path: '${item.path}',
125
+ name: '${item.path}',
126
+ component: () => import('${item.component}'),
127
+ },\n`;
128
+ }
129
+ }
98
130
  }
99
131
  if (item.children) {
100
132
  collectAssetsFromMenu(item.children);
@@ -222,6 +254,9 @@ class CodeInjector {
222
254
  tailwindConfigContent = tailwindConfigContent.replace('/* IMPORTANT:ADMINFORTH TAILWIND STYLES */', stylesText);
223
255
  yield fs.promises.writeFile(tailwindConfigPath, tailwindConfigContent);
224
256
  }
257
+ const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
258
+ let routerVueContent = yield fs.promises.readFile(routerVuePath, 'utf-8');
259
+ routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES IMPORTS */', routerComponents);
225
260
  /* generate custom routes */
226
261
  const homepageMenuItem = this.adminforth.config.menu.find((mi) => mi.homepage);
227
262
  let childrenHomePageMenuItem = this.adminforth.config.menu.find((mi) => { var _a; return mi.children && ((_a = mi.children) === null || _a === void 0 ? void 0 : _a.find((mi) => mi.homepage)); });
@@ -236,8 +271,6 @@ class CodeInjector {
236
271
  //redirect to login
237
272
  redirect: '${homePagePath}'
238
273
  },\n`;
239
- const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
240
- let routerVueContent = yield fs.promises.readFile(routerVuePath, 'utf-8');
241
274
  routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES */', routes);
242
275
  yield fs.promises.writeFile(routerVuePath, routerVueContent);
243
276
  /* hash checking */
@@ -16,8 +16,8 @@ export function guessLabelFromName(name) {
16
16
  export const currentFileDir = (metaUrl) => {
17
17
  const __filename = fileURLToPath(metaUrl);
18
18
  let __dirname = path.dirname(__filename);
19
- if (__dirname.endsWith('dist')) {
20
- // in prod build we are in dist also
19
+ if (__dirname.endsWith('/dist/modules')) {
20
+ // in prod build we are in dist also, so make another back jump to go true sorces
21
21
  __dirname = path.join(__dirname, '..');
22
22
  }
23
23
  return __dirname;
@@ -26,5 +26,5 @@ export const ADMIN_FORTH_ABSOLUTE_PATH = path.join(currentFileDir(import.meta.ur
26
26
  const package_json = JSON.parse(fs.readFileSync(path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'package.json'), 'utf8'));
27
27
  export const ADMINFORTH_VERSION = package_json.version;
28
28
  export function getComponentNameFromPath(filePath) {
29
- return filePath.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
29
+ return filePath.replace(/@/g, '').replace(/.vue/g, '').replace(/\./g, '').replace(/\//g, '');
30
30
  }
@@ -1,5 +1,6 @@
1
1
  import { createRouter, createWebHistory } from 'vue-router'
2
2
  import ResourceParent from '@/views/ResourceParent.vue'
3
+ /* IMPORTANT:ADMINFORTH ROUTES IMPORTS */
3
4
 
4
5
  const router = createRouter({
5
6
  history: createWebHistory(import.meta.env.BASE_URL),
@@ -92,18 +92,50 @@ class CodeInjector {
92
92
 
93
93
  const icons = [];
94
94
  let routes = '';
95
+ let routerComponents = '';
95
96
 
96
97
  const collectAssetsFromMenu = (menu) => {
97
98
  menu.forEach((item) => {
98
99
  if (item.icon) {
99
100
  icons.push(item.icon);
100
101
  }
102
+
101
103
  if (item.component) {
102
- routes += `{
103
- path: '${item.path}',
104
- name: '${item.path}',
105
- component: () => import('${item.component}'),
106
- },\n`
104
+ if(Object.keys(item).includes('isStaticRoute')){
105
+ if(!item.isStaticRoute){
106
+ routes += `{
107
+ path: '${item.path}',
108
+ name: '${item.path}',
109
+ component: () => import('${item.component}'),
110
+ },\n`} else {
111
+ routes += `{
112
+ path: '${item.path}',
113
+ name: '${item.path}',
114
+ component: ${getComponentNameFromPath(item.component)},
115
+ },\n`
116
+ const componentName = `${getComponentNameFromPath(item.component)}`;
117
+ routerComponents += `import ${componentName} from '${item.component}';\n`;
118
+ }
119
+ } else{
120
+ if(item.homepage){
121
+ routes += `{
122
+ path: '${item.path}',
123
+ name: '${item.path}',
124
+ component: ${getComponentNameFromPath(item.component)},
125
+ },\n`
126
+ const componentName = `${getComponentNameFromPath(item.component)}`;
127
+ routerComponents += `import ${componentName} from '${item.component}';\n`;}
128
+ else {
129
+ routes += `{
130
+ path: '${item.path}',
131
+ name: '${item.path}',
132
+ component: () => import('${item.component}'),
133
+ },\n`
134
+
135
+ }
136
+
137
+ }
138
+
107
139
  }
108
140
  if (item.children) {
109
141
  collectAssetsFromMenu(item.children);
@@ -257,6 +289,12 @@ class CodeInjector {
257
289
  }
258
290
 
259
291
 
292
+ const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
293
+
294
+ let routerVueContent = await fs.promises.readFile(routerVuePath, 'utf-8');
295
+ routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES IMPORTS */', routerComponents);
296
+
297
+
260
298
 
261
299
  /* generate custom routes */
262
300
  const homepageMenuItem = this.adminforth.config.menu.find((mi)=>mi.homepage);
@@ -273,8 +311,6 @@ class CodeInjector {
273
311
  //redirect to login
274
312
  redirect: '${homePagePath}'
275
313
  },\n`;
276
- const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
277
- let routerVueContent = await fs.promises.readFile(routerVuePath, 'utf-8');
278
314
  routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES */', routes);
279
315
  await fs.promises.writeFile(routerVuePath, routerVueContent);
280
316
 
package/modules/utils.ts CHANGED
@@ -18,8 +18,8 @@ export function guessLabelFromName(name) {
18
18
  export const currentFileDir = (metaUrl) => {
19
19
  const __filename = fileURLToPath(metaUrl);
20
20
  let __dirname = path.dirname(__filename);
21
- if (__dirname.endsWith('dist')) {
22
- // in prod build we are in dist also
21
+ if (__dirname.endsWith('/dist/modules')) {
22
+ // in prod build we are in dist also, so make another back jump to go true sorces
23
23
  __dirname = path.join(__dirname, '..');
24
24
  }
25
25
  return __dirname;
@@ -32,5 +32,5 @@ const package_json = JSON.parse(fs.readFileSync(path.join(ADMIN_FORTH_ABSOLUTE_P
32
32
  export const ADMINFORTH_VERSION: string = package_json.version;
33
33
 
34
34
  export function getComponentNameFromPath(filePath) {
35
- return filePath.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
35
+ return filePath.replace(/@/g, '').replace(/.vue/g, '').replace(/\./g, '').replace(/\//g, '');
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.0.59",
3
+ "version": "1.0.61",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { createRouter, createWebHistory } from 'vue-router'
2
2
  import ResourceParent from '@/views/ResourceParent.vue'
3
+ /* IMPORTANT:ADMINFORTH ROUTES IMPORTS */
3
4
 
4
5
  const router = createRouter({
5
6
  history: createWebHistory(import.meta.env.BASE_URL),
@@ -10,6 +10,7 @@ export type AdminForthConfigMenuItem = {
10
10
  homepage?: boolean,
11
11
  open?: boolean,
12
12
  children?: Array<AdminForthConfigMenuItem>,
13
+ isStaticRoute?: boolean,
13
14
  }
14
15
 
15
16