clone of github.com/decent-newsroom/newsroom
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.6 KiB

#!/bin/bash
# Script to download npm packages for Symfony Asset Mapper importmap
# This works around network timeout issues in the Docker container
cd "$(dirname "$0")"
echo "Downloading npm packages for Asset Mapper..."
mkdir -p assets/vendor
# Download critical packages first
packages=(
"lodash-es@4.17.21"
"parchment@3.0.0"
"eventemitter3@5.0.1"
"fast-diff@1.3.0"
"lodash.clonedeep@4.5.0"
"lodash.isequal@4.5.0"
"es-module-shims@2.0.10"
"nostr-tools@2.17.0"
)
download_package() {
local name=$1
local ver=$2
local pkg_name=$name
echo "Downloading $name@$ver..."
# Handle scoped packages
local dir_name=$name
if [[ $name == @* ]]; then
# Scoped package like @noble/curves/secp256k1
dir_name=$(echo "$name" | sed 's/@/\\@/g')
fi
# Create package directory
mkdir -p "assets/vendor/$dir_name"
# Download and extract to temp location
local temp_dir=$(mktemp -d)
if curl -sLf "https://registry.npmjs.org/$name/-/${pkg_name##*/}-${ver}.tgz" | tar -xz -C "$temp_dir" 2>/dev/null; then
# Find the main entry point
local entry_point=""
# Check common locations for entry point
if [ -f "$temp_dir/package/dist/index.js" ]; then
entry_point="$temp_dir/package/dist/index.js"
elif [ -f "$temp_dir/package/index.js" ]; then
entry_point="$temp_dir/package/index.js"
elif [ -f "$temp_dir/package/esm/index.js" ]; then
entry_point="$temp_dir/package/esm/index.js"
elif [ -f "$temp_dir/package/main.js" ]; then
entry_point="$temp_dir/package/main.js"
else
# Try to find any .js file in the package
entry_point=$(find "$temp_dir/package" -name "*.js" -type f | grep -E "(index|main|dist.*index)" | head -1)
if [ -z "$entry_point" ]; then
entry_point=$(find "$temp_dir/package" -name "*.js" -type f | head -1)
fi
fi
if [ -n "$entry_point" ] && [ -f "$entry_point" ]; then
cp "$entry_point" "assets/vendor/$dir_name/index.js"
echo " ✓ Downloaded $name@$ver"
else
echo " ✗ Failed to find entry point for $name@$ver"
fi
rm -rf "$temp_dir"
else
echo " ✗ Failed to download $name@$ver"
rm -rf "$temp_dir"
return 1
fi
}
for pkg in "${packages[@]}"; do
name=$(echo "$pkg" | cut -d@ -f1)
ver=$(echo "$pkg" | cut -d@ -f2)
download_package "$name" "$ver" || true
done
echo "Done downloading critical packages"