diff --git a/scripts/build.sh b/scripts/build.sh index f0cbb867..c7ee1faf 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,7 +1,44 @@ #!/usr/bin/env bash -rm -rf build -node_modules/.bin/babel --minified --no-comments src -d build -cp -r src/components/ContractSchema/spec build/components/ContractSchema/spec -cp scripts/tronbox.js build/. -chmod +x build/tronbox.js +# --- Error Handling & Safety Rules --- +# -e: Exit immediately if a command fails +# -u: Treat unset variables as an error +# -o pipefail: Catch errors within pipelines +set -eou pipefail + +# --- Configuration --- +SOURCE_DIR="src" +BUILD_DIR="build" +BABEL_BIN="./node_modules/.bin/babel" + +echo "๐Ÿงน Cleaning previous builds..." +rm -rf "$BUILD_DIR" + +# Ensure Babel exists before execution (Fail-fast) +if [[ ! -f "$BABEL_BIN" ]]; then + echo "โŒ Error: Babel binary not found at $BABEL_BIN. Run 'npm install' first." + exit 1 +fi + +echo "๐Ÿš€ Transpiling source code with Babel..." +# --minified: Shrinks code size +# --no-comments: Removes developer notes (Security: hides sensitive TODOs) +"$BABEL_BIN" --minified --no-comments "$SOURCE_DIR" -d "$BUILD_DIR" + +[Image of JavaScript compilation process with Babel from ES6 to ES5] + +echo "๐Ÿ“ฆ Copying static assets and schemas..." +# Using --parents or creating dirs to ensure path integrity +mkdir -p "$BUILD_DIR/components/ContractSchema/spec" +cp -r "$SOURCE_DIR/components/ContractSchema/spec/"* "$BUILD_DIR/components/ContractSchema/spec/" + +echo "๐Ÿ“œ Preparing execution scripts..." +# Copying the utility script and securing permissions +cp scripts/tronbox.js "$BUILD_DIR/" + +# Security Check: Only add execution bit to the specific script +chmod +x "$BUILD_DIR/tronbox.js" + +[Image of a build pipeline architecture showing source to distribution flow] + +echo "โœ… Build process completed successfully!"