mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:40:43 +00:00
88 lines
2.5 KiB
Bash
88 lines
2.5 KiB
Bash
record_fixture_plugin_trust() {
|
|
local plugin_id="$1"
|
|
local plugin_root="$2"
|
|
local enabled="$3"
|
|
node - "$plugin_id" "$plugin_root" "$enabled" <<'NODE'
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
|
|
const pluginId = process.argv[2];
|
|
const pluginRoot = process.argv[3];
|
|
const enabled = process.argv[4] === "1";
|
|
const configPath = path.join(process.env.HOME, ".openclaw", "openclaw.json");
|
|
const config = fs.existsSync(configPath)
|
|
? JSON.parse(fs.readFileSync(configPath, "utf8"))
|
|
: {};
|
|
const plugins = (config.plugins ??= {});
|
|
const entries = (plugins.entries ??= {});
|
|
entries[pluginId] = { ...(entries[pluginId] ?? {}), enabled };
|
|
delete plugins.installs;
|
|
plugins.allow = Array.from(new Set([...(plugins.allow ?? []), pluginId])).sort();
|
|
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
|
|
const ledgerPath = path.join(process.env.HOME, ".openclaw", "plugins", "installs.json");
|
|
const ledger = fs.existsSync(ledgerPath)
|
|
? JSON.parse(fs.readFileSync(ledgerPath, "utf8"))
|
|
: {
|
|
version: 1,
|
|
warning:
|
|
"DO NOT EDIT. This file is generated by OpenClaw plugin install/update/uninstall commands. Use `openclaw plugins install/update/uninstall` instead.",
|
|
records: {},
|
|
};
|
|
ledger.updatedAtMs = Date.now();
|
|
ledger.records ??= {};
|
|
ledger.records[pluginId] = {
|
|
...(ledger.records[pluginId] ?? {}),
|
|
source: "path",
|
|
installPath: pluginRoot,
|
|
sourcePath: pluginRoot,
|
|
};
|
|
fs.mkdirSync(path.dirname(ledgerPath), { recursive: true });
|
|
fs.writeFileSync(ledgerPath, `${JSON.stringify(ledger, null, 2)}\n`, "utf8");
|
|
NODE
|
|
}
|
|
|
|
write_fixture_plugin() {
|
|
local dir="$1"
|
|
local id="$2"
|
|
local version="$3"
|
|
local method="$4"
|
|
local name="$5"
|
|
|
|
mkdir -p "$dir"
|
|
cat >"$dir/package.json" <<JSON
|
|
{
|
|
"name": "@openclaw/$id",
|
|
"version": "$version",
|
|
"openclaw": { "extensions": ["./index.js"] }
|
|
}
|
|
JSON
|
|
cat >"$dir/index.js" <<JS
|
|
module.exports = {
|
|
id: "$id",
|
|
name: "$name",
|
|
register(api) {
|
|
api.registerGatewayMethod("$method", async () => ({ ok: true }));
|
|
},
|
|
};
|
|
JS
|
|
cat >"$dir/openclaw.plugin.json" <<'JSON'
|
|
{
|
|
"id": "placeholder",
|
|
"configSchema": {
|
|
"type": "object",
|
|
"properties": {}
|
|
}
|
|
}
|
|
JSON
|
|
node - "$dir/openclaw.plugin.json" "$id" <<'NODE'
|
|
const fs = require("node:fs");
|
|
const file = process.argv[2];
|
|
const id = process.argv[3];
|
|
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
parsed.id = id;
|
|
fs.writeFileSync(file, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
NODE
|
|
}
|