92 lines
3.5 KiB
Bash
Executable File
92 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Configuration
|
|
CONTAINER="cms-infra-infra-cms-1"
|
|
|
|
echo "🔍 Validating Directus Extension Stability..."
|
|
|
|
# 1. Verify Patches
|
|
echo "🛠️ Checking Core Patches..."
|
|
docker exec -i "$CONTAINER" node << 'EOF'
|
|
const fs = require('node:fs');
|
|
const { execSync } = require('node:child_process');
|
|
|
|
let failures = 0;
|
|
|
|
// Check Node.js patch
|
|
const findNode = 'find /directus/node_modules -path "*/@directus/extensions/dist/node.js"';
|
|
const nodePaths = execSync(findNode).toString().trim().split('\n').filter(Boolean);
|
|
nodePaths.forEach(p => {
|
|
const c = fs.readFileSync(p, 'utf8');
|
|
if (!c.includes('(extension.entrypoint.app || extension.entrypoint)')) {
|
|
console.error('❌ Missing node.js patch at ' + p);
|
|
failures++;
|
|
}
|
|
});
|
|
|
|
// Check Manager.js patch
|
|
const findManager = 'find /directus/node_modules -path "*/@directus/api/dist/extensions/manager.js"';
|
|
const managerPaths = execSync(findManager).toString().trim().split('\n').filter(Boolean);
|
|
managerPaths.forEach(p => {
|
|
const c = fs.readFileSync(p, 'utf8');
|
|
if (!c.includes('/extensions/sources/index.js')) {
|
|
console.error('❌ Missing manager.js patch at ' + p);
|
|
failures++;
|
|
}
|
|
});
|
|
|
|
if (failures === 0) {
|
|
console.log('✅ Core patches are healthy.');
|
|
}
|
|
process.exit(failures > 0 ? 1 : 0);
|
|
EOF
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "⚠️ Core patches missing! Run 'bash scripts/patch-cms.sh' to fix."
|
|
fi
|
|
|
|
# 2. Verify Module Bar
|
|
echo "📋 Checking Sidebar Configuration..."
|
|
docker exec -i "$CONTAINER" node << 'EOF'
|
|
const sqlite3 = require('/directus/node_modules/.pnpm/sqlite3@5.1.7/node_modules/sqlite3');
|
|
const db = new sqlite3.Database('/directus/database/data.db');
|
|
const managerIds = ["unified-dashboard", "acquisition-manager", "company-manager", "customer-manager", "feedback-commander", "people-manager"];
|
|
|
|
db.get('SELECT module_bar FROM directus_settings WHERE id = 1', (err, row) => {
|
|
if (err) { console.error('❌ DB Error:', err.message); process.exit(1); }
|
|
|
|
let mb = [];
|
|
try { mb = JSON.parse(row.module_bar || '[]'); } catch(e) { mb = []; }
|
|
|
|
const existingIds = mb.map(m => m.id);
|
|
const missing = managerIds.filter(id => !existingIds.includes(id));
|
|
const disabled = mb.filter(m => managerIds.includes(m.id) && m.enabled === false);
|
|
|
|
if (missing.length === 0 && disabled.length === 0) {
|
|
console.log('✅ Sidebar is healthy with all manager modules enabled.');
|
|
process.exit(0);
|
|
} else {
|
|
if (missing.length > 0) console.log('⚠️ Missing modules:', missing.join(', '));
|
|
if (disabled.length > 0) console.log('⚠️ Disabled modules:', disabled.map(m => m.id).join(', '));
|
|
|
|
console.log('🔧 Self-healing in progress...');
|
|
|
|
// Construct Golden State Module Bar
|
|
const goldenMB = [
|
|
{ type: 'module', id: 'content', enabled: true },
|
|
{ type: 'module', id: 'users', enabled: true },
|
|
{ type: 'module', id: 'files', enabled: true },
|
|
{ type: 'module', id: 'insights', enabled: true },
|
|
...managerIds.map(id => ({ type: 'module', id, enabled: true })),
|
|
{ type: 'module', id: 'settings', enabled: true }
|
|
];
|
|
|
|
db.run('UPDATE directus_settings SET module_bar = ? WHERE id = 1', [JSON.stringify(goldenMB)], function(err) {
|
|
if (err) { console.error('❌ Repair failed:', err.message); process.exit(1); }
|
|
console.log('✨ Sidebar repaired successfully!');
|
|
process.exit(0);
|
|
});
|
|
}
|
|
});
|
|
EOF
|