Add auto-sync watcher + single-file builder for Gitea Pages
This commit is contained in:
parent
7793491202
commit
15bd8e181d
43
scripts/auto-sync.sh
Executable file
43
scripts/auto-sync.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Авто-синхронизация локальных изменений в Gitea.
|
||||||
|
# Каждые 5 сек проверяет git status. Если есть изменения:
|
||||||
|
# 1) если изменился executive-os/* → пересобирает index.html (single-file)
|
||||||
|
# 2) git add -A && git commit && git push origin main
|
||||||
|
# Креды берутся из ~/.netrc.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
ROOT="$(pwd)"
|
||||||
|
INTERVAL="${INTERVAL:-5}"
|
||||||
|
BRANCH="${BRANCH:-main}"
|
||||||
|
|
||||||
|
log() { printf "[auto-sync %s] %s\n" "$(date '+%H:%M:%S')" "$*"; }
|
||||||
|
|
||||||
|
trap 'log "stopped"; exit 0' INT TERM
|
||||||
|
log "watching $ROOT (every ${INTERVAL}s, branch=$BRANCH)"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
changes="$(git status --porcelain 2>/dev/null || true)"
|
||||||
|
if [ -n "$changes" ]; then
|
||||||
|
log "changes detected"
|
||||||
|
# если затронут executive-os/ — пересобираем single-file index.html
|
||||||
|
if echo "$changes" | grep -qE "executive-os/"; then
|
||||||
|
log "rebuilding single-file index.html"
|
||||||
|
bash "$ROOT/scripts/build-single-file.sh" || log "build failed"
|
||||||
|
fi
|
||||||
|
git add -A
|
||||||
|
if git diff --cached --quiet; then
|
||||||
|
log "nothing actually staged after add, skipping"
|
||||||
|
else
|
||||||
|
msg="auto-sync $(date '+%Y-%m-%d %H:%M:%S')"
|
||||||
|
git commit -m "$msg" >/dev/null 2>&1 || { log "commit failed"; sleep "$INTERVAL"; continue; }
|
||||||
|
log "committed: $msg"
|
||||||
|
if git push origin "$BRANCH" >/dev/null 2>&1; then
|
||||||
|
log "pushed → origin/$BRANCH"
|
||||||
|
else
|
||||||
|
log "push failed (will retry next tick)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep "$INTERVAL"
|
||||||
|
done
|
||||||
32
scripts/build-single-file.sh
Executable file
32
scripts/build-single-file.sh
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Собирает single-file index.html из executive-os/ для Gitea Pages.
|
||||||
|
# Inline CSS + JS + SVG-иконка → один HTML с правильным MIME для Pages.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
ROOT="$(pwd)"
|
||||||
|
SRC="$ROOT/executive-os"
|
||||||
|
OUT="$ROOT/index.html"
|
||||||
|
|
||||||
|
[ -f "$SRC/index.html" ] || { echo "ERR: $SRC/index.html not found"; exit 1; }
|
||||||
|
|
||||||
|
/usr/bin/python3 <<PY
|
||||||
|
import base64
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
src = Path("$SRC")
|
||||||
|
html = (src / "index.html").read_text()
|
||||||
|
css = (src / "styles.css").read_text()
|
||||||
|
data = (src / "data.js").read_text()
|
||||||
|
app = (src / "app.js").read_text()
|
||||||
|
icon = (src / "icon.svg").read_text()
|
||||||
|
icon_uri = "data:image/svg+xml;base64," + base64.b64encode(icon.encode()).decode()
|
||||||
|
|
||||||
|
html = html.replace('<link rel="stylesheet" href="styles.css" />', f'<style>\n{css}\n</style>')
|
||||||
|
html = html.replace('<script src="data.js"></script>', f'<script>\n{data}\n</script>')
|
||||||
|
html = html.replace('<script src="app.js"></script>', f'<script>\n{app}\n</script>')
|
||||||
|
html = html.replace('href="icon.svg"', f'href="{icon_uri}"')
|
||||||
|
|
||||||
|
Path("$OUT").write_text(html)
|
||||||
|
print(f"built single-file index.html: {len(html):,} bytes")
|
||||||
|
PY
|
||||||
Reference in New Issue
Block a user