Files
openclaw/scripts/lib/plugin-npm-runtime-assets.mts
T
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

50 lines
1.9 KiB
TypeScript

// 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";
import { discoverStaticExtensionAssets } from "./static-extension-assets.mts";
type PluginRuntimeAssetPlan = {
packageDir: string;
packageJson: { openclaw?: { assetScripts?: { build?: unknown } } };
pluginDir: string;
};
type PluginStaticAssetPlan = Pick<PluginRuntimeAssetPlan, "pluginDir"> & {
repoRoot: string;
};
function resolvePackageAssetBuildCommand(packageJson: PluginRuntimeAssetPlan["packageJson"]) {
const command = packageJson?.openclaw?.assetScripts?.build;
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: PluginRuntimeAssetPlan) {
const command = resolvePackageAssetBuildCommand(plan.packageJson);
if (!command) {
return null;
}
console.error(`[plugin-npm-runtime-build] build assets ${plan.pluginDir}: ${command}`);
const result = spawnSync(command, {
cwd: plan.packageDir,
env: process.env,
shell: true,
stdio: "inherit",
});
if (result.status !== 0) {
throw new Error(`${plan.pluginDir} asset build failed: ${command}`);
}
return command;
}
/** List static asset source paths referenced by a package but missing from disk. */
export function listMissingPackageStaticAssetSources(plan: PluginStaticAssetPlan) {
const packagePrefix = `extensions/${plan.pluginDir}/`;
return discoverStaticExtensionAssets({ rootDir: plan.repoRoot, includeExternalPlugins: true })
.filter((asset) => asset.src.replaceAll("\\", "/").startsWith(packagePrefix))
.map((asset) => asset.src)
.filter((src) => !fs.existsSync(path.join(plan.repoRoot, src)))
.toSorted((left, right) => left.localeCompare(right));
}