@pronto-tools-and-more/components-renderer 5.0.1 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +5 -3
- package/src/parts/CreateElement/CreateElement.js +7 -0
- package/src/parts/CreateFakeSection/CreateFakeSection.js +8 -0
- package/src/parts/CreateViews/CreateViews.js +19 -0
- package/src/parts/FakeNode/FakeNode.js +6 -0
- package/src/parts/HasComplexChildren/HasComplexChildren.js +7 -0
- package/src/parts/IsHtml/IsHtml.js +5 -0
- package/src/parts/LoadSwc/LoadSwc.js +6 -1
- package/src/parts/React/React.js +5 -0
- package/src/parts/RenderElement/RenderElement.js +28 -0
- package/src/parts/RenderView/RenderView.js +9 -0
- package/src/parts/RenderViews/RenderViews.js +63 -12
package/package.json
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pronto-tools-and-more/components-renderer",
|
3
|
-
"version": "5.0
|
3
|
+
"version": "5.1.0",
|
4
4
|
"description": "",
|
5
5
|
"main": "src/componentsRendererMain.js",
|
6
6
|
"type": "module",
|
7
7
|
"scripts": {
|
8
|
-
"test": "
|
8
|
+
"test": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit",
|
9
|
+
"test:watch": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch",
|
9
10
|
"type-check": "tsc"
|
10
11
|
},
|
11
12
|
"keywords": [],
|
@@ -19,6 +20,7 @@
|
|
19
20
|
"@swc-node/register": "^1.10.9"
|
20
21
|
},
|
21
22
|
"devDependencies": {
|
22
|
-
"@types/node": "^22.5.0"
|
23
|
+
"@types/node": "^22.5.0",
|
24
|
+
"jest": "^29.7.0"
|
23
25
|
}
|
24
26
|
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { VError } from "@lvce-editor/verror";
|
2
|
+
import * as React from "../React/React.js";
|
3
|
+
|
4
|
+
const createView = (value) => {
|
5
|
+
try {
|
6
|
+
return {
|
7
|
+
path: value.path,
|
8
|
+
name: value.name,
|
9
|
+
content: [value.component()],
|
10
|
+
};
|
11
|
+
} catch (error) {
|
12
|
+
throw new VError(error, `Failed to create view`);
|
13
|
+
}
|
14
|
+
};
|
15
|
+
|
16
|
+
export const createViews = (values) => {
|
17
|
+
globalThis.React = React.React;
|
18
|
+
return values.map(createView);
|
19
|
+
};
|
@@ -1,7 +1,12 @@
|
|
1
1
|
import { VError } from "@lvce-editor/verror";
|
2
|
+
import * as Assert from "../Assert/Assert.js";
|
2
3
|
|
3
|
-
export const loadSwc = async (swcNodePath) => {
|
4
|
+
export const loadSwc = async (swcNodePath, tsconfigPath) => {
|
4
5
|
try {
|
6
|
+
Assert.string(swcNodePath);
|
7
|
+
Assert.string(tsconfigPath);
|
8
|
+
// @ts-ignore
|
9
|
+
process.env.TS_NODE_PROJECT = tsconfigPath;
|
5
10
|
await import(swcNodePath);
|
6
11
|
} catch (error) {
|
7
12
|
throw new VError(error, `Failed to load swc`);
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import * as CreateFakeSection from "../CreateFakeSection/CreateFakeSection.js";
|
2
|
+
import * as HasComplexChildren from "../HasComplexChildren/HasComplexChildren.js";
|
3
|
+
|
4
|
+
export const renderElement = (element) => {
|
5
|
+
if (typeof element === "string") {
|
6
|
+
return {
|
7
|
+
type: "html",
|
8
|
+
tag: "div",
|
9
|
+
content: element,
|
10
|
+
};
|
11
|
+
}
|
12
|
+
if (element.tag) {
|
13
|
+
const hasComplexChildren = HasComplexChildren.hasComplexChildren(element);
|
14
|
+
const renderedChildren = hasComplexChildren
|
15
|
+
? element.children.map(renderElement)
|
16
|
+
: [];
|
17
|
+
const content = hasComplexChildren ? "" : element.children[0] || "";
|
18
|
+
return CreateFakeSection.createFakeSection([
|
19
|
+
{
|
20
|
+
type: "html",
|
21
|
+
tag: element.tag,
|
22
|
+
content,
|
23
|
+
},
|
24
|
+
...renderedChildren,
|
25
|
+
]);
|
26
|
+
}
|
27
|
+
return {};
|
28
|
+
};
|
@@ -1,22 +1,73 @@
|
|
1
|
+
import * as Assert from "../Assert/Assert.js";
|
2
|
+
import * as CreateViews from "../CreateViews/CreateViews.js";
|
3
|
+
import * as FakeNode from "../FakeNode/FakeNode.js";
|
1
4
|
import * as LoadRoutes from "../LoadRoutes/LoadRoutes.js";
|
2
5
|
import * as LoadSwc from "../LoadSwc/LoadSwc.js";
|
6
|
+
import * as RenderView from "../RenderView/RenderView.js";
|
3
7
|
import * as SwcNodePath from "../SwcNodePath/SwcNodePath.js";
|
4
8
|
|
5
|
-
export const renderViews = async (componentsPathMain) => {
|
6
|
-
|
9
|
+
export const renderViews = async (componentsPathMain, tsconfigPath) => {
|
10
|
+
Assert.string(componentsPathMain);
|
11
|
+
Assert.string(tsconfigPath);
|
12
|
+
await LoadSwc.loadSwc(SwcNodePath.swcNodePath, tsconfigPath);
|
7
13
|
const module = await LoadRoutes.loadRoutes(componentsPathMain);
|
8
|
-
|
9
|
-
// TODO
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
//
|
14
|
-
|
14
|
+
const values = Object.values(module);
|
15
|
+
// TODO return views string instead of json for faster performance?
|
16
|
+
const views = CreateViews.createViews(values);
|
17
|
+
const rendered = views.map(RenderView.renderView);
|
18
|
+
console.log(JSON.stringify(views, null, 2));
|
19
|
+
// console.log(JSON.stringify(rendered, null, 2));
|
20
|
+
if (Math) {
|
21
|
+
return rendered;
|
22
|
+
}
|
23
|
+
const newViews = [
|
15
24
|
{
|
16
|
-
|
25
|
+
content: [
|
26
|
+
{
|
27
|
+
type: "section",
|
28
|
+
content: [
|
29
|
+
FakeNode.fakeNode,
|
30
|
+
{
|
31
|
+
type: "html",
|
32
|
+
tag: "div",
|
33
|
+
className: "outer",
|
34
|
+
content: "",
|
35
|
+
},
|
36
|
+
{
|
37
|
+
type: "html",
|
38
|
+
tag: "div",
|
39
|
+
className: "inner",
|
40
|
+
content: "child",
|
41
|
+
},
|
42
|
+
// {
|
43
|
+
// type: "section",
|
44
|
+
// content: [
|
45
|
+
// FakeNode.fakeNode,
|
46
|
+
// {
|
47
|
+
// type: "html",
|
48
|
+
// tag: "p",
|
49
|
+
// content: "inner",
|
50
|
+
// },
|
51
|
+
// ],
|
52
|
+
// },
|
53
|
+
],
|
54
|
+
},
|
55
|
+
// {
|
56
|
+
// type: "section",
|
57
|
+
// content: [
|
58
|
+
// FakeNode.fakeNode,
|
59
|
+
// {
|
60
|
+
// type: "html",
|
61
|
+
// tag: "div",
|
62
|
+
// content: "23",
|
63
|
+
// },
|
64
|
+
// ],
|
65
|
+
// },
|
66
|
+
],
|
17
67
|
name: "test",
|
68
|
+
path: "test",
|
69
|
+
appBar: "login",
|
18
70
|
},
|
19
71
|
];
|
72
|
+
return newViews;
|
20
73
|
};
|
21
|
-
|
22
|
-
renderViews("/home/simon/.cache/repos/elternsein/src/components/src/main.ts");
|