Skip to content

Commit e4e2ebe

Browse files
committed
feat: Updates jsfiddle script to replace asset paths.
1 parent fd7235b commit e4e2ebe

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

samples/jsfiddle.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ cp "${SCRIPT_DIR}/${NAME}/index.js" "${DIST_DIR}/samples/${NAME}/jsfiddle/demo.j
3232
cp "${SCRIPT_DIR}/${NAME}/index.html" "${DIST_DIR}/samples/${NAME}/jsfiddle/demo.html"
3333
cp "${SCRIPT_DIR}/${NAME}/style.css" "${DIST_DIR}/samples/${NAME}/jsfiddle/demo.css"
3434

35-
# Copy the public folder if one is found (graphics, other static files).
36-
if [ -d "public" ] && [ "$(ls -A public)" ]; then
37-
cp -r public/* "${DOCS_DIR}/"
38-
fi
39-
40-
# Copy the src folder if one is found (.js, .json, anything parseable by Vite).
41-
if [ -d "src" ] && [ "$(ls -A src)" ]; then
42-
cp -r src/* "${DOCS_DIR}/"
43-
fi
35+
# Replace local asset paths with production URLs.
36+
PROD_URL_BASE="https://maps-docs-team.web.app/samples/${NAME}/dist"
37+
JSFIDDLE_DIR="${DIST_DIR}/samples/${NAME}/jsfiddle"
38+
39+
# Find all asset files in public and src directories.
40+
find "${SCRIPT_DIR}/${NAME}" \( -path "*/public/*" -o -path "*/src/*" \) -type f \( -name "*.png" -o -name "*.gif" -o -name "*.svg" -o -name "*.json" -o -name "*.js" \) | while read -r asset_file; do
41+
# Get the asset's path relative to the sample directory (e.g., public/icon.png)
42+
relative_path=${asset_file#*"${SCRIPT_DIR}/${NAME}/"}
43+
asset_name=$(basename "$relative_path")
44+
45+
# Replace paths in the demo files. Note: This handles paths like './asset.png' and 'asset.png'.
46+
sed -i.bak "s|\(['\"(]\)\(\./\)*${asset_name}\(['\")']\)|\1${PROD_URL_BASE}/${asset_name}\3|g" "${JSFIDDLE_DIR}/demo.js" "${JSFIDDLE_DIR}/demo.html" "${JSFIDDLE_DIR}/demo.css"
47+
done
48+
49+
rm -f "${JSFIDDLE_DIR}"/*.bak # Clean up backup files created by sed.
4450

4551
# Remove region tags from files by type, since they all have different comment conventions.
4652
# We use a conditional here since sed behaves differently on Linux.

0 commit comments

Comments
 (0)