mirror of
https://github.com/Lifeforge-app/lifeforge.git
synced 2026-06-27 22:36:06 +00:00
feat(client): add dynamic module category sequence loading from configuration file
Former-commit-id: e886c6b794fb1e39de28d096ff2527ed255db076 [formerly 82e16d38e321d46c3b6549b9f7f26acf5b5a8102] [formerly 8cf1c7b45c2cabc43b53f372f3274d8f32a3ab41 [formerly 3fed1b24e80f3663bb28a20f357e5a4424c8e033]] Former-commit-id: 90903ae136215dab15d6aa25da6b3c221083882a [formerly 3c6404d13024155c4dabecf6b15d91f068020c1f] Former-commit-id: 760e4ec67b53e863dd3cf9064458b39c57308418
This commit is contained in:
1
apps/cat.config.json
Normal file
1
apps/cat.config.json
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -2,6 +2,20 @@ import type { ModuleCategory, ModuleConfig } from 'shared'
|
||||
|
||||
let ROUTES: ModuleCategory[] = []
|
||||
|
||||
const categoryFile = import.meta.glob('../../../apps/cat.config.json', {
|
||||
eager: true
|
||||
})
|
||||
|
||||
let categoriesSeq: string[] = []
|
||||
|
||||
console.log(categoryFile)
|
||||
|
||||
if (categoryFile['../../../apps/cat.config.json']) {
|
||||
categoriesSeq = (
|
||||
categoryFile['../../../apps/cat.config.json'] as { default: string[] }
|
||||
).default
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(
|
||||
import.meta.glob(['../apps/**/manifest.ts', '../../../apps/**/manifest.ts'])
|
||||
@@ -49,7 +63,28 @@ ROUTES = ROUTES.sort((a, b) => {
|
||||
if (bIndex >= 1) return -1 // Settings, SSO, <END> go last
|
||||
}
|
||||
|
||||
// Both are regular categories - alphabetical
|
||||
if (categoriesSeq.length > 0) {
|
||||
const aCatIndex = categoriesSeq.indexOf(a.title)
|
||||
|
||||
const bCatIndex = categoriesSeq.indexOf(b.title)
|
||||
|
||||
// Both found in sequence
|
||||
if (aCatIndex !== -1 && bCatIndex !== -1) {
|
||||
return aCatIndex - bCatIndex
|
||||
}
|
||||
|
||||
// Only a found in sequence
|
||||
if (aCatIndex !== -1) {
|
||||
return -1
|
||||
}
|
||||
|
||||
// Only b found in sequence
|
||||
if (bCatIndex !== -1) {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
// Default to alphabetical
|
||||
return a.title.localeCompare(b.title)
|
||||
}).map(cat => ({
|
||||
title: ['<START>', '<END>'].includes(cat.title) ? '' : cat.title,
|
||||
|
||||
Reference in New Issue
Block a user