Git plug tweaks
This commit is contained in:
parent
6dd56e85de
commit
16fa05d4cc
@ -12,7 +12,7 @@
|
||||
"watch": "rm -rf .parcel-cache && parcel watch",
|
||||
"build": "parcel build",
|
||||
"clean": "rm -rf dist",
|
||||
"plugs": "./plugos/dist/plugos/plugos-bundle.js -w --dist plugs/dist plugs/*/*.plug.yaml",
|
||||
"plugs": "cd plugs && ../plugos/dist/plugos/plugos-bundle.js -w --dist dist */*.plug.yaml",
|
||||
"server": "nodemon -w dist/server dist/server/server.js pages",
|
||||
"test": "jest dist/test"
|
||||
},
|
||||
|
@ -1,27 +1,24 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import esbuild from "esbuild";
|
||||
import { readFile, unlink, writeFile } from "fs/promises";
|
||||
import { readFile, unlink, watch, writeFile } from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
import yargs from "yargs";
|
||||
import { hideBin } from "yargs/helpers";
|
||||
import { Manifest } from "../types";
|
||||
import { watchFile } from "fs";
|
||||
import YAML from "yaml";
|
||||
|
||||
async function compile(filePath: string, functionName: string, debug: boolean) {
|
||||
let outFile = "out.js";
|
||||
|
||||
let outFile = "_out.tmp";
|
||||
let inFile = filePath;
|
||||
|
||||
if (functionName) {
|
||||
// Generate a new file importing just this one function and exporting it
|
||||
inFile = "in.js";
|
||||
inFile = "_in.js";
|
||||
await writeFile(
|
||||
inFile,
|
||||
`import {${functionName}} from "./${filePath}";
|
||||
export default ${functionName};`
|
||||
`import {${functionName}} from "./${filePath}";export default ${functionName};`
|
||||
);
|
||||
}
|
||||
|
||||
@ -103,14 +100,32 @@ async function run() {
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
for (const plugManifestPath of args._) {
|
||||
let manifestPath = plugManifestPath as string;
|
||||
await buildManifest(manifestPath, args.dist, !!args.debug);
|
||||
if (args.watch) {
|
||||
watchFile(manifestPath, { interval: 1000 }, async () => {
|
||||
console.log("Rebuilding", manifestPath);
|
||||
|
||||
async function buildAll() {
|
||||
for (const plugManifestPath of args._) {
|
||||
let manifestPath = plugManifestPath as string;
|
||||
try {
|
||||
await buildManifest(manifestPath, args.dist, !!args.debug);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Error building ${manifestPath}:`, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await buildAll();
|
||||
if (args.watch) {
|
||||
console.log("Watching for changes...");
|
||||
for await (const { eventType, filename } of watch(".", {
|
||||
recursive: true,
|
||||
})) {
|
||||
if (
|
||||
filename.endsWith(".plug.yaml") ||
|
||||
filename.endsWith(".ts") ||
|
||||
(filename.endsWith(".js") && !filename.endsWith("_in.js"))
|
||||
) {
|
||||
console.log("Change detected", eventType, filename);
|
||||
await buildAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
import { Feature, Manifest } from "../types";
|
||||
import { System } from "../system";
|
||||
|
||||
// System events:
|
||||
// - plug:load (plugName: string)
|
||||
|
||||
export type EventHook = {
|
||||
events?: string[];
|
||||
};
|
||||
@ -18,7 +21,10 @@ export class EventFeature implements Feature<EventHook> {
|
||||
plug.manifest!.functions
|
||||
)) {
|
||||
if (functionDef.events && functionDef.events.includes(eventName)) {
|
||||
promises.push(plug.invoke(name, [data]));
|
||||
// Only dispatch functions that can run in this environment
|
||||
if (plug.canInvoke(name)) {
|
||||
promises.push(plug.invoke(name, [data]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,6 +33,11 @@ export class EventFeature implements Feature<EventHook> {
|
||||
|
||||
apply(system: System<EventHook>): void {
|
||||
this.system = system;
|
||||
this.system.on({
|
||||
plugLoaded: (name) => {
|
||||
this.dispatchEvent("plug:load", name);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
validateManifest(manifest: Manifest<EventHook>): string[] {
|
||||
|
@ -30,14 +30,27 @@ export class Sandbox {
|
||||
|
||||
async load(name: string, code: string): Promise<void> {
|
||||
await this.worker.ready;
|
||||
let outstandingInit = this.outstandingInits.get(name);
|
||||
if (outstandingInit) {
|
||||
// Load already in progress, let's wait for it...
|
||||
return new Promise((resolve) => {
|
||||
this.outstandingInits.set(name, () => {
|
||||
outstandingInit!();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
this.worker.postMessage({
|
||||
type: "load",
|
||||
name: name,
|
||||
code: code,
|
||||
} as WorkerMessage);
|
||||
return new Promise((resolve) => {
|
||||
this.loadedFunctions.add(name);
|
||||
this.outstandingInits.set(name, resolve);
|
||||
this.outstandingInits.set(name, () => {
|
||||
this.loadedFunctions.add(name);
|
||||
this.outstandingInits.delete(name);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,6 @@ functions:
|
||||
welcome:
|
||||
path: "./server.ts:welcome"
|
||||
events:
|
||||
- load
|
||||
- plug:load
|
||||
env: server
|
||||
|
||||
|
@ -11,7 +11,10 @@ export function endpointTest(req: EndpointRequest): EndpointResponse {
|
||||
};
|
||||
}
|
||||
|
||||
export function welcome() {
|
||||
console.log("Hello world!");
|
||||
export function welcome(plugName: string) {
|
||||
if (plugName !== "core") {
|
||||
return;
|
||||
}
|
||||
console.log("Hello world!!", plugName);
|
||||
return "hi";
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
export default function welcome() {
|
||||
console.log("Hello world!");
|
||||
}
|
@ -27,12 +27,13 @@ export async function snapshotCommand() {
|
||||
}
|
||||
|
||||
export async function syncCommand() {
|
||||
await syscall("editor.flashNotification", "Syncing with git");
|
||||
await syscall("system.invokeFunctionOnServer", "sync");
|
||||
await syscall("editor.flashNotification", "Git sync complete!");
|
||||
}
|
||||
|
||||
export async function sync() {
|
||||
console.log("Going to sync with git");
|
||||
console.log("First locally committing everything");
|
||||
await commit();
|
||||
console.log("Then pulling from remote");
|
||||
await syscall("shell.run", "git", ["pull"]);
|
||||
|
@ -42,6 +42,9 @@ export default (editor: Editor): SysCallMapping => ({
|
||||
openUrl: async (ctx, url: string) => {
|
||||
window.open(url, "_blank")!.focus();
|
||||
},
|
||||
flashNotification: (ctx, message: string) => {
|
||||
editor.flashNotification(message);
|
||||
},
|
||||
insertAtPos: (ctx, text: string, pos: number) => {
|
||||
editor.editorView!.dispatch({
|
||||
changes: {
|
||||
|
Loading…
Reference in New Issue
Block a user