-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·108 lines (89 loc) · 2.86 KB
/
build.sh
File metadata and controls
executable file
·108 lines (89 loc) · 2.86 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
# build.sh — Builds each claw source directory in src/ into a spec-compliant
# .claw archive in dist/.
#
# Usage: ./build.sh [src-dir]
# Defaults to ./src if no argument is given.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
SRC_DIR="${1:-$REPO_ROOT/src}"
DIST_DIR="$REPO_ROOT/dist"
mkdir -p "$DIST_DIR"
read_manifest_array() {
local manifest_path="$1"
local selector="$2"
node --input-type=module - "$manifest_path" "$selector" <<'EOF'
import fs from 'node:fs';
const manifestPath = process.argv[2];
const selector = process.argv[3];
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
let value = manifest;
for (const segment of selector.split('.')) {
value = value?.[segment];
}
if (Array.isArray(value)) {
for (const entry of value) {
if (typeof entry === 'string' && entry.trim()) {
console.log(entry.trim());
}
}
}
EOF
}
stage_claw_dir() {
local source_dir="$1"
local stage_dir="$2"
local manifest_path="$stage_dir/manifest.json"
local workspace_skills_dir="$stage_dir/workspace/skills"
local archive_skills_dir="$stage_dir/skills"
local archive_plugins_dir="$stage_dir/plugins"
local bundled_skill=""
local bundled_plugin=""
mkdir -p "$stage_dir"
cp -R "$source_dir"/. "$stage_dir"/
if [[ ! -f "$manifest_path" ]]; then
echo "Missing manifest.json in $source_dir" >&2
return 1
fi
while IFS= read -r bundled_skill; do
[[ -n "$bundled_skill" ]] || continue
if [[ ! -d "$workspace_skills_dir/$bundled_skill" ]]; then
echo "Bundled skill \"$bundled_skill\" is listed in $manifest_path but missing from workspace/skills/" >&2
return 1
fi
mkdir -p "$archive_skills_dir"
mv "$workspace_skills_dir/$bundled_skill" "$archive_skills_dir/$bundled_skill"
done < <(read_manifest_array "$manifest_path" "skills.bundled")
if [[ -d "$workspace_skills_dir" ]] && [[ -z "$(find "$workspace_skills_dir" -mindepth 1 -print -quit)" ]]; then
rmdir "$workspace_skills_dir"
fi
while IFS= read -r bundled_plugin; do
[[ -n "$bundled_plugin" ]] || continue
if [[ ! -d "$archive_plugins_dir/$bundled_plugin" ]]; then
echo "Bundled plugin \"$bundled_plugin\" is listed in $manifest_path but missing from plugins/" >&2
return 1
fi
done < <(read_manifest_array "$manifest_path" "plugins.bundled")
}
found=0
for dir in "$SRC_DIR"/*/; do
[[ -d "$dir" ]] || continue
name="$(basename "$dir")"
outfile="$DIST_DIR/${name}.claw"
temp_dir="$(mktemp -d "${TMPDIR:-/tmp}/claw-build.XXXXXX")"
stage_dir="$temp_dir/$name"
echo "Packing $name -> $outfile"
stage_claw_dir "$dir" "$stage_dir"
rm -f "$outfile"
(
cd "$stage_dir"
zip -qr "$outfile" .
)
rm -rf "$temp_dir"
found=$((found + 1))
done
if [[ "$found" -eq 0 ]]; then
echo "No directories found in $SRC_DIR" >&2
exit 1
fi
echo "Built $found .claw file(s) in $DIST_DIR"