Skip to content

Commit e3d1e06

Browse files
authored
fix: Fixes path generation for all scripts; adds conditional mac/linux logic. (#109)
1 parent 83d7544 commit e3d1e06

File tree

11 files changed

+136
-48
lines changed

11 files changed

+136
-48
lines changed

samples/add-map/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@js-api-samples/add-map",
33
"version": "1.0.0",
44
"scripts": {
5-
"build": "tsc && bash ../jsfiddle.sh add-map && bash ../app.sh add-map && bash ../docs.sh add-map && npm run build:vite --workspace=.",
5+
"build": "tsc && bash ../jsfiddle.sh add-map && bash ../app.sh add-map && bash ../docs.sh add-map && npm run build:vite --workspace=. && bash ../dist.sh add-map",
66
"test": "tsc && npm run build:vite --workspace=.",
77
"start": "tsc && vite build --base './' && vite",
88
"build:vite": "vite build --base './'",

samples/app.sh

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,43 @@
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

1010
# 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 )"
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
22+
23+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
24+
APP_DIR="${PROJECT_ROOT}/dist/samples/${NAME}/app"
1325

14-
APP_DIR="../../dist/samples/${NAME}/app"
15-
MAIN_DIR="../../dist/samples/${NAME}"
26+
echo "PROJECT_ROOT ${PROJECT_ROOT}"
27+
echo "APP_DIR ${APP_DIR}"
28+
echo "SAMPLE_DIR ${SAMPLE_DIR}"
1629

1730
# Create the new folders.
1831
mkdir -p ${APP_DIR}
1932
mkdir -p ${MAIN_DIR}
2033

2134
# 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}"
35+
cp "${SCRIPT_DIR}/${NAME}/index.html" "${APP_DIR}/index.html"
36+
cp "${SCRIPT_DIR}/${NAME}/index.ts" "${APP_DIR}/index.ts"
37+
cp "${SCRIPT_DIR}/${NAME}/style.css" "${APP_DIR}/style.css"
38+
cp "${SCRIPT_DIR}/${NAME}/package.json" "${APP_DIR}/package.json"
39+
cp "${SCRIPT_DIR}/${NAME}/tsconfig.json" "${APP_DIR}/tsconfig.json"
40+
cp "${SCRIPT_DIR}/${NAME}/README.md" "${APP_DIR}/README.md"
41+
cp "${SCRIPT_DIR}/.env" "${APP_DIR}/.env"
3042

3143
# Generate .eslintsrc.json
3244
touch "${APP_DIR}/.eslintsrc.json"

samples/dist.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
# Relative path to the top-level of the examples folder.
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
22+
23+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
24+
SAMPLE_DIR="${PROJECT_ROOT}/dist/samples/${NAME}"
25+
26+
# Copy Vite output files to /dist/samples/${NAME}/dist
27+
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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
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"
6+
7+
# Define path based on platform.
8+
if [[ "$OSTYPE" == "darwin"* ]]; then
9+
echo "Hello, Mac!"
10+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11+
echo "Project path: ${SCRIPT_DIR}"
12+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
13+
echo "Hello, gLinux!"
14+
SCRIPT_DIR="$(dirname "$0")"
15+
echo "Project path: ${SCRIPT_DIR}"
16+
fi
617

7-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Script directory (/samples)
818
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
919
DIST_DIR="$PROJECT_ROOT/dist"
1020

21+
echo "Project root ${PROJECT_ROOT}"
22+
1123
# Create the output file.
1224
OUTPUT_FILE="index.html"
1325

samples/jsfiddle.sh

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,63 @@
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

1315
# /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)
16-
DIST_DIR="${PROJECT_ROOT}/dist"
16+
# Define path based on platform.
17+
if [[ "$OSTYPE" == "darwin"* ]]; then
18+
echo "Hello, Mac!"
19+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
20+
echo "Project path: ${SCRIPT_DIR}"
21+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
22+
echo "Hello, gLinux!"
23+
SCRIPT_DIR="$(dirname "$0")"
24+
echo "Project path: ${SCRIPT_DIR}"
25+
fi
26+
27+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
28+
DIST_DIR="$PROJECT_ROOT/dist"
1729

1830
# Create a new folder.
1931
mkdir -p "${DIST_DIR}/samples/${NAME}/jsfiddle"
2032

2133
# 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"
34+
echo "Copy ${SCRIPT_DIR}/${NAME}/index.js to ${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
35+
cp "${SCRIPT_DIR}/${NAME}/index.js" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
36+
cp "${SCRIPT_DIR}/${NAME}/index.html" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
37+
cp "${SCRIPT_DIR}/${NAME}/style.css" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
2638

2739
# Remove region tags from files by type, since they all have different comment conventions.
40+
# We use a conditional here since sed behaves differently on Linux.
2841
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"
42+
if [[ "$OSTYPE" == "darwin"* ]]; then
43+
sed -i "" "s/\/\/ \[START .*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
44+
sed -i "" "s/\/\/ \[END .*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
45+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
46+
sed -i "s/\/\/ \[START.*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
47+
sed -i "s/\/\/ \[END.*]//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.js"
48+
fi
3149

3250
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"
51+
if [[ "$OSTYPE" == "darwin"* ]]; then
52+
sed -i "" "s/<!--\s*\[START .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
53+
sed -i "" "s/<!--\s*\[END .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
54+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
55+
sed -i "s/<!--\s*\[START .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
56+
sed -i "s/<!--\s*\[END .*\]\s*-->//g" "${DIST_DIR}/samples/${NAME}/jsfiddle/index.html"
57+
fi
3558

3659
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"
60+
if [[ "$OSTYPE" == "darwin"* ]]; then
61+
sed -i "" "s/\/\* \[START maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
62+
sed -i "" "s/\/\* \[END maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
63+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
64+
sed -i "s/\/\* \[START maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
65+
sed -i "s/\/\* \[END maps_.*] \*\///g" "${DIST_DIR}/samples/${NAME}/jsfiddle/style.css"
66+
fi
3967

4068
# Generate demo.details.
4169
echo "Generate ${DIST_DIR}/samples/${NAME}/jsfiddle/demo.details"
@@ -44,7 +72,7 @@ cat > "${DIST_DIR}/samples/${NAME}/jsfiddle/demo.details" << EOF
4472
name: ${NAME}
4573
authors:
4674
- Geo Developer IX Documentation Team
47-
tags:s
75+
tags:
4876
- google maps
4977
load_type: h
5078
description: Sample code supporting Google Maps Platform JavaScript API documentation.

samples/map-simple/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@js-api-samples/map-simple",
33
"version": "1.0.0",
44
"scripts": {
5-
"build": "tsc && bash ../jsfiddle.sh map-simple && bash ../app.sh map-simple && bash ../docs.sh map-simple && npm run build:vite --workspace=.",
5+
"build": "tsc && bash ../jsfiddle.sh map-simple && bash ../app.sh map-simple && bash ../docs.sh map-simple && npm run build:vite --workspace=. && bash ../dist.sh map-simple",
66
"test": "tsc && npm run build:vite --workspace=.",
77
"start": "tsc && vite build --base './' && vite",
88
"build:vite": "vite build --base './'",

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 './'",

samples/place-autocomplete-element/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@js-api-samples/place-autocomplete-element",
33
"version": "1.0.0",
44
"scripts": {
5-
"build": "tsc && bash ../jsfiddle.sh place-autocomplete-element && bash ../app.sh place-autocomplete-element && bash ../docs.sh place-autocomplete-element && npm run build:vite --workspace=.",
5+
"build": "tsc && bash ../jsfiddle.sh place-autocomplete-element && bash ../app.sh place-autocomplete-element && bash ../docs.sh place-autocomplete-element && npm run build:vite --workspace=. && bash ../dist.sh place-autocomplete-element",
66
"test": "tsc && npm run build:vite --workspace=.",
77
"start": "tsc && vite build --base './' && vite",
88
"build:vite": "vite build --base './'",

samples/place-autocomplete-map/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@js-api-samples/place-autocomplete-map",
33
"version": "1.0.0",
44
"scripts": {
5-
"build": "tsc && bash ../jsfiddle.sh place-autocomplete-map && bash ../app.sh place-autocomplete-map && bash ../docs.sh place-autocomplete-map && npm run build:vite --workspace=.",
5+
"build": "tsc && bash ../jsfiddle.sh place-autocomplete-map && bash ../app.sh place-autocomplete-map && bash ../docs.sh place-autocomplete-map && npm run build:vite --workspace=. && bash ../dist.sh place-autocomplete-map",
66
"test": "tsc && npm run build:vite --workspace=.",
77
"start": "tsc && vite build --base './' && vite",
88
"build:vite": "vite build --base './'",

0 commit comments

Comments
 (0)