From b23efea14e319a67a7cc75f14df5f41a3b65119c Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Fri, 8 May 2026 21:09:42 +0200 Subject: [PATCH] feat: Develop core scaffolding engine and Git configuration templates --- lib/scaffold.sh | 67 +++++++++++++++++++++++++++++++++++++++++ templates/gitattributes | 17 +++++++++++ templates/gitignore | 20 ++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 lib/scaffold.sh create mode 100644 templates/gitattributes create mode 100644 templates/gitignore diff --git a/lib/scaffold.sh b/lib/scaffold.sh new file mode 100644 index 0000000..0bea0bd --- /dev/null +++ b/lib/scaffold.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# ============================================================================= +# lib/scaffold.sh +# Directory structure creation and template rendering engine. +# ============================================================================= + +render_template() { + local template_file="$1" + local output_file="$2" + + [[ ! -f "$template_file" ]] && { error "Template not found: ${template_file}"; exit 1; } + + local content + content=$(cat "$template_file") + + # Placeholder replacement + content="${content//\{\{GENOME_NAME\}\}/${GENOME_NAME}}" + content="${content//\{\{GENOME_NAME_UPPER\}\}/${GENOME_NAME^^}}" + content="${content//\{\{GENOME_DESC\}\}/${GENOME_DESC}}" + content="${content//\{\{FORGEJO_URL\}\}/${FORGEJO_URL}}" + content="${content//\{\{FORGEJO_USER\}\}/${FORGEJO_USER}}" + content="${content//\{\{VAULTWARDEN_URL\}\}/${VAULTWARDEN_URL}}" + content="${content//\{\{MASTER_REPO\}\}/${MASTER_REPO}}" + content="${content//\{\{DATE\}\}/$(date +%Y-%m-%d)}" + + mkdir -p "$(dirname "$output_file")" + printf '%s\n' "$content" > "$output_file" +} + +scaffold_genome() { + local base="$1" + local dirs=( + "raw/articles" "raw/transcripts" "raw/code-packs" "raw/assets" "raw/private" + "wiki/sources" "wiki/entities" "wiki/concepts" "wiki/queries" "wiki/private" + ) + + info "Building directory structure in ${base}..." + for dir in "${dirs[@]}"; do + mkdir -p "${base}/${dir}" + touch "${base}/${dir}/.gitkeep" + done + + # Core templates + render_template "${TEMPLATES_DIR}/gitattributes" "${base}/.gitattributes" + render_template "${TEMPLATES_DIR}/gitignore" "${base}/.gitignore" + render_template "${TEMPLATES_DIR}/agents-genome.md" "${base}/AGENTS.md" + render_template "${TEMPLATES_DIR}/wiki-index.md" "${base}/wiki/index.md" + render_template "${TEMPLATES_DIR}/wiki-log.md" "${base}/wiki/log.md" + + success "Scaffold completed for genome: ${GENOME_NAME}" +} + +install_precommit_hook() { + local repo_path="$1" + local hook_path="${repo_path}/.git/hooks/pre-commit" + + cp "${TEMPLATES_DIR}/pre-commit.sh" "$hook_path" + chmod +x "$hook_path" + success "Pre-commit security hook installed at: $hook_path" +} + +scaffold_master() { + local base="$1" + render_template "${TEMPLATES_DIR}/agents-master.md" "${base}/AGENTS.md" + render_template "${TEMPLATES_DIR}/readme-master.md" "${base}/README.md" + success "Master repository scaffold completed." +} diff --git a/templates/gitattributes b/templates/gitattributes new file mode 100644 index 0000000..226c36e --- /dev/null +++ b/templates/gitattributes @@ -0,0 +1,17 @@ +# --- Encryption Rules for Genomes --- +# These directories are stored as encrypted AES-256 blobs on the remote server. +# They require git-crypt and the specific genome key to be readable. + +raw/private/** filter=git-crypt diff=git-crypt +wiki/private/** filter=git-crypt diff=git-crypt + +# --- Binary Integrity --- +# Prevent line-ending conversion for encrypted files to avoid corruption. +raw/private/** -text +wiki/private/** -text + +# --- Standard Text Configuration --- +*.md text eol=lf +*.sh text eol=lf +*.env text eol=lf +Makefile text eol=lf diff --git a/templates/gitignore b/templates/gitignore new file mode 100644 index 0000000..6605615 --- /dev/null +++ b/templates/gitignore @@ -0,0 +1,20 @@ +# --- Security Keys --- +# NEVER commit .key files to the repository +*.key +.resource_key + +# --- Operating System Files --- +.DS_Store +Thumbs.db +.directory +*.swp + +# --- Obsidian & Editor Configs --- +.obsidian/ +.vscode/ +.idea/ + +# --- Temporary Files & Local Logs --- +*.log +.tmp/ +node_modules/