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:
Melvin Chia
2025-10-28 10:42:48 +08:00
parent f2df46d9c3
commit ebdcf504b5
2 changed files with 37 additions and 1 deletions

1
apps/cat.config.json Normal file
View File

@@ -0,0 +1 @@
[]

View File

@@ -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,