feat: scan automatique des app.json au démarrage (découverte FALC et autres)
This commit is contained in:
@@ -434,7 +434,7 @@ function addDynamicApp(appDef) {
|
||||
}
|
||||
|
||||
function initDynamicApps() {
|
||||
// 1. Charger les apps depuis .dashboard-apps.json (créées via l'interface)
|
||||
// 1. Charger les apps depuis .dashboard-apps.json (legacy)
|
||||
const dynamicApps = loadDynamicApps();
|
||||
for (const app of dynamicApps) {
|
||||
const existingInConfig = config.apps.findIndex((a) => a.id === app.id);
|
||||
@@ -442,39 +442,32 @@ function initDynamicApps() {
|
||||
config.apps.push(app);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Découverte automatique : scanner les dossiers apps/*.json
|
||||
let discovered = 0;
|
||||
// 2. Scanner les dossiers app.json (découverte automatique)
|
||||
try {
|
||||
const appsBasePath = config.appsBasePath;
|
||||
if (fs.existsSync(appsBasePath)) {
|
||||
const entries = fs.readdirSync(appsBasePath, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const appJsonPath = path.join(appsBasePath, entry.name, 'app.json');
|
||||
if (!fs.existsSync(appJsonPath)) continue;
|
||||
try {
|
||||
const appDef = JSON.parse(fs.readFileSync(appJsonPath, 'utf-8'));
|
||||
if (!appDef.id) continue;
|
||||
// Ne pas écraser une app déjà en config (statique ou dynamique)
|
||||
const existingIdx = config.apps.findIndex((a) => a.id === appDef.id);
|
||||
if (existingIdx >= 0) {
|
||||
// Mettre à jour avec les données du app.json (source de vérité)
|
||||
config.apps[existingIdx] = { ...config.apps[existingIdx], ...appDef };
|
||||
} else {
|
||||
config.apps.push(appDef);
|
||||
discovered++;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(`[discovery] Erreur lecture ${appJsonPath}:`, e.message);
|
||||
const appsBasePath = config.appsBasePath || process.env.APPS_BASE_PATH || '/opt/manus-deploy/apps';
|
||||
const entries = fs.readdirSync(appsBasePath, { withFileTypes: true });
|
||||
let scanned = 0;
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const appJsonPath = path.join(appsBasePath, entry.name, 'app.json');
|
||||
if (!fs.existsSync(appJsonPath)) continue;
|
||||
try {
|
||||
const appDef = JSON.parse(fs.readFileSync(appJsonPath, 'utf-8'));
|
||||
if (!appDef.id) continue;
|
||||
const existingInConfig = config.apps.findIndex((a) => a.id === appDef.id);
|
||||
if (existingInConfig < 0) {
|
||||
config.apps.push(appDef);
|
||||
scanned++;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Erreur lecture app.json dans ${entry.name}:`, e.message);
|
||||
}
|
||||
}
|
||||
console.log(`Apps découvertes via app.json: ${scanned}`);
|
||||
} catch (err) {
|
||||
console.error('[discovery] Erreur scan apps:', err.message);
|
||||
console.error('Erreur scan app.json:', err.message);
|
||||
}
|
||||
|
||||
console.log(`Apps chargées: ${dynamicApps.length} dynamiques + ${discovered} découvertes (total: ${config.apps.length})`);
|
||||
console.log(`Total apps chargées: ${config.apps.length}`);
|
||||
}
|
||||
|
||||
// ============ CREATION D'APPLICATION ============
|
||||
|
||||
Reference in New Issue
Block a user