Further clean
parent
60d3199d64
commit
8d5ff601dd
|
@ -1,69 +0,0 @@
|
||||||
import { DiskSpacePrimitives } from "$common/spaces/disk_space_primitives.ts";
|
|
||||||
import { AssetBundle } from "../lib/asset_bundle/bundle.ts";
|
|
||||||
|
|
||||||
import { ServerSystem } from "../server/server_system.ts";
|
|
||||||
import { AssetBundlePlugSpacePrimitives } from "$common/spaces/asset_bundle_space_primitives.ts";
|
|
||||||
import { EndpointHook } from "../server/hooks/endpoint.ts";
|
|
||||||
import { LocalShell } from "../server/shell_backend.ts";
|
|
||||||
import { Hono } from "../server/deps.ts";
|
|
||||||
import { KvPrimitives } from "$lib/data/kv_primitives.ts";
|
|
||||||
import { DataStore } from "$lib/data/datastore.ts";
|
|
||||||
import { DataStoreMQ } from "$lib/data/mq.datastore.ts";
|
|
||||||
import { EventHook } from "$lib/plugos/hooks/event.ts";
|
|
||||||
import { sleep } from "$lib/async.ts";
|
|
||||||
|
|
||||||
export async function runPlug(
|
|
||||||
spacePath: string,
|
|
||||||
functionName: string | undefined,
|
|
||||||
args: string[] = [],
|
|
||||||
builtinAssetBundle: AssetBundle,
|
|
||||||
kvPrimitives: KvPrimitives,
|
|
||||||
httpServerPort?: number,
|
|
||||||
httpHostname?: string,
|
|
||||||
) {
|
|
||||||
const serverController = new AbortController();
|
|
||||||
const app = new Hono();
|
|
||||||
|
|
||||||
const endpointHook = new EndpointHook("/_/");
|
|
||||||
|
|
||||||
const ds = new DataStore(kvPrimitives);
|
|
||||||
const mq = new DataStoreMQ(ds);
|
|
||||||
const eventHook = new EventHook();
|
|
||||||
|
|
||||||
const serverSystem = new ServerSystem(
|
|
||||||
new AssetBundlePlugSpacePrimitives(
|
|
||||||
new DiskSpacePrimitives(spacePath),
|
|
||||||
builtinAssetBundle,
|
|
||||||
),
|
|
||||||
kvPrimitives,
|
|
||||||
new LocalShell(spacePath),
|
|
||||||
mq,
|
|
||||||
ds,
|
|
||||||
eventHook,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
await serverSystem.init(true);
|
|
||||||
app.use((context, next) => {
|
|
||||||
return endpointHook.handleRequest(serverSystem.system!, context, next);
|
|
||||||
});
|
|
||||||
if (httpHostname && httpServerPort) {
|
|
||||||
Deno.serve({
|
|
||||||
hostname: httpHostname,
|
|
||||||
port: httpServerPort,
|
|
||||||
signal: serverController.signal,
|
|
||||||
}, app.fetch);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (functionName) {
|
|
||||||
const result = await serverSystem.system.invokeFunction(functionName, args);
|
|
||||||
await serverSystem.close();
|
|
||||||
serverController.abort();
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
console.log("Running in server mode, use Ctrl-c to stop");
|
|
||||||
while (true) {
|
|
||||||
await sleep(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
|
import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
|
||||||
import { compileManifest } from "$lib/plugos/compile.ts";
|
import { compileManifest } from "$lib/plugos/compile.ts";
|
||||||
import { esbuild } from "$lib/plugos/deps.ts";
|
import { esbuild } from "$lib/plugos/deps.ts";
|
||||||
import { runPlug } from "./plug_run.ts";
|
|
||||||
import assets from "../dist/plug_asset_bundle.json" assert { type: "json" };
|
import assets from "../dist/plug_asset_bundle.json" assert { type: "json" };
|
||||||
import { assertEquals } from "$lib/test_deps.ts";
|
import { assertEquals } from "$lib/test_deps.ts";
|
||||||
import { path } from "$common/deps.ts";
|
import { path } from "$common/deps.ts";
|
||||||
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
|
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
|
||||||
|
import { runPlug } from "./plug_run.ts";
|
||||||
|
|
||||||
Deno.test("Test plug run", {
|
Deno.test("Test plug run", {
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
|
@ -1,10 +1,21 @@
|
||||||
import { runPlug } from "../cli/plug_run.ts";
|
|
||||||
import { path } from "$common/deps.ts";
|
import { path } from "$common/deps.ts";
|
||||||
import assets from "../dist/plug_asset_bundle.json" assert {
|
import assets from "../dist/plug_asset_bundle.json" assert {
|
||||||
type: "json",
|
type: "json",
|
||||||
};
|
};
|
||||||
import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
|
|
||||||
import { determineDatabaseBackend } from "../server/db_backend.ts";
|
import { determineDatabaseBackend } from "../server/db_backend.ts";
|
||||||
|
import { KvPrimitives } from "$lib/data/kv_primitives.ts";
|
||||||
|
import { DiskSpacePrimitives } from "$common/spaces/disk_space_primitives.ts";
|
||||||
|
|
||||||
|
import { ServerSystem } from "../server/server_system.ts";
|
||||||
|
import { AssetBundlePlugSpacePrimitives } from "$common/spaces/asset_bundle_space_primitives.ts";
|
||||||
|
import { EndpointHook } from "../server/hooks/endpoint.ts";
|
||||||
|
import { LocalShell } from "../server/shell_backend.ts";
|
||||||
|
import { Hono } from "../server/deps.ts";
|
||||||
|
import { DataStore } from "$lib/data/datastore.ts";
|
||||||
|
import { DataStoreMQ } from "$lib/data/mq.datastore.ts";
|
||||||
|
import { EventHook } from "$lib/plugos/hooks/event.ts";
|
||||||
|
import { sleep } from "$lib/async.ts";
|
||||||
|
import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
|
||||||
|
|
||||||
export async function plugRunCommand(
|
export async function plugRunCommand(
|
||||||
{
|
{
|
||||||
|
@ -49,3 +60,59 @@ export async function plugRunCommand(
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function runPlug(
|
||||||
|
spacePath: string,
|
||||||
|
functionName: string | undefined,
|
||||||
|
args: string[] = [],
|
||||||
|
builtinAssetBundle: AssetBundle,
|
||||||
|
kvPrimitives: KvPrimitives,
|
||||||
|
httpServerPort?: number,
|
||||||
|
httpHostname?: string,
|
||||||
|
) {
|
||||||
|
const serverController = new AbortController();
|
||||||
|
const app = new Hono();
|
||||||
|
|
||||||
|
const endpointHook = new EndpointHook("/_/");
|
||||||
|
|
||||||
|
const ds = new DataStore(kvPrimitives);
|
||||||
|
const mq = new DataStoreMQ(ds);
|
||||||
|
const eventHook = new EventHook();
|
||||||
|
|
||||||
|
const serverSystem = new ServerSystem(
|
||||||
|
new AssetBundlePlugSpacePrimitives(
|
||||||
|
new DiskSpacePrimitives(spacePath),
|
||||||
|
builtinAssetBundle,
|
||||||
|
),
|
||||||
|
kvPrimitives,
|
||||||
|
new LocalShell(spacePath),
|
||||||
|
mq,
|
||||||
|
ds,
|
||||||
|
eventHook,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
await serverSystem.init(true);
|
||||||
|
app.use((context, next) => {
|
||||||
|
return endpointHook.handleRequest(serverSystem.system!, context, next);
|
||||||
|
});
|
||||||
|
if (httpHostname && httpServerPort) {
|
||||||
|
Deno.serve({
|
||||||
|
hostname: httpHostname,
|
||||||
|
port: httpServerPort,
|
||||||
|
signal: serverController.signal,
|
||||||
|
}, app.fetch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (functionName) {
|
||||||
|
const result = await serverSystem.system.invokeFunction(functionName, args);
|
||||||
|
await serverSystem.close();
|
||||||
|
serverController.abort();
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
console.log("Running in server mode, use Ctrl-c to stop");
|
||||||
|
while (true) {
|
||||||
|
await sleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { AssetBundle, AssetJson } from "../lib/asset_bundle/bundle.ts";
|
||||||
|
|
||||||
import { determineDatabaseBackend } from "../server/db_backend.ts";
|
import { determineDatabaseBackend } from "../server/db_backend.ts";
|
||||||
import { SpaceServerConfig } from "../server/instance.ts";
|
import { SpaceServerConfig } from "../server/instance.ts";
|
||||||
import { runPlug } from "../cli/plug_run.ts";
|
import { runPlug } from "../cmd/plug_run.ts";
|
||||||
import { PrefixedKvPrimitives } from "$lib/data/prefixed_kv_primitives.ts";
|
import { PrefixedKvPrimitives } from "$lib/data/prefixed_kv_primitives.ts";
|
||||||
import { sleep } from "$lib/async.ts";
|
import { sleep } from "$lib/async.ts";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue