move scripts + create mkproj

This commit is contained in:
MaksTinyWorkshop
2026-03-08 16:24:41 +01:00
parent 74c3d8e560
commit f539b34415
7 changed files with 240 additions and 15 deletions

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail
# If no arguments are provided, infer project name and path from current directory
if [ $# -eq 0 ]; then
PROJECT_PATH="$(pwd)"
PROJECT_NAME="$(basename "$PROJECT_PATH")"
# If one argument is provided, treat it as the project name and use current directory
elif [ $# -eq 1 ]; then
PROJECT_NAME="$1"
PROJECT_PATH="$(pwd)"
# If two arguments are provided, keep explicit behaviour
elif [ $# -eq 2 ]; then
PROJECT_NAME="$1"
PROJECT_PATH="$2"
else
echo "Usage:"
echo "generate_project_claude.sh"
echo "generate_project_claude.sh <project_name>"
echo "generate_project_claude.sh <project_name> <project_path>"
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATE="$SCRIPT_DIR/70_templates/projet_CLAUDE.md"
OUTPUT="$PROJECT_PATH/CLAUDE.md"
if [ ! -f "$TEMPLATE" ]; then
echo "Template introuvable : $TEMPLATE"
exit 1
fi
mkdir -p "$PROJECT_PATH"
if [ -e "$PROJECT_PATH/CLAUDE.md" ]; then
echo "Erreur : $PROJECT_PATH/CLAUDE.md existe déjà" >&2
exit 1
fi
sed "s/{{PROJECT_NAME}}/${PROJECT_NAME}/g" "$TEMPLATE" > "$OUTPUT"
if [ -e "$PROJECT_PATH/AGENTS.md" ] || [ -L "$PROJECT_PATH/AGENTS.md" ]; then
rm -f "$PROJECT_PATH/AGENTS.md"
fi
ln -s CLAUDE.md "$PROJECT_PATH/AGENTS.md"
echo "✔ CLAUDE.md créé : $OUTPUT"
echo "✔ AGENTS.md -> CLAUDE.md"

148
scripts/mkproj.sh Executable file
View File

@@ -0,0 +1,148 @@
#!/usr/bin/env bash
set -euo pipefail
PROJECT_NAME="${1:-}"
OS="$(uname -s)"
TARGET_BASE=""
PROJECT_PATH=""
if [ -z "$PROJECT_NAME" ]; then
echo "Usage: mkproj <nom_du_projet>"
exit 1
fi
choose_mac_target_base() {
echo "Environnement détecté : Mac"
echo "Choisir le type de projet :"
echo " 1) Projet perso -> /Volumes/TeraSSD/Projets_Dev"
echo " 2) Projet Mindleaf -> /Volumes/TeraSSD/Projets_Dev/__Mindleaf"
printf "Votre choix [1/2] : "
read -r choice
case "$choice" in
1)
TARGET_BASE="/Volumes/TeraSSD/Projets_Dev"
;;
2)
TARGET_BASE="/Volumes/TeraSSD/Projets_Dev/__Mindleaf"
;;
*)
echo "Choix invalide."
exit 1
;;
esac
}
choose_target_base() {
case "$OS" in
Linux)
echo "Environnement détecté : NUC/Linux"
TARGET_BASE="/srv/projects"
;;
Darwin)
choose_mac_target_base
;;
*)
echo "Système non supporté : $OS"
exit 1
;;
esac
}
create_readme() {
cat <<EOF > "$PROJECT_PATH/README.md"
# $PROJECT_NAME
Projet initialisé avec l'environnement Lead_tech.
## Structure attendue
- \`CLAUDE.md\` : mémoire active du projet
- \`AGENTS.md\` : symlink vers \`CLAUDE.md\`
- \`README.md\` : documentation projet
- \`.gitignore\` : exclusions Git de base
## Commandes utiles
\`\`\`bash
# Initialiser la mémoire projet
gen-claude
# Démarrer la stack Docker
docker compose up -d
\`\`\`
EOF
}
create_gitignore() {
cat <<'EOF' > "$PROJECT_PATH/.gitignore"
# dependencies
node_modules/
# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# env
.env
.env.*
!.env.example
# build outputs
dist/
build/
coverage/
.next/
out/
# editors / OS
.DS_Store
.vscode/
.idea/
# local runtime data
.tmp/
tmp/
# AI tools
.claude/
.codex/
EOF
}
choose_target_base
if [ ! -d "$TARGET_BASE" ]; then
echo "Le dossier cible n'existe pas : $TARGET_BASE"
exit 1
fi
PROJECT_PATH="$TARGET_BASE/$PROJECT_NAME"
if [ -e "$PROJECT_PATH" ]; then
echo "Le dossier existe déjà : $PROJECT_PATH"
exit 1
fi
mkdir -p "$PROJECT_PATH"
cd "$PROJECT_PATH"
git init
# mémoire agents
gen-claude "$PROJECT_NAME"
create_readme
create_gitignore
echo ""
echo "Projet créé : $PROJECT_PATH"
echo ""
echo "Prochaines étapes :"
echo " cd $PROJECT_PATH"
echo " git remote add origin <repo>"
echo " docker compose up -d"

105
scripts/sync-ai-instructions.sh Executable file
View File

@@ -0,0 +1,105 @@
#!/usr/bin/env bash
# sync-ai-instructions.sh
# Génère un unique CLAUDE.md dans le repo Lead_tech depuis _AI_INSTRUCTIONS.md + _projects.conf
# puis recrée les liens symboliques nécessaires vers ce fichier unique
# selon la machine courante (Darwin = Mac, Linux = NUC)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SOURCE="$REPO_ROOT/_AI_INSTRUCTIONS.md"
PROJECTS_CONF="$REPO_ROOT/_projects.conf"
# --- Détection machine ---
OS="$(uname -s)"
CHANGED=0
# --- Construire la table markdown des projets ---
build_projects_table() {
local os="$1"
echo "| Projet | Stack | Localisation | État |"
echo "|---|---|---|---|"
while IFS='|' read -r nom stack path_nuc path_mac etat; do
# Ignorer lignes vides et commentaires
[[ -z "$nom" || "$nom" == \#* ]] && continue
if [ "$os" = "Darwin" ]; then
path="$path_mac"
else
path="$path_nuc"
fi
if [ -z "$path" ]; then
echo "| $nom | $stack | *non disponible sur cette machine* | $etat |"
else
echo "| $nom | $stack | \`$path\` | $etat |"
fi
done < "$PROJECTS_CONF"
}
generate_repo_claude() {
local header="$1"
local dest="$2"
local projects_table
local tmp
projects_table="$(build_projects_table "$OS")"
tmp="$(mktemp)"
mkdir -p "$(dirname "$dest")"
{
echo "$header"
echo ""
# Remplacer {{PROJECTS_TABLE}} par la table générée
while IFS= read -r line; do
if [ "$line" = "{{PROJECTS_TABLE}}" ]; then
echo "$projects_table"
else
echo "$line"
fi
done < "$SOURCE"
} > "$tmp"
if [ ! -f "$dest" ] || ! cmp -s "$tmp" "$dest"; then
mv "$tmp" "$dest"
CHANGED=1
else
rm -f "$tmp"
fi
}
ensure_symlink() {
local target="$1"
local link_path="$2"
mkdir -p "$(dirname "$link_path")"
if [ -L "$link_path" ]; then
local current_target
current_target="$(readlink "$link_path")"
if [ "$current_target" = "$target" ]; then
return 0
fi
elif [ -e "$link_path" ]; then
rm -f "$link_path"
fi
rm -f "$link_path"
ln -s "$target" "$link_path"
CHANGED=1
}
CLAUDE_HEADER="# Instructions globales — Lead Tech Copilote
Ce fichier est chargé automatiquement par Claude Code ou Codex à chaque session.
Il constitue la porte d'entrée principale de la base de connaissance Lead_tech et oriente vers les fichiers spécialisés utilisés par tous les projets."
generate_repo_claude "$CLAUDE_HEADER" "$REPO_ROOT/CLAUDE.md"
ensure_symlink "$REPO_ROOT/CLAUDE.md" "$HOME/.claude/CLAUDE.md"
ensure_symlink "$HOME/.claude/CLAUDE.md" "$HOME/.codex/AGENTS.md"
ensure_symlink "$REPO_ROOT/CLAUDE.md" "$REPO_ROOT/AGENTS.md"
if [ "$CHANGED" -eq 1 ]; then
echo "Sync AI instructions (OS: $OS)"
echo "Sync terminée."
fi