knowledge-genome-orchestrator/lib/scaffold.sh

67 lines
2.3 KiB
Bash

#!/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}"; return 1; }
local content
content=$(<"$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."
}