From f4869e51d5e7ae1de0e7e1831cf0b2b18abbacfb Mon Sep 17 00:00:00 2001 From: skyc4ffe1ne Date: Sat, 25 Oct 2025 21:18:53 +0200 Subject: [PATCH] Improving the scripts --- scripts/dev.sh | 30 ++++++++++++++++++------------ scripts/log.sh | 22 ++++++++++++++++++++++ scripts/test.sh | 14 +++++++++----- scripts/upload.sh | 14 +++++++++----- 4 files changed, 58 insertions(+), 22 deletions(-) create mode 100755 scripts/log.sh diff --git a/scripts/dev.sh b/scripts/dev.sh index 3cded68..c52c02a 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -1,31 +1,35 @@ -#!/bin/bash +#!/usr/bin/env bash + +set -euo pipefail NODE_ID=0 DIR_HOME=$(pwd) DIR_CC_REACT="$DIR_HOME/packages/cc-react" DIR_PLAYGROUND="$DIR_HOME/playground" +source "${DIR_HOME}/scripts/log.sh" + function start() { clear - echo -e "\033[102;30mCleaning for fresh start...\e[0m" + info "Cleaning for fresh start..." rm -rf "$DIR_CC_REACT/dist" rm -rf "$DIR_PLAYGROUND/dist" rm -rf "$DIR_PLAYGROUND/public/js" - mkdir "$DIR_PLAYGROUND/public/js" + mkdir -p "$DIR_PLAYGROUND/public/js" if [ ! -d "$DIR_CC_REACT/node_modules" ]; then - echo -e "\033[103;30mMissing 'node_modules' folder in 'cc-react', installing...\e[0m" + info "Missing 'node_modules' folder in 'cc-react', installing..." cd "$DIR_CC_REACT" npm install > /dev/null 2>&1 fi if [ ! -d "$DIR_PLAYGROUND/node_modules" ]; then - echo -e "\033[103;30mMissing 'node_modules' folder in the 'playground', installing...\e[0m" + info "Missing 'node_modules' folder in the 'playground', installing..." cd "$DIR_PLAYGROUND" npm install > /dev/null 2>&1 fi - echo -e "\033[102;30mLinking 'cc-react' package to the 'playground'...\e[0m" + info "Linking 'cc-react' package to the 'playground'..." cd "$DIR_CC_REACT" npm link > /dev/null cd "$DIR_PLAYGROUND" @@ -33,12 +37,12 @@ function start() { cd "$DIR_CC_REACT" npx tsc -w > build.log 2>&1 & - echo -e "\033[102;30mWaiting for TypeScript's Watch Mode in 'cc-react'...\e[0m" + info "Waiting for TypeScript's Watch Mode in 'cc-react'..." grep -m 1 "Found" <(tail -f build.log) > /dev/null cd "$DIR_PLAYGROUND" npx tsc -w > build.log 2>&1 & - echo -e "\033[102;30mWaiting for TypeScript's Watch Mode in the 'playground'...\e[0m" + info "Waiting for TypeScript's Watch Mode in the 'playground'..." grep -m 1 "Found" <(tail -f build.log) > /dev/null @@ -57,14 +61,16 @@ function execute() { function before_execute() { - kill $NODE_ID + kill "$NODE_ID" clear } -start "\033[1;31mExecution started. Executing commands...\e[0m" +start "\e[1;31mExecution started. Executing commands...\e[0m" while inotifywait -q -r -e modify,create,delete,move "$DIR_CC_REACT/dist" "$DIR_PLAYGROUND/dist" > /dev/null; do before_execute - execute "\033[1;31mDirectory changes detected. Re-executing commands...\e[0m" -done \ No newline at end of file + execute "\e[1;31mDirectory changes detected. Re-executing commands...\e[0m" +done + + diff --git a/scripts/log.sh b/scripts/log.sh new file mode 100755 index 0000000..c26d3a9 --- /dev/null +++ b/scripts/log.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +Color_Reset='\e[0m' + +Red='\e[0;41m' +Green='\e[0;42m' +Yellow='\e[0;43m' + + +function error(){ + echo -e "${Red}Error ${Color_Reset}" "$*" >&2 + exit 1; +} + +function info() { + echo -e "$*" +} + + +function success() { + echo -e "${Green}Success${Color_Reset} $*" +} diff --git a/scripts/test.sh b/scripts/test.sh index 72723c6..fefade0 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,10 +1,14 @@ -#!/bin/bash +#!/usr/bin/env bash + +set -euo pipefail DIR_HOME=$(pwd) DIR_CC_REACT="$DIR_HOME/packages/cc-react" DIR_PLAYGROUND="$DIR_HOME/playground" DIR_TESTS="$DIR_HOME/testing" +source "${DIR_HOME}/scripts/log.sh" + clear cd "$DIR_TESTS/environments" ENVIRONMENTS=$(echo *) @@ -18,14 +22,14 @@ for environment in $ENVIRONMENTS; do BUILD_LOG="$FOLDER/logs/build.log" RUN_LOG="$FOLDER/logs/run.log" - echo -e "\033[102;30m($environment) Removing old containers...\e[0m" + info "($environment) Removing old containers..." docker rm "$DOCKER_NAME" > /dev/null - echo -e "\033[102;30m($environment) Building new images (output in $BUILD_LOG)...\e[0m" + info "($environment) Building new images (output in $BUILD_LOG)..." docker build -t "$DOCKER_TAG" --debug --file "$FOLDER/$environment.Dockerfile" --progress=plain . &> "$BUILD_LOG" - echo -e "\033[102;30m($environment) Running new images (output in $RUN_LOG)...\e[0m" + info "($environment) Running new images (output in $RUN_LOG)..." docker run --name "$DOCKER_NAME" "$DOCKER_TAG" > /dev/null docker logs "$DOCKER_NAME" > "$RUN_LOG" ) & done -wait \ No newline at end of file +wait diff --git a/scripts/upload.sh b/scripts/upload.sh index d8f7751..762928c 100755 --- a/scripts/upload.sh +++ b/scripts/upload.sh @@ -1,16 +1,20 @@ -#!/bin/bash +#!/usr/bin/env bash + +set -euo pipefail DIR_HOME=$(pwd) DIR_CC_REACT="$DIR_HOME/packages/cc-react" DIR_PLAYGROUND="$DIR_HOME/playground" +source "${DIR_HOME}/scripts/log.sh" + clear cd "$DIR_CC_REACT" -echo -e "\033[102;30mCleaning all 'dist'...\e[0m" +info "Cleaning all 'dist'..." rm -rf "$DIR_CC_REACT/dist" -echo -e "\033[102;30mCleaning all 'node_modules'...\e[0m" +info "Cleaning all 'node_modules'..." rm -rf "$DIR_CC_REACT/node_modules" -echo -e "\033[102;30mRe-installing packages...\e[0m" +info "Re-installing packages..." npm install npx tsc -npm publish --access=public \ No newline at end of file +npm publish --access=public