mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
docs: document script lib plugin helpers
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Builds shared repo/source-root context for pairing guard scripts.
|
||||
import path from "node:path";
|
||||
import { resolveRepoRoot, resolveSourceRoots } from "./ts-guard-utils.mjs";
|
||||
|
||||
/** Create repo root and source root helpers for pairing guard scanners. */
|
||||
export function createPairingGuardContext(importMetaUrl) {
|
||||
const repoRoot = resolveRepoRoot(importMetaUrl);
|
||||
const sourceRoots = resolveSourceRoots(repoRoot, ["src", "extensions"]);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Builds balanced Vitest shard plans for plugin contract tests.
|
||||
import { listTrackedTestFiles } from "./list-test-files.mjs";
|
||||
|
||||
function listContractTestFiles(rootDir = "src/plugins/contracts") {
|
||||
@@ -32,6 +33,7 @@ function resolveContractFileWeight(file) {
|
||||
return CONTRACT_FILE_WEIGHTS.get(name) ?? 10;
|
||||
}
|
||||
|
||||
/** Create balanced plugin contract test shards for CI check planning. */
|
||||
export function createPluginContractTestShards() {
|
||||
const suffixes = ["a", "b"];
|
||||
const groups = Object.fromEntries(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Collects plugin manifest and metric observations for gateway gauntlet reports.
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import JSON5 from "json5";
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
// Augments plugin npm package manifests with generated runtime/package metadata.
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import JSON5 from "json5";
|
||||
import { packageJsonForShrinkwrap, readShrinkwrapOverrides } from "../generate-npm-shrinkwrap.mjs";
|
||||
import { resolveNpmRunner } from "../npm-runner.mjs";
|
||||
import {
|
||||
listPluginNpmRuntimeBuildOutputs,
|
||||
resolvePluginNpmRuntimeBuildPlan,
|
||||
} from "./plugin-npm-runtime-build.mjs";
|
||||
import { resolveNpmRunner } from "../npm-runner.mjs";
|
||||
|
||||
const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA_PATH =
|
||||
"src/config/bundled-channel-config-metadata.generated.ts";
|
||||
@@ -137,6 +138,7 @@ function listConfiguredBundledDependencyNames(packageJson) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** Resolve an npm command invocation for plugin package scripts. */
|
||||
export function resolvePluginNpmCommand(args, params = {}) {
|
||||
return resolveNpmRunner({
|
||||
comSpec: params.comSpec,
|
||||
@@ -405,6 +407,7 @@ function installPackageLocalBundledDependencies(params) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Build the package.json that should be used while packaging a plugin for npm. */
|
||||
export function resolveAugmentedPluginNpmPackageJson(params) {
|
||||
const repoRoot = path.resolve(params.repoRoot ?? ".");
|
||||
const packageDir = resolvePackageDir(repoRoot, params.packageDir);
|
||||
@@ -462,6 +465,7 @@ export function resolveAugmentedPluginNpmPackageJson(params) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Read generated bundled channel config metadata keyed by plugin id. */
|
||||
export function readGeneratedBundledChannelConfigs(repoRoot) {
|
||||
const metadataPath = path.join(repoRoot, GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA_PATH);
|
||||
if (!fs.existsSync(metadataPath)) {
|
||||
@@ -528,6 +532,7 @@ function readGeneratedBundledChannelConfigEntries(source) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Merge generated channel config schemas into a plugin manifest without clobbering labels. */
|
||||
export function mergeGeneratedChannelConfigs(manifest, generatedChannelConfigs) {
|
||||
if (!generatedChannelConfigs || Object.keys(generatedChannelConfigs).length === 0) {
|
||||
return manifest;
|
||||
@@ -561,6 +566,7 @@ export function mergeGeneratedChannelConfigs(manifest, generatedChannelConfigs)
|
||||
};
|
||||
}
|
||||
|
||||
/** Build the plugin manifest that should be used while packaging a plugin for npm. */
|
||||
export function resolveAugmentedPluginNpmManifest(params) {
|
||||
const repoRoot = path.resolve(params.repoRoot ?? ".");
|
||||
const packageDir = resolvePackageDir(repoRoot, params.packageDir);
|
||||
@@ -590,6 +596,7 @@ export function resolveAugmentedPluginNpmManifest(params) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Temporarily write augmented manifest/package metadata while a packaging callback runs. */
|
||||
export function withAugmentedPluginNpmManifestForPackage(params, callback) {
|
||||
const repoRoot = path.resolve(params.repoRoot ?? ".");
|
||||
const packageDir = resolvePackageDir(repoRoot, params.packageDir);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Builds and validates static assets needed by package-local plugin runtime output.
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
@@ -8,6 +9,7 @@ function resolvePackageAssetBuildCommand(packageJson) {
|
||||
return typeof command === "string" && command.trim() ? command.trim() : null;
|
||||
}
|
||||
|
||||
/** Run a package-local static asset build command when the plugin declares one. */
|
||||
export function runPackageAssetBuild(plan) {
|
||||
const command = resolvePackageAssetBuildCommand(plan.packageJson);
|
||||
if (!command) {
|
||||
@@ -26,6 +28,7 @@ export function runPackageAssetBuild(plan) {
|
||||
return command;
|
||||
}
|
||||
|
||||
/** List static asset source paths referenced by a package but missing from disk. */
|
||||
export function listMissingPackageStaticAssetSources(plan) {
|
||||
const packagePrefix = `extensions/${plan.pluginDir}/`;
|
||||
return discoverStaticExtensionAssets({ rootDir: plan.repoRoot })
|
||||
|
||||
Reference in New Issue
Block a user