Skip to content

Commit f85cbd1

Browse files
authored
fix: Fixes path generation for all scripts. (#119)
1 parent be43799 commit f85cbd1

File tree

4 files changed

+26
-47
lines changed

4 files changed

+26
-47
lines changed

samples/app.sh

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,21 @@ echo ">>>Running app.sh"
77

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-
# /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
10+
# /Users/[USERNAME]/git/js-api-samples/samples
2211

12+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
2313
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
24-
APP_DIR="${PROJECT_ROOT}/dist/samples/${NAME}/app"
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}"
2520

26-
echo "PROJECT_ROOT ${PROJECT_ROOT}"
27-
echo "APP_DIR ${APP_DIR}"
28-
echo "SAMPLE_DIR ${SAMPLE_DIR}"
21+
APP_DIR="${PROJECT_ROOT}/dist/samples/${NAME}/app"
2922

3023
# Create the new folders.
3124
mkdir -p ${APP_DIR}
32-
mkdir -p ${MAIN_DIR}
3325

3426
# Copy files
3527
cp "${SCRIPT_DIR}/${NAME}/index.html" "${APP_DIR}/index.html"

samples/dist.sh

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,14 @@ echo ">>>Running dist.sh"
77

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-
# /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
10+
# /Users/[USERNAME]/git/js-api-samples/samples
2211

12+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
2313
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
14+
DIST_DIR="${PROJECT_ROOT}/dist"
2415
SAMPLE_DIR="${PROJECT_ROOT}/dist/samples/${NAME}"
2516

17+
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
18+
2619
# Copy Vite output files to /dist/samples/${NAME}/dist
2720
cp -r "${SCRIPT_DIR}/${NAME}/dist" "${SAMPLE_DIR}"

samples/generate-index.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ echo ">>>Running generate-index.sh"
66

77
# /Users/[USERNAME]/git/js-api-samples/samples
88

9-
PROJECT_ROOT="$(pwd)"
10-
SCRIPT_DIR="${PROJECT_ROOT}/samples"
9+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
10+
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
1111
DIST_DIR="${PROJECT_ROOT}/dist"
1212

13-
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
1413
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
15-
echo "pwd: $(pwd)"
1614

1715
# Create the output file.
1816
OUTPUT_FILE="index.html"
@@ -48,7 +46,7 @@ echo "</html>" >> "${OUTPUT_FILE}"
4846

4947
echo "HTML file generated: ${OUTPUT_FILE}"
5048

51-
echo "from ${SCRIPT_DIR}/${OUTPUT_FILE}"
49+
echo "from ${PROJECT_ROOT}/${OUTPUT_FILE}"
5250
echo "to ${DIST_DIR}/${OUTPUT_FILE}"
5351

54-
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: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@ echo ">>>Running jsfiddle.sh"
1212
# Generate JSFiddle output as part of the build process.
1313
NAME=$1 # The name of the folder, taken from package.json "build" line.
1414

15-
# /Users/[USERNAME]/git/js-api-samples/samples or similar
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
15+
# /Users/[USERNAME]/git/js-api-samples/samples
2616

17+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Script directory (/samples)
2718
PROJECT_ROOT=$(dirname "$SCRIPT_DIR") # Get the parent directory (js-api-samples)
28-
DIST_DIR="$PROJECT_ROOT/dist"
19+
DIST_DIR="${PROJECT_ROOT}/dist"
20+
21+
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
22+
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
23+
echo "DIST_DIR: ${DIST_DIR}"
24+
echo "NAME: ${NAME}"
2925

3026
# Create a new folder.
3127
mkdir -p "${DIST_DIR}/samples/${NAME}/jsfiddle"

0 commit comments

Comments
 (0)