bash | Cell 0 | install node | Search

These commands navigate to a specific directory, install a browser automation library, and create three new directories: Collections, searches, and screenshots. The directory creation commands include error handling to ensure the execution continues even if a directory already exists or cannot be created.

Run example

npm run import -- "node webdriver support"

node webdriver support

cd ~/jupytangular \
   && npm install wdio webdriverio \
   && mkdir ~/Collections || true \
   && mkdir ~/Collections/searches || true \
   && mkdir ~/Collections/screenshots || true

What the code could have been:

bash
#!/bin/bash

# Set the directory path
JUPYTANGULAR_DIR="~/jupytangular"

# Function to create directory
create_directory() {
  local dir_path=$1
  if [! -d "$dir_path" ]; then
    mkdir -p "$dir_path"
    echo "Directory created: $dir_path"
  else
    echo "Directory already exists: $dir_path"
  fi
}

# Create directories
cd "$JUPYTANGULAR_DIR" || exit
echo "Installing dependencies..."
npm install wdio webdriverio
echo "Directories created..."

# Create subdirectories in ~/Collections if they don't exist
create_directory "~/Collections"
create_directory "~/Collections/searches"
create_directory "~/Collections/screenshots"

# TODO: Consider adding error handling for npm install

Code Breakdown

Command 1: cd ~/jupytangular

Command 2: npm install wdio webdriverio

Command 3: mkdir ~/Collections || true

Command 4: mkdir ~/Collections/searches || true

Command 5: mkdir ~/Collections/screenshots || true