diff --git a/modules/utils-module.sh b/modules/utils-module.sh index 4b17e23..b61ce52 100644 --- a/modules/utils-module.sh +++ b/modules/utils-module.sh @@ -104,19 +104,21 @@ function ensure_npm_packages() { # First ensure the installation directory exists if [ ! -d "$install_dir" ]; then log "INFO" "Creating installation directory: $install_dir" - mkdir -p "$install_dir" || { + mkdir -p "$install_dir" + if [ $? -ne 0 ]; then log "ERROR" "Failed to create installation directory: $install_dir" return 1 - } - } + fi + fi # Ensure data directory exists if [ ! -d "$install_dir/data" ]; then log "INFO" "Creating data directory: $install_dir/data" - mkdir -p "$install_dir/data" || { + mkdir -p "$install_dir/data" + if [ $? -ne 0 ]; then log "ERROR" "Failed to create data directory: $install_dir/data" return 1 - } + fi # Initialize empty data files echo "[]" > "$install_dir/data/rss-feeds.json" @@ -127,10 +129,11 @@ function ensure_npm_packages() { # Ensure package.json exists in the installation directory if [ ! -f "$install_dir/package.json" ]; then log "INFO" "Copying package.json to installation directory..." - cp "$SCRIPT_DIR/package.json" "$install_dir/package.json" || { + cp "$SCRIPT_DIR/package.json" "$install_dir/package.json" + if [ $? -ne 0 ]; then log "ERROR" "Failed to copy package.json to installation directory" return 1 - } + fi fi # Install NPM packages if not already installed or if it's an update @@ -141,16 +144,18 @@ function ensure_npm_packages() { local current_dir=$(pwd) # Change to install directory and install packages - cd "$install_dir" || { + cd "$install_dir" + if [ $? -ne 0 ]; then log "ERROR" "Failed to change to installation directory: $install_dir" return 1 - } + fi - npm install || { + npm install + if [ $? -ne 0 ]; then log "ERROR" "NPM installation failed in $install_dir" cd "$current_dir" # Return to original directory return 1 - } + fi # Return to original directory cd "$current_dir"