mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 19:28:09 +00:00
96 lines
3.0 KiB
JavaScript
96 lines
3.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Verifies publishable plugin packages can build their npm runtime outputs.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import {
|
|
buildPluginNpmRuntime,
|
|
listPluginNpmRuntimeBuildOutputs,
|
|
listPublishablePluginPackageDirs,
|
|
resolvePluginNpmRuntimeBuildPlan,
|
|
} from "./lib/plugin-npm-runtime-build.mjs";
|
|
|
|
function readPackageArgValue(argv, index) {
|
|
const value = argv[index + 1];
|
|
if (value === undefined || value === "" || value.startsWith("--")) {
|
|
throw new Error("missing value for --package");
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export function parseArgs(argv) {
|
|
const packageDirs = [];
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
const arg = argv[index];
|
|
if (arg === "--package") {
|
|
packageDirs.push(readPackageArgValue(argv, index));
|
|
index += 1;
|
|
continue;
|
|
}
|
|
throw new Error(
|
|
"usage: node scripts/check-plugin-npm-runtime-builds.mjs [--package extensions/<id> ...]",
|
|
);
|
|
}
|
|
return { packageDirs };
|
|
}
|
|
|
|
/**
|
|
* Builds publishable plugin npm runtimes and verifies declared outputs exist.
|
|
*/
|
|
export async function checkPluginNpmRuntimeBuilds(params = {}) {
|
|
const repoRoot = path.resolve(params.repoRoot ?? ".");
|
|
const packageDirs =
|
|
params.packageDirs?.length > 0
|
|
? params.packageDirs
|
|
: listPublishablePluginPackageDirs({ repoRoot });
|
|
const rows = [];
|
|
for (const packageDir of packageDirs) {
|
|
const plan = resolvePluginNpmRuntimeBuildPlan({ repoRoot, packageDir });
|
|
if (!plan) {
|
|
throw new Error(`${packageDir} did not produce a package-local runtime build plan`);
|
|
}
|
|
const result = await buildPluginNpmRuntime({
|
|
repoRoot,
|
|
packageDir,
|
|
logLevel: params.logLevel ?? "warn",
|
|
});
|
|
const missing = listPluginNpmRuntimeBuildOutputs(result).filter(
|
|
(runtimePath) =>
|
|
!fs.existsSync(path.join(result.packageDir, runtimePath.replace(/^\.\//u, ""))),
|
|
);
|
|
if (missing.length > 0) {
|
|
throw new Error(`${packageDir} missing built runtime outputs: ${missing.join(", ")}`);
|
|
}
|
|
rows.push({
|
|
pluginDir: result.pluginDir,
|
|
status: "built",
|
|
entryCount: Object.keys(result.entry).length,
|
|
copiedStaticAssets: result.copiedStaticAssets,
|
|
});
|
|
}
|
|
return rows;
|
|
}
|
|
|
|
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
|
|
try {
|
|
const args = parseArgs(process.argv.slice(2));
|
|
const rows = await checkPluginNpmRuntimeBuilds(args);
|
|
const builtCount = rows.filter((row) => row.status === "built").length;
|
|
console.log(`checked ${rows.length} publishable plugins; built ${builtCount} npm runtimes`);
|
|
for (const row of rows) {
|
|
console.log(
|
|
[
|
|
row.pluginDir,
|
|
row.status,
|
|
row.entryCount,
|
|
row.copiedStaticAssets.length > 0 ? row.copiedStaticAssets.join(",") : "-",
|
|
].join("\t"),
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.error(error instanceof Error ? error.message : String(error));
|
|
process.exitCode = 1;
|
|
}
|
|
}
|