adminforth 1.0.60 → 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.
- package/dist/modules/codeInjector.js +40 -7
- package/dist/modules/utils.js +3 -4
- package/dist/spa/spa/src/router/index.ts +1 -0
- package/modules/codeInjector.ts +43 -7
- package/modules/utils.ts +3 -4
- package/package.json +1 -1
- package/spa/src/router/index.ts +1 -0
- package/types/AdminForthConfig.ts +1 -0
|
@@ -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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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 */
|
package/dist/modules/utils.js
CHANGED
|
@@ -16,9 +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
|
-
|
|
20
|
-
|
|
21
|
-
// 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
|
|
22
21
|
__dirname = path.join(__dirname, '..');
|
|
23
22
|
}
|
|
24
23
|
return __dirname;
|
|
@@ -27,5 +26,5 @@ export const ADMIN_FORTH_ABSOLUTE_PATH = path.join(currentFileDir(import.meta.ur
|
|
|
27
26
|
const package_json = JSON.parse(fs.readFileSync(path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'package.json'), 'utf8'));
|
|
28
27
|
export const ADMINFORTH_VERSION = package_json.version;
|
|
29
28
|
export function getComponentNameFromPath(filePath) {
|
|
30
|
-
return filePath.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
|
|
29
|
+
return filePath.replace(/@/g, '').replace(/.vue/g, '').replace(/\./g, '').replace(/\//g, '');
|
|
31
30
|
}
|
package/modules/codeInjector.ts
CHANGED
|
@@ -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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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,9 +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
|
-
|
|
22
|
-
|
|
23
|
-
// 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
|
|
24
23
|
__dirname = path.join(__dirname, '..');
|
|
25
24
|
}
|
|
26
25
|
return __dirname;
|
|
@@ -33,5 +32,5 @@ const package_json = JSON.parse(fs.readFileSync(path.join(ADMIN_FORTH_ABSOLUTE_P
|
|
|
33
32
|
export const ADMINFORTH_VERSION: string = package_json.version;
|
|
34
33
|
|
|
35
34
|
export function getComponentNameFromPath(filePath) {
|
|
36
|
-
return filePath.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
|
|
35
|
+
return filePath.replace(/@/g, '').replace(/.vue/g, '').replace(/\./g, '').replace(/\//g, '');
|
|
37
36
|
}
|
package/package.json
CHANGED
package/spa/src/router/index.ts
CHANGED