silverbullet/cmd/plug_run.ts

42 lines
922 B
TypeScript
Raw Normal View History

2023-08-05 00:56:55 +08:00
import { runPlug } from "../cli/plug_run.ts";
import { path } from "../common/deps.ts";
import assets from "../dist/plug_asset_bundle.json" assert {
type: "json",
};
import { AssetBundle } from "../plugos/asset_bundle/bundle.ts";
export async function plugRunCommand(
{
noIndex,
2023-08-12 02:37:13 +08:00
hostname,
port,
2023-08-05 00:56:55 +08:00
}: {
noIndex: boolean;
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);
try {
const result = await runPlug(
spacePath,
functionName,
args,
new AssetBundle(assets),
!noIndex,
2023-08-12 02:37:13 +08:00
port,
hostname,
2023-08-05 00:56:55 +08:00
);
console.log("Output", result);
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);
}
}