2023-08-05 00:56:55 +08:00
|
|
|
import { runPlug } from "../cli/plug_run.ts";
|
2024-02-09 04:00:45 +08:00
|
|
|
import { path } from "$common/deps.ts";
|
2024-01-15 23:46:37 +08:00
|
|
|
import assets from "../dist/plug_asset_bundle.json" assert {
|
2023-08-05 00:56:55 +08:00
|
|
|
type: "json",
|
|
|
|
};
|
2024-02-09 04:00:45 +08:00
|
|
|
import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
|
2024-01-27 00:05:10 +08:00
|
|
|
import { determineDatabaseBackend } from "../server/db_backend.ts";
|
2023-08-05 00:56:55 +08:00
|
|
|
|
|
|
|
export async function plugRunCommand(
|
|
|
|
{
|
2023-08-12 02:37:13 +08:00
|
|
|
hostname,
|
|
|
|
port,
|
2023-08-05 00:56:55 +08:00
|
|
|
}: {
|
2023-08-12 02:37:13 +08:00
|
|
|
hostname?: string;
|
|
|
|
port?: number;
|
2023-08-05 00:56:55 +08:00
|
|
|
},
|
|
|
|
spacePath: string,
|
2023-08-12 02:37:13 +08:00
|
|
|
functionName: string | undefined,
|
2023-08-05 00:56:55 +08:00
|
|
|
...args: string[]
|
|
|
|
) {
|
|
|
|
spacePath = path.resolve(spacePath);
|
|
|
|
console.log("Space path", spacePath);
|
|
|
|
console.log("Function to run:", functionName, "with arguments", args);
|
2024-01-27 00:05:10 +08:00
|
|
|
|
|
|
|
const kvPrimitives = await determineDatabaseBackend(spacePath);
|
|
|
|
|
|
|
|
if (!kvPrimitives) {
|
|
|
|
console.error("Cannot run plugs in databaseless mode.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-05 00:56:55 +08:00
|
|
|
try {
|
|
|
|
const result = await runPlug(
|
|
|
|
spacePath,
|
|
|
|
functionName,
|
|
|
|
args,
|
|
|
|
new AssetBundle(assets),
|
2024-01-27 00:05:10 +08:00
|
|
|
kvPrimitives,
|
2023-08-12 02:37:13 +08:00
|
|
|
port,
|
|
|
|
hostname,
|
2023-08-05 00:56:55 +08:00
|
|
|
);
|
2023-08-15 13:55:07 +08:00
|
|
|
if (result) {
|
|
|
|
console.log("Output", result);
|
|
|
|
}
|
2024-01-27 00:05:10 +08:00
|
|
|
kvPrimitives.close();
|
2023-08-12 02:37:13 +08:00
|
|
|
Deno.exit(0);
|
2023-08-05 00:56:55 +08:00
|
|
|
} catch (e: any) {
|
|
|
|
console.error(e.message);
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
}
|