@pronto-tools-and-more/components-renderer 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +24 -0
- package/src/componentsRendererMain.js +3 -0
- package/src/parts/Assert/Assert.js +1 -0
- package/src/parts/Callback/Callback.js +1 -0
- package/src/parts/Command/Command.js +9 -0
- package/src/parts/CommandMap/CommandMap.js +5 -0
- package/src/parts/CommandState/CommandState.js +17 -0
- package/src/parts/HandleIpc/HandleIpc.js +10 -0
- package/src/parts/HandleMessage/HandleMessage.js +27 -0
- package/src/parts/IpcChild/IpcChild.js +15 -0
- package/src/parts/IpcChildModule/IpcChildModule.js +25 -0
- package/src/parts/IpcChildType/IpcChildType.js +20 -0
- package/src/parts/IpcId/IpcId.js +9 -0
- package/src/parts/JsonRpc/JsonRpc.js +1 -0
- package/src/parts/Listen/Listen.js +8 -0
- package/src/parts/LoadRoutes/LoadRoutes.js +10 -0
- package/src/parts/LoadSwc/LoadSwc.js +9 -0
- package/src/parts/Main/Main.js +8 -0
- package/src/parts/RenderViews/RenderViews.js +22 -0
- package/src/parts/ResolveBin/ResolveBin.js +11 -0
- package/src/parts/Root/Root.js +6 -0
- package/src/parts/SwcNodePath/SwcNodePath.js +16 -0
package/package.json
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"name": "@pronto-tools-and-more/components-renderer",
|
3
|
+
"version": "5.0.1",
|
4
|
+
"description": "",
|
5
|
+
"main": "src/componentsRendererMain.js",
|
6
|
+
"type": "module",
|
7
|
+
"scripts": {
|
8
|
+
"test": "echo ok",
|
9
|
+
"type-check": "tsc"
|
10
|
+
},
|
11
|
+
"keywords": [],
|
12
|
+
"author": "",
|
13
|
+
"license": "MIT",
|
14
|
+
"dependencies": {
|
15
|
+
"@lvce-editor/assert": "^1.2.0",
|
16
|
+
"@lvce-editor/ipc": "^10.0.4",
|
17
|
+
"@lvce-editor/json-rpc": "^3.0.0",
|
18
|
+
"@lvce-editor/verror": "^1.4.0",
|
19
|
+
"@swc-node/register": "^1.10.9"
|
20
|
+
},
|
21
|
+
"devDependencies": {
|
22
|
+
"@types/node": "^22.5.0"
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "@lvce-editor/assert";
|
@@ -0,0 +1 @@
|
|
1
|
+
export { resolve } from "@lvce-editor/json-rpc";
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export const state = {
|
2
|
+
commands: Object.create(null),
|
3
|
+
};
|
4
|
+
|
5
|
+
export const registerCommand = (key, fn) => {
|
6
|
+
state.commands[key] = fn;
|
7
|
+
};
|
8
|
+
|
9
|
+
export const registerCommands = (commandMap) => {
|
10
|
+
for (const [key, value] of Object.entries(commandMap)) {
|
11
|
+
registerCommand(key, value);
|
12
|
+
}
|
13
|
+
};
|
14
|
+
|
15
|
+
export const getCommand = (key) => {
|
16
|
+
return state.commands[key];
|
17
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import * as HandleMessage from "../HandleMessage/HandleMessage.js";
|
2
|
+
|
3
|
+
export const handleIpc = (ipc) => {
|
4
|
+
if ("addEventListener" in ipc) {
|
5
|
+
ipc.addEventListener("message", HandleMessage.handleMessage);
|
6
|
+
} else if ("on" in ipc) {
|
7
|
+
// deprecated
|
8
|
+
ipc.on("message", HandleMessage.handleMessage);
|
9
|
+
}
|
10
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import * as Callback from "../Callback/Callback.js";
|
2
|
+
import * as Command from "../Command/Command.js";
|
3
|
+
import * as JsonRpc from "../JsonRpc/JsonRpc.js";
|
4
|
+
|
5
|
+
const prepare = (error) => {
|
6
|
+
return error;
|
7
|
+
};
|
8
|
+
|
9
|
+
const requiresSocket = (method) => {
|
10
|
+
return false;
|
11
|
+
};
|
12
|
+
|
13
|
+
const logError = (error, prettyError) => {
|
14
|
+
console.error(error);
|
15
|
+
};
|
16
|
+
|
17
|
+
export const handleMessage = (event) => {
|
18
|
+
return JsonRpc.handleJsonRpcMessage(
|
19
|
+
event.target,
|
20
|
+
event.data,
|
21
|
+
Command.execute,
|
22
|
+
Callback.resolve,
|
23
|
+
prepare,
|
24
|
+
logError,
|
25
|
+
requiresSocket
|
26
|
+
);
|
27
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import * as IpcChildModule from "../IpcChildModule/IpcChildModule.js";
|
2
|
+
|
3
|
+
export const listen = async ({ method, ...params }) => {
|
4
|
+
const module = await IpcChildModule.getModule(method);
|
5
|
+
// @ts-ignore
|
6
|
+
const rawIpc = await module.listen(params);
|
7
|
+
// @ts-ignore
|
8
|
+
if (module.signal) {
|
9
|
+
// @ts-ignore
|
10
|
+
module.signal(rawIpc);
|
11
|
+
}
|
12
|
+
// @ts-ignore
|
13
|
+
const ipc = module.wrap(rawIpc);
|
14
|
+
return ipc;
|
15
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import {
|
2
|
+
IpcChildWithElectronMessagePort,
|
3
|
+
IpcChildWithElectronUtilityProcess,
|
4
|
+
IpcChildWithNodeForkedProcess,
|
5
|
+
IpcChildWithNodeWorker,
|
6
|
+
IpcChildWithWebSocket,
|
7
|
+
} from "@lvce-editor/ipc";
|
8
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
9
|
+
|
10
|
+
export const getModule = (method) => {
|
11
|
+
switch (method) {
|
12
|
+
case IpcChildType.NodeForkedProcess:
|
13
|
+
return IpcChildWithNodeForkedProcess;
|
14
|
+
case IpcChildType.NodeWorker:
|
15
|
+
return IpcChildWithNodeWorker;
|
16
|
+
case IpcChildType.ElectronUtilityProcess:
|
17
|
+
return IpcChildWithElectronUtilityProcess;
|
18
|
+
case IpcChildType.ElectronMessagePort:
|
19
|
+
return IpcChildWithElectronMessagePort;
|
20
|
+
case IpcChildType.WebSocket:
|
21
|
+
return IpcChildWithWebSocket;
|
22
|
+
default:
|
23
|
+
throw new Error("unexpected ipc type");
|
24
|
+
}
|
25
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export const NodeWorker = 1;
|
2
|
+
export const NodeForkedProcess = 2;
|
3
|
+
export const ElectronUtilityProcess = 3;
|
4
|
+
export const ElectronMessagePort = 4;
|
5
|
+
export const NodeMessagePort = 5;
|
6
|
+
export const WebSocket = 6;
|
7
|
+
|
8
|
+
export const Auto = () => {
|
9
|
+
const { argv } = process;
|
10
|
+
if (argv.includes("--ipc-type=node-worker")) {
|
11
|
+
return NodeWorker;
|
12
|
+
}
|
13
|
+
if (argv.includes("--ipc-type=node-forked-process")) {
|
14
|
+
return NodeForkedProcess;
|
15
|
+
}
|
16
|
+
if (argv.includes("--ipc-type=electron-utility-process")) {
|
17
|
+
return ElectronUtilityProcess;
|
18
|
+
}
|
19
|
+
throw new Error(`[shared-process] unknown ipc type`);
|
20
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export const EmbedsProcess = 2;
|
2
|
+
export const EmbedsWorker = 77;
|
3
|
+
export const ExtensionHostHelperProcess = 3;
|
4
|
+
export const MainProcess = -5;
|
5
|
+
export const ProcessExplorer = 11;
|
6
|
+
export const SearchProcess = 13;
|
7
|
+
export const SharedProcess = 1;
|
8
|
+
export const TerminalProcess = 7;
|
9
|
+
export const Unknown = 0;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "@lvce-editor/json-rpc";
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as HandleIpc from "../HandleIpc/HandleIpc.js";
|
2
|
+
import * as IpcChild from "../IpcChild/IpcChild.js";
|
3
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
4
|
+
|
5
|
+
export const listen = async () => {
|
6
|
+
const ipc = await IpcChild.listen({ method: IpcChildType.Auto() });
|
7
|
+
HandleIpc.handleIpc(ipc);
|
8
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { VError } from "@lvce-editor/verror";
|
2
|
+
|
3
|
+
export const loadRoutes = async (componentsPathMain) => {
|
4
|
+
try {
|
5
|
+
const module = await import(componentsPathMain);
|
6
|
+
return module;
|
7
|
+
} catch (error) {
|
8
|
+
throw new VError(error, `Failed to load routes`);
|
9
|
+
}
|
10
|
+
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as CommandMap from "../CommandMap/CommandMap.js";
|
2
|
+
import * as CommandState from "../CommandState/CommandState.js";
|
3
|
+
import * as Listen from "../Listen/Listen.js";
|
4
|
+
|
5
|
+
export const main = async () => {
|
6
|
+
CommandState.registerCommands(CommandMap.commandMap);
|
7
|
+
await Listen.listen();
|
8
|
+
};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import * as LoadRoutes from "../LoadRoutes/LoadRoutes.js";
|
2
|
+
import * as LoadSwc from "../LoadSwc/LoadSwc.js";
|
3
|
+
import * as SwcNodePath from "../SwcNodePath/SwcNodePath.js";
|
4
|
+
|
5
|
+
export const renderViews = async (componentsPathMain) => {
|
6
|
+
await LoadSwc.loadSwc(SwcNodePath.swcNodePath);
|
7
|
+
const module = await LoadRoutes.loadRoutes(componentsPathMain);
|
8
|
+
console.log(module);
|
9
|
+
// TODO
|
10
|
+
// 1. enable swc loader
|
11
|
+
// 2. load components url
|
12
|
+
// 3. render views to json
|
13
|
+
// 4. render json to views.json
|
14
|
+
return [
|
15
|
+
{
|
16
|
+
path: "/test",
|
17
|
+
name: "test",
|
18
|
+
},
|
19
|
+
];
|
20
|
+
};
|
21
|
+
|
22
|
+
renderViews("/home/simon/.cache/repos/elternsein/src/components/src/main.ts");
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import * as Path from "node:path";
|
2
|
+
import * as Root from "../Root/Root.js";
|
3
|
+
import * as ResolveBin from "../ResolveBin/ResolveBin.js";
|
4
|
+
|
5
|
+
export const swcNodePath =
|
6
|
+
ResolveBin.resolveBin("@swc-node/register/esm-register") ||
|
7
|
+
Path.join(
|
8
|
+
Root.root,
|
9
|
+
"packages",
|
10
|
+
"pronto-components-renderer",
|
11
|
+
"node_modules",
|
12
|
+
"@swc-node",
|
13
|
+
"register",
|
14
|
+
"esm",
|
15
|
+
"esm-register.mjs"
|
16
|
+
);
|