Cleanup
parent
76636dd9b1
commit
0182a587e4
|
@ -1,3 +1,4 @@
|
||||||
{
|
{
|
||||||
"editor.formatOnSave": true
|
"editor.formatOnSave": true,
|
||||||
}
|
"typescriptHero.imports.stringQuoteStyle": "\""
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { app, BrowserWindow, dialog, Menu } from "electron";
|
import { app, BrowserWindow, dialog, Menu } from "electron";
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
import { ExpressServer } from "@silverbulletmd/server/api_server";
|
import { ExpressServer } from "@silverbulletmd/server/express_server";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
|
||||||
let mainWindow: BrowserWindow | undefined;
|
let mainWindow: BrowserWindow | undefined;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { SpacePrimitives } from "./space_primitives";
|
|
||||||
import { EventHook } from "@plugos/plugos/hooks/event";
|
import { EventHook } from "@plugos/plugos/hooks/event";
|
||||||
import { PageMeta } from "../types";
|
|
||||||
import { Plug } from "@plugos/plugos/plug";
|
import { Plug } from "@plugos/plugos/plug";
|
||||||
|
|
||||||
|
import { PageMeta } from "../types";
|
||||||
import { plugPrefix, trashPrefix } from "./constants";
|
import { plugPrefix, trashPrefix } from "./constants";
|
||||||
|
import { SpacePrimitives } from "./space_primitives";
|
||||||
|
|
||||||
export class EventedSpacePrimitives implements SpacePrimitives {
|
export class EventedSpacePrimitives implements SpacePrimitives {
|
||||||
constructor(private wrapped: SpacePrimitives, private eventHook: EventHook) {}
|
constructor(private wrapped: SpacePrimitives, private eventHook: EventHook) {}
|
||||||
|
|
|
@ -9,5 +9,5 @@ export async function invokeFunction(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function reloadPlugs() {
|
export async function reloadPlugs() {
|
||||||
return syscall("system.reloadPlugs");
|
syscall("system.reloadPlugs");
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ export class System<HookT> extends EventEmitter<SystemEvents<HookT>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async unload(name: string) {
|
async unload(name: string) {
|
||||||
console.log("Unloading", name);
|
// console.log("Unloading", name);
|
||||||
const plug = this.plugs.get(name);
|
const plug = this.plugs.get(name);
|
||||||
if (!plug) {
|
if (!plug) {
|
||||||
throw Error(`Plug ${name} not found`);
|
throw Error(`Plug ${name} not found`);
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
name: plugmd
|
name: plugmanager
|
||||||
functions:
|
functions:
|
||||||
updatePlugsCommand:
|
updatePlugsCommand:
|
||||||
path: ./plugmd.ts:updatePlugsCommand
|
path: ./plugmanager.ts:updatePlugsCommand
|
||||||
command:
|
command:
|
||||||
name: "Plugs: Update"
|
name: "Plugs: Update"
|
||||||
key: "Ctrl-Shift-p"
|
key: "Ctrl-Shift-p"
|
||||||
mac: "Cmd-Shift-p"
|
mac: "Cmd-Shift-p"
|
||||||
updatePlugs:
|
updatePlugs:
|
||||||
path: ./plugmd.ts:updatePlugs
|
path: ./plugmanager.ts:updatePlugs
|
||||||
env: server
|
env: server
|
||||||
compile:
|
compile:
|
||||||
path: "./plugmd.ts:compileCommand"
|
path: "./plugmanager.ts:compileCommand"
|
||||||
command:
|
command:
|
||||||
name: "Plug: Compile"
|
name: "Plug: Compile"
|
||||||
mac: "Cmd-Shift-c"
|
mac: "Cmd-Shift-c"
|
||||||
key: "Ctrl-Shift-c"
|
key: "Ctrl-Shift-c"
|
||||||
compileJS:
|
compileJS:
|
||||||
path: "./plugmd.ts:compileJS"
|
path: "./plugmanager.ts:compileJS"
|
||||||
env: server
|
env: server
|
||||||
|
|
||||||
getPlugPlugMd:
|
getPlugPlugMd:
|
||||||
path: "./plugmd.ts:getPlugPlugMd"
|
path: "./plugmanager.ts:getPlugPlugMd"
|
||||||
events:
|
events:
|
||||||
- get-plug:plugmd
|
- get-plug:plugmd
|
|
@ -1,12 +1,10 @@
|
||||||
import { dispatch } from "@plugos/plugos-syscall/event";
|
import { dispatch } from "@plugos/plugos-syscall/event";
|
||||||
import type { Manifest } from "@silverbulletmd/common/manifest";
|
|
||||||
import {
|
import {
|
||||||
addParentPointers,
|
addParentPointers,
|
||||||
collectNodesOfType,
|
collectNodesOfType,
|
||||||
findNodeOfType,
|
findNodeOfType,
|
||||||
} from "@silverbulletmd/common/tree";
|
} from "@silverbulletmd/common/tree";
|
||||||
import {
|
import {
|
||||||
getCurrentPage,
|
|
||||||
getText,
|
getText,
|
||||||
hideBhs,
|
hideBhs,
|
||||||
showBhs,
|
showBhs,
|
||||||
|
@ -23,8 +21,11 @@ import {
|
||||||
reloadPlugs,
|
reloadPlugs,
|
||||||
} from "@silverbulletmd/plugos-silverbullet-syscall/system";
|
} from "@silverbulletmd/plugos-silverbullet-syscall/system";
|
||||||
import YAML from "yaml";
|
import YAML from "yaml";
|
||||||
|
|
||||||
import { extractMeta } from "../query/data";
|
import { extractMeta } from "../query/data";
|
||||||
|
|
||||||
|
import type { Manifest } from "@silverbulletmd/common/manifest";
|
||||||
|
|
||||||
export async function compileCommand() {
|
export async function compileCommand() {
|
||||||
let text = await getText();
|
let text = await getText();
|
||||||
try {
|
try {
|
||||||
|
@ -139,7 +140,7 @@ export async function updatePlugs() {
|
||||||
}
|
}
|
||||||
let plugYaml = codeTextNode.children![0].text;
|
let plugYaml = codeTextNode.children![0].text;
|
||||||
let plugList = YAML.parse(plugYaml!);
|
let plugList = YAML.parse(plugYaml!);
|
||||||
console.log("Plug YAML", plugList);
|
// console.log("Plug YAML", plugList);
|
||||||
let allPlugNames: string[] = [];
|
let allPlugNames: string[] = [];
|
||||||
for (let plugUri of plugList) {
|
for (let plugUri of plugList) {
|
||||||
let [protocol, ...rest] = plugUri.split(":");
|
let [protocol, ...rest] = plugUri.split(":");
|
||||||
|
@ -164,11 +165,11 @@ export async function updatePlugs() {
|
||||||
await deletePage(`_plug/${existingPlug}`);
|
await deletePage(`_plug/${existingPlug}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Important not to await!
|
await reloadPlugs();
|
||||||
reloadPlugs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPlugPlugMd(pageName: string): Promise<Manifest> {
|
export async function getPlugPlugMd(pageName: string): Promise<Manifest> {
|
||||||
let { text } = await readPage(pageName);
|
let { text } = await readPage(pageName);
|
||||||
|
console.log("Compiling", pageName);
|
||||||
return compileDefinition(text);
|
return compileDefinition(text);
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
import express, { Express } from "express";
|
import express, { Express } from "express";
|
||||||
import { Manifest, SilverBulletHooks } from "@silverbulletmd/common/manifest";
|
import { Manifest, SilverBulletHooks } from "@silverbulletmd/common/manifest";
|
||||||
import { EndpointHook } from "@plugos/plugos/hooks/endpoint";
|
import { EndpointHook } from "@plugos/plugos/hooks/endpoint";
|
||||||
import { readFile } from "fs/promises";
|
import { readdir, readFile } from "fs/promises";
|
||||||
import { System } from "@plugos/plugos/system";
|
import { System } from "@plugos/plugos/system";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import { DiskSpacePrimitives } from "@silverbulletmd/common/spaces/disk_space_primitives";
|
import { DiskSpacePrimitives } from "@silverbulletmd/common/spaces/disk_space_primitives";
|
||||||
|
@ -17,7 +17,6 @@ import { NodeCronHook } from "@plugos/plugos/hooks/node_cron";
|
||||||
import { markdownSyscalls } from "@silverbulletmd/common/syscalls/markdown";
|
import { markdownSyscalls } from "@silverbulletmd/common/syscalls/markdown";
|
||||||
import { EventedSpacePrimitives } from "@silverbulletmd/common/spaces/evented_space_primitives";
|
import { EventedSpacePrimitives } from "@silverbulletmd/common/spaces/evented_space_primitives";
|
||||||
import { Space } from "@silverbulletmd/common/spaces/space";
|
import { Space } from "@silverbulletmd/common/spaces/space";
|
||||||
import { safeRun, throttle } from "@silverbulletmd/common/util";
|
|
||||||
import { createSandbox } from "@plugos/plugos/environments/node_sandbox";
|
import { createSandbox } from "@plugos/plugos/environments/node_sandbox";
|
||||||
import { jwtSyscalls } from "@plugos/plugos/syscalls/jwt";
|
import { jwtSyscalls } from "@plugos/plugos/syscalls/jwt";
|
||||||
import buildMarkdown from "@silverbulletmd/web/parser";
|
import buildMarkdown from "@silverbulletmd/web/parser";
|
||||||
|
@ -25,6 +24,7 @@ import { loadMarkdownExtensions } from "@silverbulletmd/web/markdown_ext";
|
||||||
import http, { Server } from "http";
|
import http, { Server } from "http";
|
||||||
import { esbuildSyscalls } from "@plugos/plugos/syscalls/esbuild";
|
import { esbuildSyscalls } from "@plugos/plugos/syscalls/esbuild";
|
||||||
import { systemSyscalls } from "./syscalls/system";
|
import { systemSyscalls } from "./syscalls/system";
|
||||||
|
import { plugPrefix } from "@silverbulletmd/common/spaces/constants";
|
||||||
|
|
||||||
export class ExpressServer {
|
export class ExpressServer {
|
||||||
app: Express;
|
app: Express;
|
||||||
|
@ -82,10 +82,6 @@ export class ExpressServer {
|
||||||
this.system.registerSyscalls([], jwtSyscalls());
|
this.system.registerSyscalls([], jwtSyscalls());
|
||||||
this.system.addHook(new EndpointHook(this.app, "/_/"));
|
this.system.addHook(new EndpointHook(this.app, "/_/"));
|
||||||
|
|
||||||
let throttledRebuildMdExtensions = throttle(() => {
|
|
||||||
this.rebuildMdExtensions();
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
this.eventHook.addLocalListener(
|
this.eventHook.addLocalListener(
|
||||||
"get-plug:builtin",
|
"get-plug:builtin",
|
||||||
async (plugName: string): Promise<Manifest> => {
|
async (plugName: string): Promise<Manifest> => {
|
||||||
|
@ -115,11 +111,42 @@ export class ExpressServer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async bootstrapBuiltinPlugs() {
|
||||||
|
let allPlugFiles = await readdir(this.builtinPlugDir);
|
||||||
|
let pluginNames = [];
|
||||||
|
for (let file of allPlugFiles) {
|
||||||
|
if (file.endsWith(".plug.json")) {
|
||||||
|
let manifestJson = await readFile(
|
||||||
|
path.join(this.builtinPlugDir, file),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
let manifest: Manifest = JSON.parse(manifestJson);
|
||||||
|
pluginNames.push(manifest.name);
|
||||||
|
await this.space.writePage(
|
||||||
|
`${plugPrefix}${manifest.name}`,
|
||||||
|
manifestJson
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.space.writePage(
|
||||||
|
"PLUGS",
|
||||||
|
"This file lists all plugs that SilverBullet will load. Run the `Plugs: Update` command to update and reload this list of plugs.\n\n```yaml\n- " +
|
||||||
|
pluginNames.map((name) => `builtin:${name}`).join("\n- ") +
|
||||||
|
"\n```"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async reloadPlugs() {
|
async reloadPlugs() {
|
||||||
await this.space.updatePageList();
|
await this.space.updatePageList();
|
||||||
|
let allPlugs = this.space.listPlugs();
|
||||||
|
if (allPlugs.size === 0) {
|
||||||
|
await this.bootstrapBuiltinPlugs();
|
||||||
|
allPlugs = this.space.listPlugs();
|
||||||
|
}
|
||||||
await this.system.unloadAll();
|
await this.system.unloadAll();
|
||||||
console.log("Reloading plugs");
|
console.log("Reloading plugs");
|
||||||
for (let pageInfo of this.space.listPlugs()) {
|
for (let pageInfo of allPlugs) {
|
||||||
let { text } = await this.space.readPage(pageInfo.name);
|
let { text } = await this.space.readPage(pageInfo.name);
|
||||||
await this.system.load(JSON.parse(text), (p) =>
|
await this.system.load(JSON.parse(text), (p) =>
|
||||||
createSandbox(p, this.preloadedModules)
|
createSandbox(p, this.preloadedModules)
|
|
@ -1,13 +1,11 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import yargs from "yargs";
|
|
||||||
import { hideBin } from "yargs/helpers";
|
|
||||||
import { ExpressServer } from "./api_server";
|
|
||||||
import { nodeModulesDir } from "@plugos/plugos/environments/node_sandbox";
|
import { nodeModulesDir } from "@plugos/plugos/environments/node_sandbox";
|
||||||
import { preloadModules } from "@silverbulletmd/common/preload_modules";
|
import { preloadModules } from "@silverbulletmd/common/preload_modules";
|
||||||
import path from "path";
|
|
||||||
import { realpath } from "fs/promises";
|
|
||||||
import { realpathSync } from "fs";
|
import { realpathSync } from "fs";
|
||||||
|
import yargs from "yargs";
|
||||||
|
import { hideBin } from "yargs/helpers";
|
||||||
|
|
||||||
|
import { ExpressServer } from "./express_server";
|
||||||
|
|
||||||
let args = yargs(hideBin(process.argv))
|
let args = yargs(hideBin(process.argv))
|
||||||
.option("port", {
|
.option("port", {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { SysCallMapping } from "@plugos/plugos/system";
|
import { SysCallMapping } from "@plugos/plugos/system";
|
||||||
import type { ExpressServer } from "../api_server";
|
import type { ExpressServer } from "../express_server";
|
||||||
|
|
||||||
export function systemSyscalls(expressServer: ExpressServer): SysCallMapping {
|
export function systemSyscalls(expressServer: ExpressServer): SysCallMapping {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue