1
0
silverbullet/cmd/plug_run.ts

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-08-04 16:56:55 +00: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";
2023-08-30 15:25:54 +00:00
import { silverBulletDbFile } from "./constants.ts";
2023-08-04 16:56:55 +00:00
export async function plugRunCommand(
{
2023-08-30 15:25:54 +00:00
db,
2023-08-11 18:37:13 +00:00
hostname,
port,
2023-08-04 16:56:55 +00:00
}: {
2023-08-30 15:25:54 +00:00
db?: string;
2023-08-11 18:37:13 +00:00
hostname?: string;
port?: number;
2023-08-04 16:56:55 +00:00
},
spacePath: string,
2023-08-11 18:37:13 +00:00
functionName: string | undefined,
2023-08-04 16:56:55 +00:00
...args: string[]
) {
spacePath = path.resolve(spacePath);
console.log("Space path", spacePath);
2023-08-30 15:25:54 +00:00
let dbPath = path.resolve(spacePath, silverBulletDbFile);
if (db) {
dbPath = path.resolve(db);
}
2023-08-04 16:56:55 +00:00
console.log("Function to run:", functionName, "with arguments", args);
try {
const result = await runPlug(
spacePath,
2023-08-30 15:25:54 +00:00
dbPath,
2023-08-04 16:56:55 +00:00
functionName,
args,
new AssetBundle(assets),
2023-08-11 18:37:13 +00:00
port,
hostname,
2023-08-04 16:56:55 +00:00
);
2023-08-15 05:55:07 +00:00
if (result) {
console.log("Output", result);
}
2023-08-11 18:37:13 +00:00
Deno.exit(0);
2023-08-04 16:56:55 +00:00
} catch (e: any) {
console.error(e.message);
Deno.exit(1);
}
}