chore: optimize cms startup, refactor scripts and implement real-time dev mode
This commit is contained in:
66
scripts/patch-cms.sh
Executable file
66
scripts/patch-cms.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
# Define potential container names
|
||||
CONTAINERS=("cms-infra-infra-cms-1" "at-mintel-directus-1")
|
||||
|
||||
echo "🔧 Checking for Directus containers to patch..."
|
||||
|
||||
for CONTAINER in "${CONTAINERS[@]}"; do
|
||||
# Check if container exists and is running
|
||||
if [ "$(docker ps -q -f name=^/${CONTAINER}$)" ]; then
|
||||
echo "🔧 Applying core patch to Directus container: $CONTAINER..."
|
||||
docker exec "$CONTAINER" node -e '
|
||||
const fs = require("node:fs");
|
||||
// Try multiple potential paths for the node_modules location
|
||||
const searchPaths = [
|
||||
"/directus/node_modules/.pnpm/@directus+extensions@file+packages+extensions_deep-diff@1.0.2_express@4.21.2_graphql@16_244b87fbecd929c2d2240e7b3abc1fe4/node_modules/@directus/extensions/dist/node.js",
|
||||
"/directus/node_modules/@directus/extensions/dist/node.js"
|
||||
];
|
||||
|
||||
let targetPath = null;
|
||||
for (const p of searchPaths) {
|
||||
if (fs.existsSync(p)) {
|
||||
targetPath = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetPath) {
|
||||
let content = fs.readFileSync(targetPath, "utf8");
|
||||
|
||||
// Patch the filter: allow string entrypoints for modules
|
||||
const filterPatch = "extension.host === \"app\" && (extension.entrypoint.app || extension.entrypoint)";
|
||||
if (!content.includes(filterPatch)) {
|
||||
content = content.replace(
|
||||
/extension\.host === \"app\" && !!extension\.entrypoint\.app/g,
|
||||
filterPatch
|
||||
);
|
||||
}
|
||||
|
||||
// Patch all imports: handle string entrypoints
|
||||
if (!content.includes("(extension.entrypoint.app || extension.entrypoint)")) {
|
||||
content = content.replace(
|
||||
/extension\.entrypoint\.app/g,
|
||||
"(extension.entrypoint.app || extension.entrypoint)"
|
||||
);
|
||||
}
|
||||
|
||||
fs.writeFileSync(targetPath, content);
|
||||
console.log(`✅ Core patched successfully at ${targetPath}.`);
|
||||
} else {
|
||||
console.error("⚠️ Could not find @directus/extensions node.js to patch!");
|
||||
}
|
||||
'
|
||||
|
||||
echo "🔄 Restarting Directus container: $CONTAINER..."
|
||||
docker restart "$CONTAINER"
|
||||
else
|
||||
echo "ℹ️ Container $CONTAINER is not running or not found. Skipping patch."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "✨ Patching process finished."
|
||||
Reference in New Issue
Block a user