69 lines
1.7 KiB
Bash
Executable File
69 lines
1.7 KiB
Bash
Executable File
|
|
#!/usr/bin/env bash
|
|
|
|
# This script is designed to work on:
|
|
# - macOS
|
|
# - Linux
|
|
# - Windows when using Git Bash (recommended)
|
|
#
|
|
# On Windows, run it from Git Bash:
|
|
# ./scripts/init_project.sh my-project-name
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
REPO_ROOT=$(cd -- "$SCRIPT_DIR/.." && pwd)
|
|
cd "$REPO_ROOT"
|
|
|
|
if [ -d ".git" ]; then
|
|
echo "Error: this repository still contains a .git directory."
|
|
echo "Please remove .git first or run this script only on a fresh copy of the template."
|
|
exit 1
|
|
fi
|
|
|
|
PROJECT_NAME=${1:-}
|
|
|
|
if [ -z "$PROJECT_NAME" ]; then
|
|
echo "Usage: ./scripts/init_project.sh <project-name>"
|
|
exit 1
|
|
fi
|
|
|
|
if ! printf '%s' "$PROJECT_NAME" | grep -Eq '^[a-zA-Z0-9._-]+$'; then
|
|
echo "Error: project name contains unsupported characters."
|
|
echo "Use only letters, numbers, dots, underscores, and hyphens."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Creating project: $PROJECT_NAME"
|
|
echo "Working directory: $REPO_ROOT"
|
|
|
|
|
|
# rename project metadata (portable sed usage for macOS, Linux, and Git Bash on Windows)
|
|
# create temporary backup files (.bak) and remove them after replacement
|
|
if [ ! -f "README.md" ] || [ ! -f "pyproject.toml" ]; then
|
|
echo "Error: README.md or pyproject.toml not found in repository root."
|
|
exit 1
|
|
fi
|
|
sed -i.bak "s/New Project/$PROJECT_NAME/g" README.md
|
|
sed -i.bak "s/python-ai-dev-template/$PROJECT_NAME/g" pyproject.toml
|
|
|
|
rm -f README.md.bak pyproject.toml.bak
|
|
|
|
# reset git history
|
|
rm -rf .git
|
|
git init
|
|
git branch -M main
|
|
|
|
echo ""
|
|
echo "Project initialized."
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo ""
|
|
echo "git add ."
|
|
echo "git commit -m \"Initial $PROJECT_NAME\""
|
|
echo ""
|
|
echo "Create a remote repository and run:"
|
|
echo ""
|
|
echo "git remote add origin <repo-url>"
|
|
echo "git push -u origin main"
|