BASH

Automating Basic Project Directory Structure Creation

A simple bash script to quickly scaffold a new web project's common directories like src, public, config, and logs, enhancing development workflow.

#!/bin/bash
# Script to create a basic project directory structure

PROJECT_NAME=$1
declare -a DIRS=("src" "src/components" "src/pages" "public" "config" "logs" "scripts")

if [ -z "$PROJECT_NAME" ]; then
  echo "Usage: $0 <project_name>"
  exit 1
fi

if [ -d "$PROJECT_NAME" ]; then
  echo "Error: Directory '$PROJECT_NAME' already exists."
  exit 1
fi

echo "Creating project structure for '$PROJECT_NAME'..."
mkdir "$PROJECT_NAME" && cd "$PROJECT_NAME" || exit 1

for DIR in "${DIRS[@]}"; do
  mkdir -p "$DIR"
  echo "  - Created $DIR/"
done

# Create some placeholder files
touch "public/index.html"
echo "console.log('Hello, World!');" > "src/app.js"
echo "Project '$PROJECT_NAME' scaffolding complete."
How it works: This script accepts a project name as an argument and creates a new directory with that name. Inside, it generates a set of predefined subdirectories common to many web projects (e.g., `src`, `public`, `config`, `logs`, `scripts`) using `mkdir -p`. It also adds basic placeholder files like `index.html` and `app.js` to jumpstart development, streamlining the setup process for new projects.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs