Skip to content

Commit d2e58c1

Browse files
committed
fix: Fixes path generation for all scripts.
1 parent 83d7544 commit d2e58c1

File tree

6 files changed

+109
-48
lines changed

6 files changed

+109
-48
lines changed

samples/app.sh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@
22

33
# Copy/generate:
44
# - Files for Cloud Shell
5-
# - Vite build output for hosting
65

7-
# Generate JSFiddle output as part of the build process.
6+
echo ">>>Running app.sh"
7+
88
NAME=$1 # The name of the folder, taken from package.json "build" line.
99

10-
# Relative path to the top-level of the examples folder.
11-
#OUTPUT_DIR=/Users/[USERNAME]/git/js-api-samples/samples
12-
OUTPUT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
10+
# /Users/[USERNAME]/git/js-api-samples/samples
11+
12+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
13+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
14+
DIST_DIR="${PROJECT_ROOT}/dist"
15+
16+
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
17+
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
18+
echo "DIST_DIR: ${DIST_DIR}"
19+
echo "NAME: ${NAME}"
1320

14-
APP_DIR="../../dist/samples/${NAME}/app"
15-
MAIN_DIR="../../dist/samples/${NAME}"
21+
APP_DIR="${PROJECT_ROOT}/dist/samples/${NAME}/app"
1622

1723
# Create the new folders.
1824
mkdir -p ${APP_DIR}
19-
mkdir -p ${MAIN_DIR}
2025

2126
# Copy files
22-
cp "${OUTPUT_DIR}/${NAME}/index.html" "${APP_DIR}/index.html"
23-
cp "${OUTPUT_DIR}/${NAME}/index.ts" "${APP_DIR}/index.ts"
24-
cp "${OUTPUT_DIR}/${NAME}/style.css" "${APP_DIR}/style.css"
25-
cp "${OUTPUT_DIR}/${NAME}/package.json" "${APP_DIR}/package.json"
26-
cp "${OUTPUT_DIR}/${NAME}/tsconfig.json" "${APP_DIR}/tsconfig.json"
27-
cp "${OUTPUT_DIR}/${NAME}/README.md" "${APP_DIR}/README.md"
28-
cp "${OUTPUT_DIR}/.env" "${APP_DIR}/.env"
29-
cp -r "${OUTPUT_DIR}/${NAME}/dist" "${MAIN_DIR}"
27+
cp "${SCRIPT_DIR}/${NAME}/index.html" "${APP_DIR}/index.html"
28+
cp "${SCRIPT_DIR}/${NAME}/index.ts" "${APP_DIR}/index.ts"
29+
cp "${SCRIPT_DIR}/${NAME}/style.css" "${APP_DIR}/style.css"
30+
cp "${SCRIPT_DIR}/${NAME}/package.json" "${APP_DIR}/package.json"
31+
cp "${SCRIPT_DIR}/${NAME}/tsconfig.json" "${APP_DIR}/tsconfig.json"
32+
cp "${SCRIPT_DIR}/${NAME}/README.md" "${APP_DIR}/README.md"
33+
cp "${SCRIPT_DIR}/.env" "${APP_DIR}/.env"
3034

3135
# Generate .eslintsrc.json
3236
touch "${APP_DIR}/.eslintsrc.json"

samples/dist.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Copy/generate:
4+
# - Vite build output for hosting
5+
6+
echo ">>>Running dist.sh"
7+
8+
NAME=$1 # The name of the folder, taken from package.json "build" line.
9+
10+
# /Users/[USERNAME]/git/js-api-samples/samples
11+
12+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
13+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
14+
DIST_DIR="${PROJECT_ROOT}/dist"
15+
SAMPLE_DIR="${PROJECT_ROOT}/dist/samples/${NAME}"
16+
17+
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
18+
19+
# Copy Vite output files to /dist/samples/${NAME}/dist
20+
cp -r "${SCRIPT_DIR}/${NAME}/dist" "${SAMPLE_DIR}"

samples/docs.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,32 @@
22

33
# Copy/generate files for doc snippets.
44

5-
# Generate JSFiddle output as part of the build process.
5+
echo ">>>Running docs.sh"
6+
7+
# Copy static documentation files as part of the build process.
68
NAME=$1 # The name of the folder, taken from package.json "build" line.
79

810
# Relative path to the top-level of the examples folder.
9-
#PATH_TO_DOCS=/Users/[USERNAME]/git/js-api-samples/samples
10-
PATH_TO_DOCS="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
11-
12-
echo ${PATH_TO_DOCS}
11+
# /Users/[USERNAME]/git/js-api-samples/samples or similar
12+
# Define path based on platform.
13+
if [[ "$OSTYPE" == "darwin"* ]]; then
14+
echo "Hello, Mac!"
15+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
16+
echo "Project path: ${SCRIPT_DIR}"
17+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
18+
echo "Hello, gLinux!"
19+
SCRIPT_DIR="$(dirname "$0")"
20+
echo "Project path: ${SCRIPT_DIR}"
21+
fi
1322

14-
OUTPUT_DIR=${PATH_TO_DOCS}
15-
DIST_DIR="../../dist/samples/${NAME}/docs"
23+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
24+
DOCS_DIR="${PROJECT_ROOT}/dist/samples/${NAME}/docs"
1625

1726
# Create a new folder.
18-
mkdir -p ${DIST_DIR}
27+
mkdir -p ${DOCS_DIR}
1928

2029
# Copy files
21-
cp "${OUTPUT_DIR}/${NAME}/index.ts" "${DIST_DIR}/index.ts"
22-
cp "${OUTPUT_DIR}/${NAME}/index.js" "${DIST_DIR}/index.js"
23-
cp "${OUTPUT_DIR}/${NAME}/index.html" "${DIST_DIR}/index.html"
24-
cp "${OUTPUT_DIR}/${NAME}/style.css" "${DIST_DIR}/style.css"
30+
cp "${SCRIPT_DIR}/${NAME}/index.ts" "${DOCS_DIR}/index.ts"
31+
cp "${SCRIPT_DIR}/${NAME}/index.js" "${DOCS_DIR}/index.js"
32+
cp "${SCRIPT_DIR}/${NAME}/index.html" "${DOCS_DIR}/index.html"
33+
cp "${SCRIPT_DIR}/${NAME}/style.css" "${DOCS_DIR}/style.css"

samples/generate-index.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
# Generate a new index.html for Firebase App Hosting.
44

5-
#https://maps-docs-team.web.app/samples/place-autocomplete-map/
5+
echo ">>>Running generate-index.sh"
66

7-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Script directory (/samples)
7+
# /Users/[USERNAME]/git/js-api-samples/samples
8+
9+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
810
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
9-
DIST_DIR="$PROJECT_ROOT/dist"
11+
DIST_DIR="${PROJECT_ROOT}/dist"
12+
13+
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
1014

1115
# Create the output file.
1216
OUTPUT_FILE="index.html"
@@ -42,7 +46,7 @@ echo "</html>" >> "${OUTPUT_FILE}"
4246

4347
echo "HTML file generated: ${OUTPUT_FILE}"
4448

45-
echo "from ${SCRIPT_DIR}/${OUTPUT_FILE}"
49+
echo "from ${PROJECT_ROOT}/${OUTPUT_FILE}"
4650
echo "to ${DIST_DIR}/${OUTPUT_FILE}"
4751

48-
cp "${PROJECT_ROOT}/${OUTPUT_FILE}" "${DIST_DIR}/${OUTPUT_FILE}"
52+
echo cp "${PROJECT_ROOT}/${OUTPUT_FILE}" "${DIST_DIR}/${OUTPUT_FILE}"

samples/jsfiddle.sh

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,59 @@
77
# Disable history expansion so '!' doesn't trigger the command. (do we need this?)
88
#set +H
99

10+
echo ">>>Running jsfiddle.sh"
11+
1012
# Generate JSFiddle output as part of the build process.
1113
NAME=$1 # The name of the folder, taken from package.json "build" line.
1214

13-
# /Users/[USERNAME]/git/js-api-samples/samples or similar
14-
SAMPLES_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
15-
PROJECT_ROOT=$(dirname "$SAMPLES_DIR") # Get the parent directory (js-api-samples)
15+
# /Users/[USERNAME]/git/js-api-samples/samples
16+
17+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
18+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
1619
DIST_DIR="${PROJECT_ROOT}/dist"
1720

21+
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
22+
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
23+
echo "DIST_DIR: ${DIST_DIR}"
24+
echo "NAME: ${NAME}"
25+
1826
# Create a new folder.
1927
mkdir -p "${DIST_DIR}/samples/${NAME}/jsfiddle"
2028

2129
# Copy files
22-
echo "Copy ${SAMPLES_DIR}/${NAME}/index.js to ${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
23-
cp "${SAMPLES_DIR}/${NAME}/index.js" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
24-
cp "${SAMPLES_DIR}/${NAME}/index.html" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
25-
cp "${SAMPLES_DIR}/${NAME}/style.css" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
30+
echo "Copy ${SCRIPT_DIR}/${NAME}/index.js to ${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
31+
cp "${SCRIPT_DIR}/${NAME}/index.js" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
32+
cp "${SCRIPT_DIR}/${NAME}/index.html" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
33+
cp "${SCRIPT_DIR}/${NAME}/style.css" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
2634

2735
# Remove region tags from files by type, since they all have different comment conventions.
36+
# We use a conditional here since sed behaves differently on Linux.
2837
echo "Remove region tags from ${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
29-
sed -i "" "s/\/\/ \[START .*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
30-
sed -i "" "s/\/\/ \[END .*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
38+
if [[ "$OSTYPE" == "darwin"* ]]; then
39+
sed -i "" "s/\/\/ \[START .*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
40+
sed -i "" "s/\/\/ \[END .*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
41+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
42+
sed -i "s/\/\/ \[START.*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
43+
sed -i "s/\/\/ \[END.*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
44+
fi
3145

3246
echo "Remove region tags from ${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
33-
sed -i "" "s/<!--\s*\[START .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
34-
sed -i "" "s/<!--\s*\[END .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
47+
if [[ "$OSTYPE" == "darwin"* ]]; then
48+
sed -i "" "s/<!--\s*\[START .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
49+
sed -i "" "s/<!--\s*\[END .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
50+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
51+
sed -i "s/<!--\s*\[START .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
52+
sed -i "s/<!--\s*\[END .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
53+
fi
3554

3655
echo "Remove region tags from ${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
37-
sed -i "" "s/\/\* \[START maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
38-
sed -i "" "s/\/\* \[END maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
56+
if [[ "$OSTYPE" == "darwin"* ]]; then
57+
sed -i "" "s/\/\* \[START maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
58+
sed -i "" "s/\/\* \[END maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
59+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
60+
sed -i "s/\/\* \[START maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
61+
sed -i "s/\/\* \[END maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
62+
fi
3963

4064
# Generate demo.details.
4165
echo "Generate ${DIST_DIR}/samples/${NAME}/jsfiddle/demo.details"
@@ -44,7 +68,7 @@ cat > "${DIST_DIR}/samples/${NAME}/jsfiddle/demo.details" << EOF
4468
name: ${NAME}
4569
authors:
4670
- Geo Developer IX Documentation Team
47-
tags:s
71+
tags:
4872
- google maps
4973
load_type: h
5074
description: Sample code supporting Google Maps Platform JavaScript API documentation.

samples/new1.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ cat > "${OUTPUT_DIR}/${NAME}/package.json" << EOF
7070
"name": "@js-api-samples/${NAME}",
7171
"version": "1.0.0",
7272
"scripts": {
73-
"build": "tsc && bash ../jsfiddle.sh ${NAME} && bash ../app.sh ${NAME} && bash ../docs.sh ${NAME} && npm run build:vite --workspace=.",
73+
"build": "tsc && bash ../jsfiddle.sh ${NAME} && bash ../app.sh ${NAME} && bash ../docs.sh ${NAME} && npm run build:vite --workspace=. && bash ../dist.sh ${NAME}",
7474
"test": "tsc && npm run build:vite --workspace=.",
7575
"start": "tsc && vite build --base './' && vite",
7676
"build:vite": "vite build --base './'",

0 commit comments

Comments
 (0)