Plugbox cleanup
This commit is contained in:
parent
24ceaea9d5
commit
a97bff60d9
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@ logo.pxd
|
||||
.DS_Store
|
||||
node_modules
|
||||
.parcel-cache
|
||||
dist
|
||||
dist
|
||||
generated
|
@ -1,9 +0,0 @@
|
||||
import {syscall} from "./syscall.ts";
|
||||
|
||||
export async function put(key: string, value: any) {
|
||||
return await syscall("db.put", key, value);
|
||||
}
|
||||
|
||||
export async function get(key: string) {
|
||||
return await syscall("db.get", key);
|
||||
}
|
@ -6,10 +6,11 @@
|
||||
"main": "dist/bundle.js",
|
||||
"scripts": {
|
||||
"build": "parcel build",
|
||||
"core": "node dist/bundle.js --debug core/core.plugin.json ../webapp/src/generated/core.plugin.json"
|
||||
"check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"esbuild": "^0.14.24",
|
||||
"idb": "^7.0.0",
|
||||
"typescript": ">=3.0.0",
|
||||
"vm2": "^3.9.9",
|
||||
"yargs": "^17.3.1"
|
||||
|
@ -6,7 +6,7 @@ import yargs from "yargs";
|
||||
import { hideBin } from "yargs/helpers";
|
||||
import { Manifest } from "../../webapp/src/plugins/types";
|
||||
|
||||
async function compile(filePath: string, sourceMap: string) {
|
||||
async function compile(filePath: string, sourceMap: boolean) {
|
||||
let tempFile = "out.js";
|
||||
let js = await esbuild.build({
|
||||
entryPoints: [filePath],
|
||||
@ -25,7 +25,7 @@ async function compile(filePath: string, sourceMap: string) {
|
||||
return jsCode;
|
||||
}
|
||||
|
||||
async function bundle(manifestPath, sourceMaps) {
|
||||
async function bundle(manifestPath: string, sourceMaps: boolean) {
|
||||
const rootPath = path.dirname(manifestPath);
|
||||
const manifest = JSON.parse(
|
||||
(await readFile(manifestPath)).toString()
|
||||
@ -53,7 +53,7 @@ async function run() {
|
||||
})
|
||||
.parse();
|
||||
|
||||
let generatedManifest = await bundle(args._[0], !!args.debug);
|
||||
let generatedManifest = await bundle(args._[0] as string, !!args.debug);
|
||||
writeFile(args._[1] as string, JSON.stringify(generatedManifest, null, 2));
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,6 @@ export class FunctionWorker {
|
||||
private plugin: Plugin;
|
||||
|
||||
constructor(plugin: Plugin, pathPrefix: string, name: string) {
|
||||
// this.worker = new Worker(new URL("function_worker.ts", import.meta.url), {
|
||||
// type: "classic",
|
||||
// });
|
||||
let worker = window.Worker;
|
||||
this.worker = new worker("/function_worker.js");
|
||||
|
27
plugbox/src/util.ts
Normal file
27
plugbox/src/util.ts
Normal file
@ -0,0 +1,27 @@
|
||||
export function countWords(str: string): number {
|
||||
var matches = str.match(/[\w\d\'\'-]+/gi);
|
||||
return matches ? matches.length : 0;
|
||||
}
|
||||
|
||||
export function readingTime(wordCount: number): number {
|
||||
// 225 is average word reading speed for adults
|
||||
return Math.ceil(wordCount / 225);
|
||||
}
|
||||
|
||||
export function safeRun(fn: () => Promise<void>) {
|
||||
fn().catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
export function isMacLike() {
|
||||
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
||||
}
|
11
plugbox/tsconfig.json
Normal file
11
plugbox/tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"include": ["src/**/*", "../webapp/src/plugbox_browser/browser_system.ts"],
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"strict": true,
|
||||
"moduleResolution": "node",
|
||||
"module": "ESNext",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
7
plugs/Makefile
Normal file
7
plugs/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
BUILD=node ../plugbox/dist/bundle.js
|
||||
|
||||
core: *
|
||||
${BUILD} --debug core/core.plug.json ../webapp/src/generated/core.plug.json
|
||||
|
||||
watch: *
|
||||
ls -d core/* | entr make
|
@ -1,4 +1,4 @@
|
||||
import { syscall } from "./lib/syscall.ts";
|
||||
import { syscall } from "./lib/syscall";
|
||||
|
||||
export async function insertToday() {
|
||||
let niceDate = new Date().toISOString().split("T")[0];
|
@ -1,4 +1,4 @@
|
||||
import { syscall } from "./lib/syscall.ts";
|
||||
import { syscall } from "./lib/syscall";
|
||||
|
||||
export async function toggleH1() {
|
||||
await togglePrefix("# ");
|
@ -1,5 +1,5 @@
|
||||
import { ClickEvent } from "../../webapp/src/app_event.ts";
|
||||
import { syscall } from "./lib/syscall.ts";
|
||||
import { ClickEvent } from "../../webapp/src/app_event";
|
||||
import { syscall } from "./lib/syscall";
|
||||
|
||||
async function navigate(syntaxNode: any) {
|
||||
if (!syntaxNode) {
|
@ -1,5 +1,5 @@
|
||||
import { ClickEvent } from "../../webapp/src/app_event.ts";
|
||||
import { syscall } from "./lib/syscall.ts";
|
||||
import { ClickEvent } from "../../webapp/src/app_event";
|
||||
import { syscall } from "./lib/syscall";
|
||||
|
||||
export async function taskToggle(event: ClickEvent) {
|
||||
let syntaxNode = await syscall("editor.getSyntaxNodeAtPos", event.pos);
|
@ -1,3 +1,5 @@
|
||||
import { syscall } from "./lib/syscall";
|
||||
|
||||
function countWords(str: string): number {
|
||||
var matches = str.match(/[\w\d\'\'-]+/gi);
|
||||
return matches ? matches.length : 0;
|
||||
@ -8,8 +10,6 @@ function readingTime(wordCount: number): number {
|
||||
return Math.ceil(wordCount / 225);
|
||||
}
|
||||
|
||||
import { syscall } from "./lib/syscall.ts";
|
||||
|
||||
export async function wordCount({ text }: { text: string }) {
|
||||
let sysCallText = (await syscall("editor.getText")) as string;
|
||||
const count = countWords(sysCallText);
|
@ -19,9 +19,20 @@
|
||||
"@parcel/validator-typescript": "^2.3.2",
|
||||
"@types/react": "^17.0.39",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"assert": "^2.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"events": "^3.3.0",
|
||||
"os-browserify": "^0.3.0",
|
||||
"parcel": "^2.3.2",
|
||||
"path-browserify": "^1.0.1",
|
||||
"querystring-es3": "^0.2.1",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"tty-browserify": "^0.0.1",
|
||||
"typescript": ">=3.0.0",
|
||||
"uglify-js": "^3.15.1"
|
||||
"uglify-js": "^3.15.1",
|
||||
"url": "^0.11.0",
|
||||
"util": "^0.12.4"
|
||||
},
|
||||
"resolutions": {
|
||||
"@lezer/common": "git://github.com/zefhemel/common.git#046c880d1fcab713cadad327a5b7d8bb5de6522c"
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
|
||||
import React, { useEffect, useReducer } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import coreManifest from "./generated/core.plugin.json";
|
||||
import coreManifest from "./generated/core.plug.json";
|
||||
// @ts-ignore
|
||||
window.coreManifest = coreManifest;
|
||||
import { AppEvent, AppEventDispatcher, ClickEvent } from "./app_event";
|
||||
@ -36,9 +36,10 @@ import { lineWrapper } from "./lineWrapper";
|
||||
import { markdown } from "./markdown";
|
||||
import { IPageNavigator, PathPageNavigator } from "./navigator";
|
||||
import customMarkDown from "./parser";
|
||||
import { BrowserSystem } from "./plugins/browser_system";
|
||||
import { Plugin } from "./plugins/runtime";
|
||||
import { slashCommandRegexp } from "./plugins/types";
|
||||
import { BrowserSystem } from "./plugbox_browser/browser_system";
|
||||
import { Plugin } from "../../plugbox/src/runtime";
|
||||
import { slashCommandRegexp } from "../../plugbox/src/types";
|
||||
|
||||
import reducer from "./reducer";
|
||||
import { smartQuoteKeymap } from "./smart_quotes";
|
||||
import { Space } from "./space";
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
||||
import { PluginLoader, System } from "./runtime";
|
||||
import { Manifest } from "./types";
|
||||
import { PluginLoader, System } from "../../../plugbox/src/runtime";
|
||||
import { Manifest } from "../../../plugbox/src/types";
|
||||
import { sleep } from "../util";
|
||||
|
||||
export class BrowserLoader implements PluginLoader {
|
||||
@ -43,7 +43,7 @@ export class BrowserSystem extends System {
|
||||
async bootServiceWorker() {
|
||||
// @ts-ignore
|
||||
let reg = navigator.serviceWorker.register(
|
||||
new URL("../plugin_sw.ts", import.meta.url),
|
||||
new URL("../plugbox_sw.ts", import.meta.url),
|
||||
{
|
||||
type: "module",
|
||||
scope: "/",
|
@ -1,12 +1,10 @@
|
||||
import { Manifest } from "./plugins/types";
|
||||
import { Manifest } from "../../plugbox/src/types";
|
||||
|
||||
import { openDB, wrap, unwrap } from "idb";
|
||||
import { openDB } from "idb";
|
||||
|
||||
const rootUrl = location.origin + "/plugin";
|
||||
|
||||
// Storing manifests in IndexedDB, y'all
|
||||
let manifestCache = caches.open("manifests");
|
||||
|
||||
const db = openDB("manifests-store", undefined, {
|
||||
upgrade(db) {
|
||||
db.createObjectStore("manifests");
|
@ -1,4 +1,4 @@
|
||||
import { CommandDef } from "./plugins/types";
|
||||
import { CommandDef } from "../../plugbox/src/types";
|
||||
|
||||
export type PageMeta = {
|
||||
name: string;
|
||||
|
966
webapp/yarn.lock
966
webapp/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user