@pronto-tools-and-more/pronto 10.12.0 → 10.13.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/pronto",
3
- "version": "10.12.0",
3
+ "version": "10.13.0",
4
4
  "description": "",
5
5
  "main": "src/main.js",
6
6
  "type": "module",
@@ -17,15 +17,16 @@
17
17
  "@lvce-editor/ipc": "^11.3.0",
18
18
  "@lvce-editor/json-rpc": "^5.2.0",
19
19
  "@lvce-editor/verror": "^1.6.0",
20
- "@pronto-tools-and-more/file-watcher": "10.12.0",
21
- "@pronto-tools-and-more/files": "10.12.0",
22
- "@pronto-tools-and-more/network-process": "10.12.0",
23
- "@pronto-tools-and-more/sass-compiler": "10.12.0",
24
- "@pronto-tools-and-more/components-renderer": "10.12.0",
25
- "@pronto-tools-and-more/components": "10.12.0",
26
- "@pronto-tools-and-more/schema-process": "10.12.0",
27
- "@pronto-tools-and-more/diff-process": "10.12.0",
28
- "@pronto-tools-and-more/type-checker": "10.12.0",
20
+ "@pronto-tools-and-more/file-watcher": "10.13.0",
21
+ "@pronto-tools-and-more/files": "10.13.0",
22
+ "@pronto-tools-and-more/network-process": "10.13.0",
23
+ "@pronto-tools-and-more/sass-compiler": "10.13.0",
24
+ "@pronto-tools-and-more/components-renderer": "10.13.0",
25
+ "@pronto-tools-and-more/components": "10.13.0",
26
+ "@pronto-tools-and-more/schema-process": "10.13.0",
27
+ "@pronto-tools-and-more/diff-process": "10.13.0",
28
+ "@pronto-tools-and-more/type-checker": "10.13.0",
29
+ "@pronto-tools-and-more/custom-js-functions": "10.13.0",
29
30
  "execa": "^9.5.1",
30
31
  "express": "^4.21.1"
31
32
  },
@@ -6,6 +6,7 @@ import * as HandleFeaturesJson from "../HandleFeaturesJson/HandleFeaturesJson.js
6
6
  import * as HandleIndex from "../HandleIndex/HandleIndex.js";
7
7
  import * as HandleMainJs from "../HandleMainJs/HandleMainJs.js";
8
8
  import * as HandleViews from "../HandleViews/HandleViews.js";
9
+ import * as HandleCustomServer from "../HandleCustomServer/HandleCustomServer.js";
9
10
  import * as ProxyPath from "../ProxyPath/ProxyPath.js";
10
11
 
11
12
  export const create = ({
@@ -23,6 +24,7 @@ export const create = ({
23
24
  reactComponents,
24
25
  managerWebUrl,
25
26
  resourceDynamicUrlsInViewsJson,
27
+ injectCustomJs,
26
28
  }) => {
27
29
  const app = express();
28
30
  const storeFrontPath = join(root, "src", "default", "storefront");
@@ -69,6 +71,14 @@ export const create = ({
69
71
  filesPath: FilesPath.filesPath,
70
72
  })
71
73
  );
74
+ app.get(
75
+ "/assets/scripts/custom.server.js",
76
+ HandleCustomServer.handleCustomServerJs({
77
+ storeFrontPath,
78
+ filesPath: FilesPath.filesPath,
79
+ injectCustomJs,
80
+ })
81
+ );
72
82
  app.use("*", HandleCss.handleCss(storeFrontPath));
73
83
  app.use(express.static(FilesPath.filesPath));
74
84
  if (mode === "slim") {
@@ -113,3 +113,5 @@ export const hotReload = config.hotReload || false;
113
113
 
114
114
  export const resourceDynamicUrlsInViewsJson =
115
115
  config.resourceDynamicUrlsInViewsJson || false;
116
+
117
+ export const injectCustomJs = config.injectCustomJs || false;
@@ -25,6 +25,7 @@ export const createServer = async (root, errorColor) => {
25
25
  reactComponents: Config.reactComponents,
26
26
  splitViews: Config.splitViews,
27
27
  resourceDynamicUrlsInViewsJson: Config.resourceDynamicUrlsInViewsJson,
28
+ injectCustomJs: Config.injectCustomJs,
28
29
  });
29
30
  const server = http.createServer(app);
30
31
  const webSocketServer = new ws.WebSocketServer({
@@ -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 customJsFunctionsPath =
6
+ ResolveBin.resolveBin("@pronto-tools-and-more/custom-js-functions") ||
7
+ Path.join(
8
+ Root.root,
9
+ "packages",
10
+ "pronto-custom-js-functions",
11
+ "dist",
12
+ "main.js"
13
+ );
@@ -0,0 +1,38 @@
1
+ import { createReadStream, existsSync } from "fs";
2
+ import { readFile } from "fs/promises";
3
+ import { join } from "path";
4
+ import { pipeline } from "stream/promises";
5
+ import * as CustomJsFunctionsPath from "../CustomJsFunctionsPath/CustomJsFunctionsPath.js";
6
+
7
+ const getCustomServerJsContent = async ({ customServerJsPath }) => {
8
+ const baseContent = await readFile(customServerJsPath, "utf8");
9
+ const injectedContent = await readFile(
10
+ CustomJsFunctionsPath.customJsFunctionsPath,
11
+ "utf8"
12
+ );
13
+ const merged =
14
+ baseContent + `\n\n\n// pronto injected code\n\n\n` + injectedContent;
15
+ return merged;
16
+ };
17
+
18
+ export const handleCustomServerJs =
19
+ ({ storeFrontPath, filesPath, injectCustomJs }) =>
20
+ async (req, res) => {
21
+ try {
22
+ const customServerJsPath = join(
23
+ storeFrontPath,
24
+ "assets",
25
+ "scripts",
26
+ "custom.server.js"
27
+ );
28
+ if (injectCustomJs) {
29
+ const content = await getCustomServerJsContent({ customServerJsPath });
30
+ res.end(content);
31
+ } else {
32
+ await pipeline(createReadStream(customServerJsPath), res);
33
+ }
34
+ } catch (error) {
35
+ console.error(`[server] ${error}`);
36
+ res.status(500).end("internal server error when generating server js");
37
+ }
38
+ };
@@ -1 +1 @@
1
- export const version = '10.12.0'
1
+ export const version = '10.13.0'