adminforth 1.0.60 → 1.0.62
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 +41 -7
- package/dist/modules/utils.js +2 -3
- package/dist/spa/spa/src/router/index.ts +1 -0
- package/modules/codeInjector.ts +45 -7
- package/modules/utils.ts +2 -3
- 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);
|
|
@@ -182,6 +214,7 @@ class CodeInjector {
|
|
|
182
214
|
const componentName = getComponentNameFromPath(filePath);
|
|
183
215
|
this.allComponentNames[filePath] = componentName;
|
|
184
216
|
});
|
|
217
|
+
console.log('🔧 Injecting code into Vue sources...', this.allComponentNames);
|
|
185
218
|
let customComponentsImports = '';
|
|
186
219
|
for (const [targetPath, component] of Object.entries(this.allComponentNames)) {
|
|
187
220
|
customComponentsImports += `import ${component} from '${targetPath}';\n`;
|
|
@@ -222,6 +255,9 @@ class CodeInjector {
|
|
|
222
255
|
tailwindConfigContent = tailwindConfigContent.replace('/* IMPORTANT:ADMINFORTH TAILWIND STYLES */', stylesText);
|
|
223
256
|
yield fs.promises.writeFile(tailwindConfigPath, tailwindConfigContent);
|
|
224
257
|
}
|
|
258
|
+
const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
|
|
259
|
+
let routerVueContent = yield fs.promises.readFile(routerVuePath, 'utf-8');
|
|
260
|
+
routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES IMPORTS */', routerComponents);
|
|
225
261
|
/* generate custom routes */
|
|
226
262
|
const homepageMenuItem = this.adminforth.config.menu.find((mi) => mi.homepage);
|
|
227
263
|
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 +272,6 @@ class CodeInjector {
|
|
|
236
272
|
//redirect to login
|
|
237
273
|
redirect: '${homePagePath}'
|
|
238
274
|
},\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
275
|
routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES */', routes);
|
|
242
276
|
yield fs.promises.writeFile(routerVuePath, routerVueContent);
|
|
243
277
|
/* 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;
|
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);
|
|
@@ -206,6 +238,8 @@ class CodeInjector {
|
|
|
206
238
|
const componentName = getComponentNameFromPath(filePath);
|
|
207
239
|
this.allComponentNames[filePath] = componentName;
|
|
208
240
|
});
|
|
241
|
+
|
|
242
|
+
console.log('🔧 Injecting code into Vue sources...', this.allComponentNames);
|
|
209
243
|
|
|
210
244
|
let customComponentsImports = '';
|
|
211
245
|
for (const [targetPath, component] of Object.entries(this.allComponentNames)) {
|
|
@@ -257,6 +291,12 @@ class CodeInjector {
|
|
|
257
291
|
}
|
|
258
292
|
|
|
259
293
|
|
|
294
|
+
const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
|
|
295
|
+
|
|
296
|
+
let routerVueContent = await fs.promises.readFile(routerVuePath, 'utf-8');
|
|
297
|
+
routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES IMPORTS */', routerComponents);
|
|
298
|
+
|
|
299
|
+
|
|
260
300
|
|
|
261
301
|
/* generate custom routes */
|
|
262
302
|
const homepageMenuItem = this.adminforth.config.menu.find((mi)=>mi.homepage);
|
|
@@ -273,8 +313,6 @@ class CodeInjector {
|
|
|
273
313
|
//redirect to login
|
|
274
314
|
redirect: '${homePagePath}'
|
|
275
315
|
},\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
316
|
routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES */', routes);
|
|
279
317
|
await fs.promises.writeFile(routerVuePath, routerVueContent);
|
|
280
318
|
|
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;
|
package/package.json
CHANGED
package/spa/src/router/index.ts
CHANGED