Skip to content

Instantly share code, notes, and snippets.

@wyattowalsh
Last active June 15, 2024 08:14
Show Gist options
  • Save wyattowalsh/3e4e2354c033d69f97c3703df695131c to your computer and use it in GitHub Desktop.
Save wyattowalsh/3e4e2354c033d69f97c3703df695131c to your computer and use it in GitHub Desktop.
setup

Numanac Monorepo 🧑‍🌾


Setup 🌱

Warning

these setup instructions are intended for MacOS (ideally ARM-based) users only.


setup.sh

The setup.sh script is a utility script that installs the necessary tools and software packages for Numanac development. To run the script, use the following command in your terminal (from the project root directory):

chmod +x utils/setup.sh && ./utils/setup.sh

Manual Setup

1. Install Homebrew

Homebrew is a package manager for MacOS. The script checks if Homebrew is installed, and if not, it installs Homebrew.

if ! command -v brew &>/dev/null; then
    echo "Homebrew not found. Installing Homebrew..."
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || { echo "ERROR: Homebrew installation failed."; exit 1; }
    echo "Homebrew installed successfully."
else
    echo "Homebrew is already installed."
    brew update || { echo "ERROR: Homebrew update failed."; exit 1; }
fi

Tip

If Homebrew is already installed, the script will update it to the latest version.

2. Install Necessary Software

The script installs Visual Studio Code, Git, GitHub CLI, wget, and Docker using Homebrew.

echo "Installing necessary software using Homebrew..."
brew install --cask visual-studio-code || { echo "ERROR: VSCode installation failed."; exit 1; }
brew install git gh wget docker || { echo "ERROR: Software installation failed."; exit 1; }
echo "Software installed successfully."

3. Setup NVM and Install Node.js

NVM (Node Version Manager) is installed, followed by Node.js.

echo "Setting up nvm (Node Version Manager)..."
wget -qO- "https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh" | bash || { echo "ERROR: nvm installation failed."; exit 1; }
source "$HOME/.nvm/nvm.sh"
nvm install node || { echo "ERROR: Node.js installation failed."; exit 1; }
nvm use node
echo "nvm and Node.js setup completed."

Tip

Make sure to source the nvm script to ensure NVM is properly set up.

4. Authenticate with GitHub

GitHub authentication is handled via the GitHub CLI.

echo "Authenticating with GitHub..."
echo "Please follow the prompts to authenticate with GitHub."
gh auth login || { echo "ERROR: GitHub authentication failed."; exit 1; }
echo "GitHub authentication successful."

Important

Follow the prompts to authenticate with GitHub to ensure you have access to necessary repositories.

5. Clone the Repository

The script clones the Numanac repository from GitHub.

echo "Cloning the Numanac repository..."
git clone "https://github.com/numanac/numanac.git" || { echo "ERROR: Failed to clone the repository."; exit 1; }
cd "numanac" || { echo "ERROR: Failed to change directory to numanac."; exit 1; }
echo "Repository cloned and directory changed successfully."

6. Open Project in VSCode

The script opens the Numanac project in Visual Studio Code.

echo "Opening the project in VSCode..."
code . || { echo "ERROR: Failed to open VSCode."; exit 1; }
echo "Project opened in VSCode successfully."

7. Launch Documentation Site

Navigate to the docs directory and launch the documentation site.

echo "Launching the Numanac documentation site..."
cd "./docs" || { echo "ERROR: Failed to change directory to ./docs."; exit 1; }
npm install || { echo "ERROR: npm install failed."; exit 1; }
npm start || { echo "ERROR: Failed to launch the documentation site."; exit 1; }
echo "Documentation site launched successfully at http://localhost:3000."
Success! The documentation site will be available at http://localhost:3000.

#!/bin/bash
# ==============================================================================
# File: setup.sh
# Description: This script automates the setup of the Numanac project on a MacOS
# system. It installs necessary software, sets up the development
# environment, and launches the documentation site.
# Usage: ./setup.sh
# ==============================================================================
# Variables
REPO_URL="https://github.com/numanac/numanac.git"
REPO_DIR="numanac"
DOCS_DIR="./docs"
NVM_VERSION="v0.39.7"
# Functions
# Log message function
log_message() {
echo "$(date +"%Y-%m-%d %T") : $1"
}
# Error handling function
handle_error() {
log_message "ERROR: $1"
exit 1
}
# Install Homebrew
install_homebrew() {
if ! command -v brew &>/dev/null; then
log_message "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || handle_error "Homebrew installation failed."
log_message "Homebrew installed successfully."
else
log_message "Homebrew is already installed."
brew update || handle_error "Homebrew update failed."
fi
}
# Install software using Homebrew
install_software() {
log_message "Installing necessary software using Homebrew..."
brew install --cask visual-studio-code || handle_error "VSCode installation failed."
brew install git gh wget docker || handle_error "Software installation failed."
log_message "Software installed successfully."
}
# Setup nvm and install Node.js
setup_nvm() {
log_message "Setting up nvm (Node Version Manager)..."
wget -qO- "https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh" | bash || handle_error "nvm installation failed."
source "$HOME/.nvm/nvm.sh"
nvm install node || handle_error "Node.js installation failed."
nvm use node
log_message "nvm and Node.js setup completed."
}
# Setup Git and authenticate with GitHub
setup_git() {
log_message "Authenticating with GitHub..."
echo "Please follow the prompts to authenticate with GitHub."
gh auth login || handle_error "GitHub authentication failed."
log_message "GitHub authentication successful."
}
# Clone the repository
clone_repo() {
log_message "Cloning the Numanac repository..."
git clone "$REPO_URL" || handle_error "Failed to clone the repository."
cd "$REPO_DIR" || handle_error "Failed to change directory to $REPO_DIR."
log_message "Repository cloned and directory changed successfully."
}
# Launch the documentation site
launch_docs_site() {
log_message "Launching the Numanac documentation site..."
cd "$DOCS_DIR" || handle_error "Failed to change directory to $DOCS_DIR."
npm install || handle_error "npm install failed."
npm start || handle_error "Failed to launch the documentation site."
log_message "Documentation site launched successfully at http://localhost:3000."
}
# Open project root in VSCode
open_vscode() {
log_message "Opening the project in VSCode..."
code . || handle_error "Failed to open VSCode."
log_message "Project opened in VSCode successfully."
}
# Main script execution
main() {
log_message "Starting the setup process..."
install_homebrew
install_software
setup_nvm
setup_git
clone_repo
open_vscode
launch_docs_site
log_message "Setup process completed successfully."
}
# Execute the main function
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment