Skip to content

Commit e2af385

Browse files
committed
fix: Adds a script to generate the default index file for Firebase.
1 parent ba353c5 commit e2af385

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Maps JSAPI Samples</title>
5+
</head>
6+
<body>
7+
<!-- Default top-level index for Firebase Hosting -->
8+
<h1>Maps JSAPI Samples</h1>
9+
<ul>
10+
<li><a href='add-map/app/dist/'>add-map</a></li>
11+
<li><a href='map-simple/app/dist/'>map-simple</a></li>
12+
<li><a href='place-text-search/app/dist/'>place-text-search</a></li>
13+
</ul>
14+
</body>
15+
</html>

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "1.0.0",
44
"description": "Samples for the Google Maps JavaScript API.",
55
"scripts": {
6-
"build-all": "npm run clean && npm run build --workspaces",
7-
"clean": "bash samples/clean.sh"
6+
"build-all": "npm run generate-index && npm run clean && npm run build --workspaces",
7+
"clean": "bash samples/clean.sh",
8+
"generate-index": "bash samples/generate-index.sh"
89
},
910
"workspaces": [
1011
"samples/*"

samples/generate-index.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Generate a new index.html for Firebase App Hosting.
4+
5+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Script directory (/samples)
6+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
7+
DIST_DIR="$PROJECT_ROOT/dist"
8+
9+
# Create the output file.
10+
OUTPUT_FILE="index.html"
11+
12+
# Generate the HTML document.
13+
echo "<!DOCTYPE html>" > "${OUTPUT_FILE}"
14+
echo "<html>" >> "${OUTPUT_FILE}"
15+
echo "<head>" >> "${OUTPUT_FILE}"
16+
echo "<title>Maps JSAPI Samples</title>" >> "${OUTPUT_FILE}"
17+
echo "</head>" >> "${OUTPUT_FILE}"
18+
echo "<body>" >> "${OUTPUT_FILE}"
19+
echo "<!-- Default top-level index for Firebase Hosting -->" >> "${OUTPUT_FILE}"
20+
echo "<h1>Maps JSAPI Samples</h1>" >> "${OUTPUT_FILE}"
21+
echo "<ul>" >> "${OUTPUT_FILE}"
22+
23+
# Iterate through sample directories.
24+
find "${SCRIPT_DIR}" -maxdepth 1 -mindepth 1 -type d | while read -r subdir; do
25+
26+
# Extract the directory name.
27+
DIR_NAME=$(basename "${subdir}")
28+
29+
# Construct the link.
30+
LINK_URL="${DIR_NAME}/app/dist/"
31+
LINK_TEXT="${DIR_NAME}"
32+
33+
# Create the list item.
34+
echo " <li><a href='${LINK_URL}'>${LINK_TEXT}</a></li>" >> "${OUTPUT_FILE}"
35+
done
36+
37+
echo "</ul>" >> "${OUTPUT_FILE}"
38+
echo "</body>" >> "${OUTPUT_FILE}"
39+
echo "</html>" >> "${OUTPUT_FILE}"
40+
41+
echo "HTML file generated: ${OUTPUT_FILE}"
42+
43+
echo "from ${SCRIPT_DIR}/${OUTPUT_FILE}"
44+
echo "to ${DIST_DIR}/${OUTPUT_FILE}"
45+
46+
cp "${PROJECT_ROOT}/${OUTPUT_FILE}" "${DIST_DIR}/${OUTPUT_FILE}"

0 commit comments

Comments
 (0)