Plug manger rebuild
parent
f6758dbbaf
commit
f9ddb49ec6
|
@ -4,22 +4,26 @@ import path from "path";
|
||||||
|
|
||||||
export async function compile(
|
export async function compile(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
functionName: string = "",
|
functionName: string | undefined = undefined,
|
||||||
debug: boolean = false,
|
debug: boolean = false,
|
||||||
excludeModules: string[] = [],
|
excludeModules: string[] = [],
|
||||||
meta = false
|
meta = false
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
let outFile = path.join(path.dirname(filePath), "_out.tmp");
|
let outFile = path.resolve(path.dirname(filePath), "_out.tmp");
|
||||||
let inFile = filePath;
|
let inFile = filePath;
|
||||||
|
|
||||||
if (functionName) {
|
if (functionName) {
|
||||||
// Generate a new file importing just this one function and exporting it
|
// Generate a new file importing just this one function and exporting it
|
||||||
inFile = "_in.ts";
|
inFile = path.resolve(path.dirname(filePath), "_in.ts");
|
||||||
await writeFile(
|
await writeFile(
|
||||||
inFile,
|
inFile,
|
||||||
`import {${functionName}} from "./${filePath}";export default ${functionName};`
|
`import {${functionName}} from "./${path.basename(
|
||||||
|
filePath
|
||||||
|
)}";export default ${functionName};`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// console.log("In:", inFile);
|
||||||
|
// console.log("Outfile:", outFile);
|
||||||
|
|
||||||
// TODO: Figure out how to make source maps work correctly with eval() code
|
// TODO: Figure out how to make source maps work correctly with eval() code
|
||||||
let result = await esbuild.build({
|
let result = await esbuild.build({
|
||||||
|
|
|
@ -93,7 +93,8 @@ self.addEventListener("message", (event: { data: WorkerMessage }) => {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
error: e.message,
|
error: e.message,
|
||||||
});
|
});
|
||||||
throw e;
|
console.error("Error invoking function", data.name, e.message);
|
||||||
|
// throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -15,7 +15,8 @@ export function esbuildSyscalls(): SysCallMapping {
|
||||||
"esbuild.compile": async (
|
"esbuild.compile": async (
|
||||||
ctx,
|
ctx,
|
||||||
filename: string,
|
filename: string,
|
||||||
code: string
|
code: string,
|
||||||
|
functionName?: string
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
let tmpDir = `${tmpdir()}/plugos-${Math.random()}`;
|
let tmpDir = `${tmpdir()}/plugos-${Math.random()}`;
|
||||||
await mkdir(tmpDir, { recursive: true });
|
await mkdir(tmpDir, { recursive: true });
|
||||||
|
@ -34,7 +35,9 @@ export function esbuildSyscalls(): SysCallMapping {
|
||||||
}
|
}
|
||||||
|
|
||||||
await writeFile(`${tmpDir}/${filename}`, code);
|
await writeFile(`${tmpDir}/${filename}`, code);
|
||||||
let jsCode = await compile(`${tmpDir}/${filename}`, "", false, ["yaml"]);
|
let jsCode = await compile(`${tmpDir}/${filename}`, functionName, false, [
|
||||||
|
"yaml",
|
||||||
|
]);
|
||||||
await rm(tmpDir, { recursive: true });
|
await rm(tmpDir, { recursive: true });
|
||||||
return jsCode;
|
return jsCode;
|
||||||
},
|
},
|
||||||
|
|
|
@ -58,69 +58,55 @@ export async function checkCommand() {
|
||||||
async function compileDefinition(text: string): Promise<Manifest> {
|
async function compileDefinition(text: string): Promise<Manifest> {
|
||||||
let tree = await parseMarkdown(text);
|
let tree = await parseMarkdown(text);
|
||||||
|
|
||||||
let pageMeta = extractMeta(tree);
|
let codeNodes = collectNodesOfType(tree, "FencedCode");
|
||||||
|
let manifest: Manifest | undefined;
|
||||||
if (!pageMeta.name) {
|
let code: string | undefined;
|
||||||
throw new Error("No 'name' specified in page meta");
|
let language = "js";
|
||||||
}
|
for (let codeNode of codeNodes) {
|
||||||
|
let codeInfo = findNodeOfType(codeNode, "CodeInfo")!.children![0].text!;
|
||||||
addParentPointers(tree);
|
let codeText = findNodeOfType(codeNode, "CodeText")!.children![0].text!;
|
||||||
let allHeaders = collectNodesOfType(tree, "ATXHeading2");
|
if (codeInfo === "yaml") {
|
||||||
let manifest: Manifest = {
|
manifest = YAML.parse(codeText);
|
||||||
name: pageMeta.name,
|
|
||||||
functions: {},
|
|
||||||
};
|
|
||||||
for (let t of allHeaders) {
|
|
||||||
let parent = t.parent!;
|
|
||||||
let headerIdx = parent.children!.indexOf(t);
|
|
||||||
let headerTitle = t.children![1].text!.trim();
|
|
||||||
if (!headerTitle.startsWith("function ")) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let functionName = headerTitle
|
if (codeInfo === "typescript" || codeInfo === "ts") {
|
||||||
.substring("function ".length)
|
language = "ts";
|
||||||
.replace(/[^\w]/g, "_");
|
|
||||||
let meta: any;
|
|
||||||
let code: string | undefined;
|
|
||||||
let language = "js";
|
|
||||||
for (let i = headerIdx + 1; i < parent.children!.length; i++) {
|
|
||||||
let child = parent.children![i];
|
|
||||||
if (child.type === "FencedCode") {
|
|
||||||
let codeInfo = findNodeOfType(child, "CodeInfo")!.children![0].text!;
|
|
||||||
let codeText = findNodeOfType(child, "CodeText")!.children![0].text!;
|
|
||||||
if (codeInfo === "yaml") {
|
|
||||||
meta = YAML.parse(codeText);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (codeInfo === "typescript" || codeInfo === "ts") {
|
|
||||||
language = "ts";
|
|
||||||
}
|
|
||||||
code = codeText;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child.type?.startsWith("ATXHeading")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (code) {
|
|
||||||
let compiled = await invokeFunction(
|
|
||||||
"server",
|
|
||||||
"compileJS",
|
|
||||||
`file.${language}`,
|
|
||||||
code
|
|
||||||
);
|
|
||||||
manifest.functions[functionName] = meta;
|
|
||||||
manifest.functions[functionName].code = compiled;
|
|
||||||
}
|
}
|
||||||
|
code = codeText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!manifest) {
|
||||||
|
throw new Error("No meta found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!code) {
|
||||||
|
throw new Error("No code found");
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest.functions = manifest.functions || {};
|
||||||
|
|
||||||
|
for (let [name, func] of Object.entries(manifest.functions)) {
|
||||||
|
let compiled = await invokeFunction(
|
||||||
|
"server",
|
||||||
|
"compileJS",
|
||||||
|
`file.${language}`,
|
||||||
|
code,
|
||||||
|
name
|
||||||
|
);
|
||||||
|
func.code = compiled;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Doing the whole manifest thing");
|
||||||
|
|
||||||
return manifest;
|
return manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function compileJS(
|
export async function compileJS(
|
||||||
filename: string,
|
filename: string,
|
||||||
code: string
|
code: string,
|
||||||
|
functionName: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return self.syscall("esbuild.compile", filename, code);
|
return self.syscall("esbuild.compile", filename, code, functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listPlugs(): Promise<string[]> {
|
async function listPlugs(): Promise<string[]> {
|
||||||
|
@ -151,7 +137,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(":");
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
import {pullDataCommand} from ".//var/folders/s2/4nqrw2192hngtxg672qzc0nr0000gn/T/plugos-0.8739407042390945/file.js";export default pullDataCommand;
|
|
@ -94,7 +94,7 @@ export class ExpressServer {
|
||||||
sandboxSyscalls(this.system),
|
sandboxSyscalls(this.system),
|
||||||
jwtSyscalls()
|
jwtSyscalls()
|
||||||
);
|
);
|
||||||
this.system.addHook(new EndpointHook(this.app, "/_/"));
|
this.system.addHook(new EndpointHook(this.app, "/_"));
|
||||||
|
|
||||||
this.eventHook.addLocalListener(
|
this.eventHook.addLocalListener(
|
||||||
"get-plug:builtin",
|
"get-plug:builtin",
|
||||||
|
|
Loading…
Reference in New Issue