update config setup
This commit is contained in:
+33
-5
@@ -45,11 +45,39 @@ bun -e '
|
||||
' "$install/package/dist/index.js"
|
||||
|
||||
tag=$(jq -r '.tag_name' "$install/release.json")
|
||||
if ! mv -f "$install/package/dist/index.js" "$config/plugins/stanp-opencode.js"; then
|
||||
config_file="$config/opencode.json"
|
||||
config_source="$config_file"
|
||||
if [[ ! -e "$config_source" ]]; then
|
||||
config_source="$install/empty-config.json"
|
||||
printf '{}\n' > "$config_source"
|
||||
fi
|
||||
jq -e '
|
||||
if type != "object" then error("opencode.json must contain an object") else . end
|
||||
| if (.plugins // []) | type != "array" then error("opencode.json plugins must be an array") else . end
|
||||
| .["$schema"] = (.["$schema"] // "https://opencode.ai/config.json")
|
||||
| .plugins = (.plugins // [])
|
||||
| if any(.plugins[]?; .package == "./plugins/stanp-opencode") then . else
|
||||
.plugins += [{
|
||||
package: "./plugins/stanp-opencode",
|
||||
options: { mode: "gpt", provider: "openai", lunaPriority: true }
|
||||
}]
|
||||
end
|
||||
' "$config_source" > "$install/opencode.json"
|
||||
target="$config/plugins/stanp-opencode"
|
||||
staged="$config/plugins/.stanp-opencode.new.$$"
|
||||
backup="$config/plugins/.stanp-opencode.old.$$"
|
||||
mkdir "$staged"
|
||||
mv "$install/package/dist/index.js" "$staged/index.js"
|
||||
cat > "$staged/package.json" <<'EOF'
|
||||
{"name":"stanp-opencode","type":"module","main":"./index.js","exports":"./index.js"}
|
||||
EOF
|
||||
if [[ -e "$target" || -L "$target" ]]; then mv "$target" "$backup"; fi
|
||||
if ! mv "$staged" "$target"; then
|
||||
if [[ -e "$backup" || -L "$backup" ]]; then mv "$backup" "$target"; fi
|
||||
printf 'Could not activate plugin; installation unchanged\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -L "$config/plugins/stanp-opencode" ]]; then
|
||||
rm -f "$config/plugins/stanp-opencode"
|
||||
fi
|
||||
printf 'Installed stanp-opencode %s into %s/plugins/stanp-opencode.js\nRestart opencode2 to load it.\n' "$tag" "$config"
|
||||
rm -rf "$backup"
|
||||
rm -f "$config/plugins/stanp-opencode.js"
|
||||
mv "$install/opencode.json" "$config_file"
|
||||
printf 'Installed stanp-opencode %s into %s/plugins/stanp-opencode and updated %s\nRestart opencode2 to load it.\n' "$tag" "$config" "$config_file"
|
||||
|
||||
Reference in New Issue
Block a user