chore: Clean up variable replacement paths
This commit is contained in:
@@ -26,10 +26,23 @@ PLACEHOLDER_WIKI="https://next-wiki.useplunk.com"
|
|||||||
MANIFEST_FILE="$APP_DIR/.next/url-manifest.txt"
|
MANIFEST_FILE="$APP_DIR/.next/url-manifest.txt"
|
||||||
|
|
||||||
# Find all files that contain placeholder URLs and save to manifest
|
# Find all files that contain placeholder URLs and save to manifest
|
||||||
# Search in .next directory for relevant file types
|
# IMPORTANT: Only scan the standalone directory, not the entire .next directory
|
||||||
find "$APP_DIR/.next" -type f \( -name "*.js" -o -name "*.json" -o -name "*.html" -o -name "*.rsc" \) \
|
# This avoids including server-only files that won't exist in the runtime container
|
||||||
-exec grep -l -E "$PLACEHOLDER_API|$PLACEHOLDER_DASHBOARD|$PLACEHOLDER_LANDING|$PLACEHOLDER_WIKI" {} \; \
|
STANDALONE_DIR="$APP_DIR/.next/standalone/apps/$APP_NAME"
|
||||||
2>/dev/null > "$MANIFEST_FILE" || true
|
|
||||||
|
if [ -d "$STANDALONE_DIR" ]; then
|
||||||
|
# Search in standalone directory for files that will be deployed
|
||||||
|
# Store paths RELATIVE to the standalone directory for easier runtime processing
|
||||||
|
find "$STANDALONE_DIR/.next" -type f \( -name "*.js" -o -name "*.json" -o -name "*.html" -o -name "*.rsc" \) \
|
||||||
|
-exec grep -l -E "$PLACEHOLDER_API|$PLACEHOLDER_DASHBOARD|$PLACEHOLDER_LANDING|$PLACEHOLDER_WIKI" {} \; \
|
||||||
|
2>/dev/null | sed "s|$STANDALONE_DIR/||g" > "$MANIFEST_FILE" || true
|
||||||
|
else
|
||||||
|
echo "⚠️ Warning: Standalone directory not found at $STANDALONE_DIR"
|
||||||
|
echo " Falling back to scanning entire .next directory"
|
||||||
|
find "$APP_DIR/.next" -type f \( -name "*.js" -o -name "*.json" -o -name "*.html" -o -name "*.rsc" \) \
|
||||||
|
-exec grep -l -E "$PLACEHOLDER_API|$PLACEHOLDER_DASHBOARD|$PLACEHOLDER_LANDING|$PLACEHOLDER_WIKI" {} \; \
|
||||||
|
2>/dev/null > "$MANIFEST_FILE" || true
|
||||||
|
fi
|
||||||
|
|
||||||
# Count files
|
# Count files
|
||||||
FILE_COUNT=$(wc -l < "$MANIFEST_FILE" | tr -d ' ')
|
FILE_COUNT=$(wc -l < "$MANIFEST_FILE" | tr -d ' ')
|
||||||
@@ -37,9 +50,18 @@ FILE_COUNT=$(wc -l < "$MANIFEST_FILE" | tr -d ' ')
|
|||||||
echo "✅ Generated manifest for $APP_NAME: $FILE_COUNT files need URL replacement"
|
echo "✅ Generated manifest for $APP_NAME: $FILE_COUNT files need URL replacement"
|
||||||
echo " Manifest saved to: $MANIFEST_FILE"
|
echo " Manifest saved to: $MANIFEST_FILE"
|
||||||
|
|
||||||
# Also generate manifest for sitemap/robots files
|
# Also generate manifest for sitemap/robots files in standalone public directory
|
||||||
SITEMAP_MANIFEST_FILE="$APP_DIR/.next/sitemap-manifest.txt"
|
SITEMAP_MANIFEST_FILE="$APP_DIR/.next/sitemap-manifest.txt"
|
||||||
find "$APP_DIR/public" -type f \( -name "sitemap*.xml" -o -name "robots.txt" \) 2>/dev/null > "$SITEMAP_MANIFEST_FILE" || true
|
|
||||||
|
if [ -d "$STANDALONE_DIR/public" ]; then
|
||||||
|
# Store paths RELATIVE to the standalone directory
|
||||||
|
find "$STANDALONE_DIR/public" -type f \( -name "sitemap*.xml" -o -name "robots.txt" \) \
|
||||||
|
2>/dev/null | sed "s|$STANDALONE_DIR/||g" > "$SITEMAP_MANIFEST_FILE" || true
|
||||||
|
else
|
||||||
|
# Fallback to app public directory
|
||||||
|
find "$APP_DIR/public" -type f \( -name "sitemap*.xml" -o -name "robots.txt" \) 2>/dev/null > "$SITEMAP_MANIFEST_FILE" || true
|
||||||
|
fi
|
||||||
|
|
||||||
SITEMAP_COUNT=$(wc -l < "$SITEMAP_MANIFEST_FILE" | tr -d ' ')
|
SITEMAP_COUNT=$(wc -l < "$SITEMAP_MANIFEST_FILE" | tr -d ' ')
|
||||||
echo "✅ Generated sitemap manifest for $APP_NAME: $SITEMAP_COUNT files"
|
echo "✅ Generated sitemap manifest for $APP_NAME: $SITEMAP_COUNT files"
|
||||||
|
|
||||||
|
|||||||
@@ -37,36 +37,24 @@ replace_urls_in_app() {
|
|||||||
echo " 📊 Processing $file_count files from manifest"
|
echo " 📊 Processing $file_count files from manifest"
|
||||||
|
|
||||||
if [ "$file_count" -gt 0 ]; then
|
if [ "$file_count" -gt 0 ]; then
|
||||||
# Process files using xargs for better performance
|
# Process files line by line
|
||||||
# Use -P 4 to process up to 4 files in parallel
|
# The manifest now contains RELATIVE paths (e.g., .next/static/chunks/abc.js)
|
||||||
# This significantly speeds up processing of many files
|
# We just need to prepend the app_dir
|
||||||
#
|
|
||||||
# IMPORTANT: The manifest contains build-time paths (e.g., /app/apps/web/.next/...)
|
cat "$manifest_file" | while IFS= read -r rel_path; do
|
||||||
# but we need to translate them to runtime standalone paths
|
# Construct full runtime path
|
||||||
# (e.g., /app/apps/web/.next/standalone/apps/web/.next/...)
|
|
||||||
cat "$manifest_file" | while IFS= read -r build_path; do
|
|
||||||
# Translate build path to runtime standalone path
|
|
||||||
# Build path format: /app/apps/<app>/.next/...
|
|
||||||
# Runtime path format: /app/apps/<app>/.next/standalone/apps/<app>/.next/...
|
|
||||||
|
|
||||||
# Extract the relative path after /app/apps/<app>/
|
|
||||||
rel_path="${build_path#/app/apps/${app}/}"
|
|
||||||
|
|
||||||
# Construct runtime path in standalone directory
|
|
||||||
runtime_path="$app_dir/$rel_path"
|
runtime_path="$app_dir/$rel_path"
|
||||||
|
|
||||||
if [ -f "$runtime_path" ]; then
|
if [ -f "$runtime_path" ]; then
|
||||||
sed -e "s|$PLACEHOLDER_API|$API_URI|g" \
|
sed -e "s|$PLACEHOLDER_API|$API_URI|g" \
|
||||||
-e "s|$PLACEHOLDER_DASHBOARD|$DASHBOARD_URI|g" \
|
-e "s|$PLACEHOLDER_DASHBOARD|$DASHBOARD_URI|g" \
|
||||||
-e "s|$PLACEHOLDER_LANDING|$LANDING_URI|g" \
|
-e "s|$PLACEHOLDER_LANDING|$LANDING_URI|g" \
|
||||||
-e "s|$PLACEHOLDER_WIKI|$WIKI_URI|g" \
|
-e "s|$PLACEHOLDER_WIKI|$WIKI_URI|g" \
|
||||||
"$runtime_path" > "${runtime_path}.tmp" && mv "${runtime_path}.tmp" "$runtime_path"
|
"$runtime_path" > "${runtime_path}.tmp" && mv "${runtime_path}.tmp" "$runtime_path"
|
||||||
else
|
|
||||||
echo " ⚠️ Warning: File not found at runtime: $runtime_path"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo " ✅ Successfully replaced URLs in $file_count files"
|
echo " ✅ Successfully replaced URLs in files"
|
||||||
else
|
else
|
||||||
echo " ℹ️ No files found with placeholder URLs"
|
echo " ℹ️ No files found with placeholder URLs"
|
||||||
fi
|
fi
|
||||||
@@ -76,25 +64,16 @@ replace_urls_in_app() {
|
|||||||
local sitemap_manifest="$app_dir/.next/sitemap-manifest.txt"
|
local sitemap_manifest="$app_dir/.next/sitemap-manifest.txt"
|
||||||
|
|
||||||
if [ -f "$sitemap_manifest" ]; then
|
if [ -f "$sitemap_manifest" ]; then
|
||||||
while IFS= read -r build_sitemap_path; do
|
while IFS= read -r rel_path; do
|
||||||
# Translate build path to runtime path
|
# Manifest contains relative paths, just prepend app_dir
|
||||||
# Build path format: /app/apps/<app>/public/...
|
|
||||||
# Runtime path format: /app/apps/<app>/.next/standalone/apps/<app>/public/...
|
|
||||||
|
|
||||||
# Extract the relative path after /app/apps/<app>/
|
|
||||||
rel_path="${build_sitemap_path#/app/apps/${app}/}"
|
|
||||||
|
|
||||||
# Construct runtime path in standalone directory
|
|
||||||
runtime_sitemap_path="$app_dir/$rel_path"
|
runtime_sitemap_path="$app_dir/$rel_path"
|
||||||
|
|
||||||
if [ -f "$runtime_sitemap_path" ]; then
|
if [ -f "$runtime_sitemap_path" ]; then
|
||||||
sed -e "s|$PLACEHOLDER_API|$API_URI|g" \
|
sed -e "s|$PLACEHOLDER_API|$API_URI|g" \
|
||||||
-e "s|$PLACEHOLDER_DASHBOARD|$DASHBOARD_URI|g" \
|
-e "s|$PLACEHOLDER_DASHBOARD|$DASHBOARD_URI|g" \
|
||||||
-e "s|$PLACEHOLDER_LANDING|$LANDING_URI|g" \
|
-e "s|$PLACEHOLDER_LANDING|$LANDING_URI|g" \
|
||||||
-e "s|$PLACEHOLDER_WIKI|$WIKI_URI|g" \
|
-e "s|$PLACEHOLDER_WIKI|$WIKI_URI|g" \
|
||||||
"$runtime_sitemap_path" > "${runtime_sitemap_path}.tmp" && mv "${runtime_sitemap_path}.tmp" "$runtime_sitemap_path"
|
"$runtime_sitemap_path" > "${runtime_sitemap_path}.tmp" && mv "${runtime_sitemap_path}.tmp" "$runtime_sitemap_path"
|
||||||
else
|
|
||||||
echo " ⚠️ Warning: Sitemap file not found at runtime: $runtime_sitemap_path"
|
|
||||||
fi
|
fi
|
||||||
done < "$sitemap_manifest"
|
done < "$sitemap_manifest"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user