mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:20:44 +00:00
refactor: compact generated protocol metadata
This commit is contained in:
@@ -102,19 +102,7 @@ export function readGeneratedBundledChannelConfigs(repoRoot) {
|
||||
return new Map();
|
||||
}
|
||||
const source = fs.readFileSync(metadataPath, "utf8");
|
||||
const match = source.match(
|
||||
/export const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA = ([\s\S]*?) as const;/u,
|
||||
);
|
||||
if (!match?.[1]) {
|
||||
return new Map();
|
||||
}
|
||||
|
||||
let entries;
|
||||
try {
|
||||
entries = JSON5.parse(match[1]);
|
||||
} catch {
|
||||
return new Map();
|
||||
}
|
||||
const entries = readGeneratedBundledChannelConfigEntries(source);
|
||||
if (!Array.isArray(entries)) {
|
||||
return new Map();
|
||||
}
|
||||
@@ -145,6 +133,35 @@ export function readGeneratedBundledChannelConfigs(repoRoot) {
|
||||
return byPlugin;
|
||||
}
|
||||
|
||||
function readGeneratedBundledChannelConfigEntries(source) {
|
||||
const legacyMatch = source.match(
|
||||
/export const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA = ([\s\S]*?) as const;/u,
|
||||
);
|
||||
if (legacyMatch?.[1]) {
|
||||
try {
|
||||
return JSON5.parse(legacyMatch[1]);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const compactMatch = source.match(
|
||||
/const RAW_BUNDLED_CHANNEL_CONFIG_METADATA = \[([\s\S]*?)\]\.join\(""\);/u,
|
||||
);
|
||||
if (!compactMatch?.[1]) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const chunks = JSON5.parse(`[${compactMatch[1]}]`);
|
||||
if (!Array.isArray(chunks) || chunks.some((chunk) => typeof chunk !== "string")) {
|
||||
return undefined;
|
||||
}
|
||||
return JSON.parse(chunks.join(""));
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeGeneratedChannelConfigs(manifest, generatedChannelConfigs) {
|
||||
if (!generatedChannelConfigs || Object.keys(generatedChannelConfigs).length === 0) {
|
||||
return manifest;
|
||||
|
||||
Reference in New Issue
Block a user