Bash to initialize a project

Most of the time I start an experiment/idea/project with an empty directory.

mkdir newbootgoofin
cd newbootgoofin
echo "{}" > package.json
touch index.js
npm i thing-i-read-about
code .

I don't even use npm init on most occasions.

This is all fine and well until I need to "upgrade" it to a "real" project. In my case that's almost always adding Architect and usually Enhance. I've got this script in ~/bin/enhance-init

#!/bin/bash

set -euo pipefail

if [ $# -eq 0 ]; then
    echo "Please provide a project name."
    exit 1
fi

PROJECT_NAME=$1

# Create project directory
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME" || exit

# I'll definitely leave notes about wtf I was doing.
touch README.md
# Definitely.

# Create Enhance things
mkdir -p pulic app/api app/pages app/elements
touch app/pages/index.html
touch app/api/index.mjs
touch app/head.mjs

# Create package.json if needed
if [ ! -f package.json ]; then
    echo -e "{\n  \"name\":\"$PROJECT_NAME\"\n}" > package.json
    echo "Created package.json"
fi

# add .gitignore; I'll forget otherwise
if [ ! -f .gitignore ]; then
    echo -e "node_modules/\n" > .gitignore
fi

# Add npm packages but don't download packages yet
npm install --package-lock-only @enhance/arc-plugin-enhance
npm install --package-lock-only -D @architect/architect @enhance/types

# Create app.arc manifest
if ! ls *.arc 1> /dev/null 2>&1; then
    echo -e "@app\n$PROJECT_NAME\n" > app.arc
    echo "Created app.arc"
fi

# Check if @plugins exists and add enhance/arc-plugin-enhance
if grep -q "@plugins" app.arc; then
    # If @plugins exists, add the new line right after it
    sed -i.bak -e $'/^@plugins/a\\\nenhance/arc-plugin-enhance' app.arc && rm app.arc.bak
    echo "Added Enhance to existing @plugins section"
else
    # If @plugins doesn't exist, add it with the new line
    echo -e "\n@plugins\nenhance/arc-plugin-enhance" >> app.arc
    echo "Added new @plugins section with Enhance"
fi

echo "\"$PROJECT_NAME\" initialized."
echo "run: cd $PROJECT_NAME && npm i"

So now I can...

cd ..
enhance-init newbootgoofin

💥

I tried to make it as safe as possible so as to not override files or clobber work. It will even start a new project if it doesn't exist.

Adapt as you see fit.

from Sanity.io (109.37ms) to HTML (0.48ms)