-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·81 lines (71 loc) · 3.36 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·81 lines (71 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
#
# setup.sh — prepare a fresh checkout of this tutorial for development.
#
# 1. installs npm dependencies (if missing)
# 2. fetches the @parity/product-sdk skills into .claude/skills/ so AI
# coding assistants (Claude Code, Cursor, Windsurf, Copilot, Gemini)
# have Polkadot Product SDK guidance on hand while you build.
#
# This is the Polkadot Games Tutorial, so .claude/skills/ ALSO contains the
# tutorial's own hand-written guides — `00-overview.md` and `level-N-*.md`.
# Those are flat .md FILES, committed to the repo. The fetched @parity/product-sdk
# skills are DIRECTORIES and are NOT committed (gitignored, fetched fresh so they
# never go stale). This script only ever creates/replaces the fetched
# subdirectories; it never touches the committed level files. Safe to re-run.
# Pass --refresh to re-pull the skills even if they're already present.
#
# ./setup.sh # install deps + fetch skills if missing
# ./setup.sh --refresh # also re-pull the latest skills
#
# Overridable via env: PRODUCT_SDK_REPO, PRODUCT_SDK_REF (default: main).
set -euo pipefail
cd "$(dirname "$0")"
SKILLS_REPO="${PRODUCT_SDK_REPO:-https://github.com/paritytech/product-sdk.git}"
SKILLS_REF="${PRODUCT_SDK_REF:-main}"
SKILLS_SUBDIR="product-sdk/skills"
SKILLS_DEST=".claude/skills"
# --- 1. dependencies ---------------------------------------------------------
if [ ! -d node_modules ]; then
if ! command -v npm >/dev/null 2>&1; then
echo " npm not found — install Node.js (>= 20) and re-run." >&2
exit 1
fi
echo "==> Installing npm dependencies..."
npm install --no-audit --no-fund
else
echo "==> node_modules present; skipping npm install (delete it to reinstall)."
fi
# --- 2. @parity/product-sdk skills ------------------------------------------
# "Already populated" = at least one fetched skill DIRECTORY is present. The
# committed level *files* don't count, so a fresh clone still fetches.
if [ -n "$(find "$SKILLS_DEST" -mindepth 1 -maxdepth 1 -type d 2>/dev/null || true)" ] \
&& [ "${1:-}" != "--refresh" ]; then
echo "==> product-sdk skills already present in ${SKILLS_DEST}/; pass --refresh to re-pull."
exit 0
fi
if ! command -v git >/dev/null 2>&1; then
echo " git not found — skipping skills fetch (the tutorial's own level skills are still here)." >&2
exit 0
fi
echo "==> Fetching @parity/product-sdk skills into ${SKILLS_DEST}/ ..."
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
if ! git clone --quiet --depth 1 --branch "$SKILLS_REF" \
--filter=blob:none --sparse "$SKILLS_REPO" "$tmp" 2>/dev/null; then
echo " Could not clone ${SKILLS_REPO}@${SKILLS_REF} (offline?) — skipping." >&2
exit 0
fi
git -C "$tmp" sparse-checkout set "$SKILLS_SUBDIR" >/dev/null 2>&1
if [ ! -d "$tmp/$SKILLS_SUBDIR" ]; then
echo " No ${SKILLS_SUBDIR} found in the repo — skipping." >&2
exit 0
fi
mkdir -p "$SKILLS_DEST"
# Replace ONLY the fetched skill subdirectories; leave the committed
# tutorial level files (00-overview.md, level-N-*.md) untouched.
find "$SKILLS_DEST" -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} +
cp -R "$tmp/$SKILLS_SUBDIR/." "$SKILLS_DEST/"
echo "==> Done. Fetched product-sdk skills now in ${SKILLS_DEST}/:"
find "$SKILLS_DEST" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort | sed 's/^/ - /'
echo " (plus the tutorial's committed level guides: 00-overview.md, level-1..4-*.md)"