@pronto-tools-and-more/pronto 4.9.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/pronto",
3
- "version": "4.9.3",
3
+ "version": "5.0.1",
4
4
  "description": "",
5
5
  "main": "src/main.js",
6
6
  "type": "module",
@@ -13,14 +13,15 @@
13
13
  "author": "",
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@pronto-tools-and-more/file-watcher": "4.9.3",
17
- "@pronto-tools-and-more/files": "4.9.3",
18
- "@pronto-tools-and-more/network-process": "4.9.3",
19
- "@pronto-tools-and-more/sass-compiler": "4.9.3",
20
16
  "@lvce-editor/assert": "^1.2.0",
21
17
  "@lvce-editor/ipc": "^10.0.4",
22
18
  "@lvce-editor/json-rpc": "^3.0.0",
23
19
  "@lvce-editor/verror": "^1.4.0",
20
+ "@pronto-tools-and-more/file-watcher": "5.0.1",
21
+ "@pronto-tools-and-more/files": "5.0.1",
22
+ "@pronto-tools-and-more/network-process": "5.0.1",
23
+ "@pronto-tools-and-more/sass-compiler": "5.0.1",
24
+ "@pronto-tools-and-more/components-renderer": "5.0.1",
24
25
  "execa": "^9.3.1",
25
26
  "express": "^4.19.2"
26
27
  },
@@ -1,6 +1,5 @@
1
1
  import express from "express";
2
2
  import { join } from "node:path";
3
- import * as Config from "../Config/Config.js";
4
3
  import * as FilesPath from "../FilesPath/FilesPath.js";
5
4
  import * as HandleCss from "../HandleCss/HandleCss.js";
6
5
  import * as HandleIndex from "../HandleIndex/HandleIndex.js";
@@ -19,6 +18,9 @@ export const create = ({
19
18
  catalogApiBaseUrl,
20
19
  companyUrl,
21
20
  mode,
21
+ splitViews,
22
+ reactComponents,
23
+ managerWebUrl,
22
24
  }) => {
23
25
  const app = express();
24
26
  const storeFrontPath = join(root, "src", "default", "storefront");
@@ -51,7 +53,8 @@ export const create = ({
51
53
  "/assets/views.json",
52
54
  HandleViews.handleViews({
53
55
  storeFrontPath,
54
- splitViews: Config.splitViews,
56
+ splitViews,
57
+ reactComponents,
55
58
  })
56
59
  );
57
60
  app.use("*", HandleCss.handleCss(storeFrontPath));
@@ -70,7 +73,7 @@ export const create = ({
70
73
  "/resources/web",
71
74
  ProxyPath.create({
72
75
  prefix: "/resources/web",
73
- to: Config.managerWebUrl,
76
+ to: managerWebUrl,
74
77
  customIf: [
75
78
  {
76
79
  match: "purpleshared/custom.css",
@@ -0,0 +1,13 @@
1
+ import * as Path from "node:path";
2
+ import * as ResolveBin from "../ResolveBin/ResolveBin.js";
3
+ import * as Root from "../Root/Root.js";
4
+
5
+ export const componentsRendererPath =
6
+ ResolveBin.resolveBin("@pronto-tools-and-more/components-renderer") ||
7
+ Path.join(
8
+ Root.root,
9
+ "packages",
10
+ "pronto-components-renderer",
11
+ "src",
12
+ "componentsRendererMain.js"
13
+ );
@@ -96,3 +96,5 @@ export const catalogApiBaseUrl =
96
96
  export const companyUrl = config.companyUrl || "https://sprylab.com";
97
97
 
98
98
  export const splitViews = config.splitViews || false;
99
+
100
+ export const reactComponents = config.reactComponents || false;
@@ -21,6 +21,9 @@ export const createServer = async (root, errorColor) => {
21
21
  catalogApiBaseUrl: Config.catalogApiBaseUrl,
22
22
  companyUrl: Config.companyUrl,
23
23
  mode: Config.mode,
24
+ managerWebUrl: Config.managerWebUrl,
25
+ reactComponents: Config.reactComponents,
26
+ splitViews: Config.splitViews,
24
27
  });
25
28
  const server = http.createServer(app);
26
29
  const webSocketServer = new ws.WebSocketServer({
@@ -1,28 +1,22 @@
1
- import { readdir } from "node:fs/promises";
1
+ import { createReadStream } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { pipeline } from "node:stream/promises";
4
- import * as JsonFile from "../JsonFile/JsonFile.js";
5
- import { createReadStream } from "node:fs";
6
-
7
- const handleViewsSplit = async (storeFrontPath) => {
8
- const viewsFolderPath = join(storeFrontPath, "assets", "views");
9
- const dirents = await readdir(viewsFolderPath);
10
- const promises = [];
11
- for (const dirent of dirents) {
12
- const absolutePath = join(viewsFolderPath, dirent);
13
- const promise = JsonFile.readJson(absolutePath);
14
- promises.push(promise);
15
- }
16
- const contents = await Promise.all(promises);
17
- const stringified = JSON.stringify(contents, null, 2) + "\n";
18
- return stringified;
19
- };
4
+ import * as HandleViewsReactComponents from "../HandleViewsReactComponents/HandleViewsReactComponents.js";
5
+ import * as HandleViewsSplit from "../HandleViewsSplit/HandleViewsSplit.js";
20
6
 
21
7
  export const handleViews =
22
- ({ storeFrontPath, splitViews }) =>
8
+ ({ storeFrontPath, splitViews, reactComponents }) =>
23
9
  async (req, res) => {
10
+ if (reactComponents) {
11
+ const content =
12
+ await HandleViewsReactComponents.handleViewsReactComponents(
13
+ storeFrontPath
14
+ );
15
+ res.end(content);
16
+ return;
17
+ }
24
18
  if (splitViews) {
25
- const content = await handleViewsSplit(storeFrontPath);
19
+ const content = await HandleViewsSplit.handleViewsSplit(storeFrontPath);
26
20
  res.end(content);
27
21
  return;
28
22
  }
@@ -0,0 +1,41 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import * as ComponentsRendererPath from "../ComponentsRendererPath/ComponentsRendererPath.js";
4
+ import * as HandleIpc from "../HandleIpc/HandleIpc.js";
5
+ import * as IpcParent from "../IpcParent/IpcParent.js";
6
+ import * as IpcParentType from "../IpcParentType/IpcParentType.js";
7
+ import * as JsonRpc from "../JsonRpc/JsonRpc.js";
8
+
9
+ export const handleViewsReactComponents = async (storeFrontPath) => {
10
+ try {
11
+ const componentsPath = join(
12
+ storeFrontPath,
13
+ "..",
14
+ "..",
15
+ "components",
16
+ "src",
17
+ "main.ts"
18
+ );
19
+ if (!existsSync(componentsPath)) {
20
+ throw new Error(`components path not found: ${componentsPath}`);
21
+ }
22
+ const ipc = await IpcParent.create({
23
+ path: ComponentsRendererPath.componentsRendererPath,
24
+ method: IpcParentType.NodeForkedProcess, // TODO worker could be faster
25
+ execArgv: [],
26
+ });
27
+ HandleIpc.handleIpc(ipc);
28
+ const result = await JsonRpc.invoke(
29
+ ipc,
30
+ "RenderViews.renderViews",
31
+ componentsPath
32
+ );
33
+ return JSON.stringify(result);
34
+ } catch (error) {
35
+ console.log(error);
36
+ console.error(`[pronto] views json error: ${error}`);
37
+ return JSON.stringify({
38
+ error,
39
+ });
40
+ }
41
+ };
@@ -0,0 +1,17 @@
1
+ import { readdir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import * as JsonFile from "../JsonFile/JsonFile.js";
4
+
5
+ export const handleViewsSplit = async (storeFrontPath) => {
6
+ const viewsFolderPath = join(storeFrontPath, "assets", "views");
7
+ const dirents = await readdir(viewsFolderPath);
8
+ const promises = [];
9
+ for (const dirent of dirents) {
10
+ const absolutePath = join(viewsFolderPath, dirent);
11
+ const promise = JsonFile.readJson(absolutePath);
12
+ promises.push(promise);
13
+ }
14
+ const contents = await Promise.all(promises);
15
+ const stringified = JSON.stringify(contents, null, 2) + "\n";
16
+ return stringified;
17
+ };