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.
1113NAME=$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.
1931mkdir -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.
2841echo " 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
3250echo " 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
3659echo " 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.
4169echo " Generate ${DIST_DIR} /samples/${NAME} /jsfiddle/demo.details"
@@ -44,7 +72,7 @@ cat > "${DIST_DIR}/samples/${NAME}/jsfiddle/demo.details" << EOF
4472name: ${NAME}
4573authors:
4674 - Geo Developer IX Documentation Team
47- tags:s
75+ tags:
4876 - google maps
4977load_type: h
5078description: Sample code supporting Google Maps Platform JavaScript API documentation.
0 commit comments