@pronto-tools-and-more/components-renderer 5.0.1 → 5.0.2
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 +5 -3
- package/src/parts/CreateElement/CreateElement.js +22 -0
- package/src/parts/CreateViews/CreateViews.js +19 -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 +4 -0
- package/src/parts/RenderViews/RenderViews.js +10 -16
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.0.2",
|
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,22 @@
|
|
1
|
+
import * as IsHtml from "../IsHtml/IsHtml.js";
|
2
|
+
|
3
|
+
export const createElement = (tag, props, children) => {
|
4
|
+
if (IsHtml.isHtml(tag)) {
|
5
|
+
return {
|
6
|
+
type: "section",
|
7
|
+
content: [
|
8
|
+
{
|
9
|
+
type: "html",
|
10
|
+
tag: "div",
|
11
|
+
content: "abc",
|
12
|
+
},
|
13
|
+
],
|
14
|
+
};
|
15
|
+
}
|
16
|
+
return {
|
17
|
+
type: "section",
|
18
|
+
tag,
|
19
|
+
props,
|
20
|
+
children,
|
21
|
+
};
|
22
|
+
};
|
@@ -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`);
|
@@ -1,22 +1,16 @@
|
|
1
|
+
import * as Assert from "../Assert/Assert.js";
|
2
|
+
import * as CreateViews from "../CreateViews/CreateViews.js";
|
1
3
|
import * as LoadRoutes from "../LoadRoutes/LoadRoutes.js";
|
2
4
|
import * as LoadSwc from "../LoadSwc/LoadSwc.js";
|
3
5
|
import * as SwcNodePath from "../SwcNodePath/SwcNodePath.js";
|
4
6
|
|
5
|
-
export const renderViews = async (componentsPathMain) => {
|
6
|
-
|
7
|
+
export const renderViews = async (componentsPathMain, tsconfigPath) => {
|
8
|
+
Assert.string(componentsPathMain);
|
9
|
+
Assert.string(tsconfigPath);
|
10
|
+
await LoadSwc.loadSwc(SwcNodePath.swcNodePath, tsconfigPath);
|
7
11
|
const module = await LoadRoutes.loadRoutes(componentsPathMain);
|
8
|
-
|
9
|
-
// TODO
|
10
|
-
|
11
|
-
|
12
|
-
// 3. render views to json
|
13
|
-
// 4. render json to views.json
|
14
|
-
return [
|
15
|
-
{
|
16
|
-
path: "/test",
|
17
|
-
name: "test",
|
18
|
-
},
|
19
|
-
];
|
12
|
+
const values = Object.values(module);
|
13
|
+
// TODO return views string instead of json for faster performance?
|
14
|
+
const views = CreateViews.createViews(values);
|
15
|
+
return views;
|
20
16
|
};
|
21
|
-
|
22
|
-
renderViews("/home/simon/.cache/repos/elternsein/src/components/src/main.ts");
|