Fix npm installation issues during setup
- Created reusable ensure_npm_packages function for consistency - Fixed npm install being called in wrong directory during installation - Added proper directory context preservation for npm operations - Ensured package.json file is always copied to installation directory - Added checks to prevent redundant npm installations - Improved error handling and reporting for npm operations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
16c73bca70
commit
83222078d9
@ -295,10 +295,8 @@ EOF
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install npm dependencies
|
# Install npm dependencies using our common function
|
||||||
log "INFO" "Updating npm dependencies..."
|
ensure_npm_packages "$INSTALL_DIR" || {
|
||||||
cd "$SCRIPT_DIR"
|
|
||||||
npm install || {
|
|
||||||
log "ERROR" "NPM installation failed"
|
log "ERROR" "NPM installation failed"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -393,10 +391,8 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Step 6: Install npm dependencies
|
# Step 6: Install npm dependencies using our common function
|
||||||
log "INFO" "Installing npm dependencies..."
|
ensure_npm_packages "$INSTALL_DIR" || {
|
||||||
cd "$SCRIPT_DIR"
|
|
||||||
npm install || {
|
|
||||||
log "ERROR" "NPM installation failed"
|
log "ERROR" "NPM installation failed"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,48 @@ function create_dir_if_not_exists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to finalize the setup (permissions, etc.)
|
# Function to finalize the setup (permissions, etc.)
|
||||||
|
# Function to ensure NPM packages are properly installed
|
||||||
|
function ensure_npm_packages() {
|
||||||
|
local install_dir=$1
|
||||||
|
|
||||||
|
# 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" || {
|
||||||
|
log "ERROR" "Failed to copy package.json to installation directory"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install NPM packages if not already installed or if it's an update
|
||||||
|
if [ ! -d "$install_dir/node_modules" ] || [ "$IS_UPDATE" = "true" ]; then
|
||||||
|
log "INFO" "Installing NPM packages in $install_dir..."
|
||||||
|
|
||||||
|
# Save current directory
|
||||||
|
local current_dir=$(pwd)
|
||||||
|
|
||||||
|
# Change to install directory and install packages
|
||||||
|
cd "$install_dir" || {
|
||||||
|
log "ERROR" "Failed to change to installation directory: $install_dir"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
npm install || {
|
||||||
|
log "ERROR" "NPM installation failed in $install_dir"
|
||||||
|
cd "$current_dir" # Return to original directory
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
cd "$current_dir"
|
||||||
|
log "INFO" "NPM packages successfully installed in $install_dir"
|
||||||
|
else
|
||||||
|
log "INFO" "NPM packages appear to be already installed in $install_dir, skipping"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
function finalize_setup() {
|
function finalize_setup() {
|
||||||
log "INFO" "Setting up final permissions and configurations..."
|
log "INFO" "Setting up final permissions and configurations..."
|
||||||
|
|
||||||
@ -139,9 +181,10 @@ function finalize_setup() {
|
|||||||
create_dir_if_not_exists "$MEDIA_DIR/magazines" "$USER:$USER"
|
create_dir_if_not_exists "$MEDIA_DIR/magazines" "$USER:$USER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install NPM packages
|
# Install npm packages
|
||||||
log "INFO" "Installing NPM packages..."
|
ensure_npm_packages "$INSTALL_DIR" || {
|
||||||
cd $INSTALL_DIR && npm install
|
log "ERROR" "Failed to install NPM packages"
|
||||||
|
}
|
||||||
|
|
||||||
# Handle configuration file
|
# Handle configuration file
|
||||||
if ! update_config_file "$CONFIG_DIR/config.json" "$IS_UPDATE"; then
|
if ! update_config_file "$CONFIG_DIR/config.json" "$IS_UPDATE"; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user