@pronto-tools-and-more/pronto 12.28.0 → 12.29.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": "12.28.0",
3
+ "version": "12.29.0",
4
4
  "description": "",
5
5
  "main": "src/main.js",
6
6
  "type": "module",
@@ -17,16 +17,16 @@
17
17
  "@lvce-editor/ipc": "^13.7.0",
18
18
  "@lvce-editor/json-rpc": "^5.4.0",
19
19
  "@lvce-editor/verror": "^1.6.0",
20
- "@pronto-tools-and-more/file-watcher": "12.28.0",
21
- "@pronto-tools-and-more/files": "12.28.0",
22
- "@pronto-tools-and-more/network-process": "12.28.0",
23
- "@pronto-tools-and-more/sass-compiler": "12.28.0",
24
- "@pronto-tools-and-more/components-renderer": "12.28.0",
25
- "@pronto-tools-and-more/components": "12.28.0",
26
- "@pronto-tools-and-more/schema-process": "12.28.0",
27
- "@pronto-tools-and-more/diff-process": "12.28.0",
28
- "@pronto-tools-and-more/type-checker": "12.28.0",
29
- "@pronto-tools-and-more/custom-js-functions": "12.28.0",
20
+ "@pronto-tools-and-more/file-watcher": "12.29.0",
21
+ "@pronto-tools-and-more/files": "12.29.0",
22
+ "@pronto-tools-and-more/network-process": "12.29.0",
23
+ "@pronto-tools-and-more/sass-compiler": "12.29.0",
24
+ "@pronto-tools-and-more/components-renderer": "12.29.0",
25
+ "@pronto-tools-and-more/components": "12.29.0",
26
+ "@pronto-tools-and-more/schema-process": "12.29.0",
27
+ "@pronto-tools-and-more/diff-process": "12.29.0",
28
+ "@pronto-tools-and-more/type-checker": "12.29.0",
29
+ "@pronto-tools-and-more/custom-js-functions": "12.29.0",
30
30
  "execa": "^9.5.2",
31
31
  "express": "^4.21.2"
32
32
  },
@@ -2,6 +2,7 @@ import express from "express";
2
2
  import { join } from "node:path";
3
3
  import * as FilesPath from "../FilesPath/FilesPath.js";
4
4
  import * as HandleApi from "../HandleApi/HandleApi.js";
5
+ import * as HandleCommonJs from "../HandleCommonJs/HandleCommonJs.js";
5
6
  import * as HandleConfigLoader from "../HandleConfigLoader/HandleConfigLoader.js";
6
7
  import * as HandleCss from "../HandleCss/HandleCss.js";
7
8
  import * as HandleCustomServer from "../HandleCustomServer/HandleCustomServer.js";
@@ -31,6 +32,7 @@ export const create = ({
31
32
  injectCustomJs,
32
33
  shimConfigLoader,
33
34
  apiUrl,
35
+ supportNormalHtmlElements,
34
36
  }) => {
35
37
  const app = express();
36
38
  const storeFrontPath = join(root, "src", "default", "storefront");
@@ -68,6 +70,17 @@ export const create = ({
68
70
  mode,
69
71
  })
70
72
  );
73
+ if (supportNormalHtmlElements) {
74
+ app.get(
75
+ "/modules/common.js",
76
+ HandleCommonJs.handleCommonJs({
77
+ storeFrontPath,
78
+ filesPath: FilesPath.filesPath,
79
+ mode,
80
+ })
81
+ );
82
+ }
83
+
71
84
  app.get(
72
85
  "/assets/views.json",
73
86
  HandleViews.handleViews({
@@ -118,5 +118,8 @@ export const injectCustomJs = config.injectCustomJs || false;
118
118
 
119
119
  export const shimConfigLoader = config.shimConfigLoader || false;
120
120
 
121
+ export const supportNormalHtmlElements =
122
+ config.supportNormalHtmlElements || false;
123
+
121
124
  export const apiUrl =
122
125
  process.env.API_URL || "https://catalog.purplemanager.com/graphql";
@@ -30,6 +30,7 @@ export const createServer = async (root, errorColor) => {
30
30
  shimConfigLoader: Config.shimConfigLoader,
31
31
  releaseAppId: Config.releaseAppId,
32
32
  apiUrl: Config.apiUrl,
33
+ supportNormalHtmlElements: Config.supportNormalHtmlElements,
33
34
  });
34
35
  const server = http.createServer(app);
35
36
  const webSocketServer = new ws.WebSocketServer({
@@ -0,0 +1,8 @@
1
+ import { join } from "node:path";
2
+
3
+ export const getBasePath = (mode, storeFrontPath, filesPath) => {
4
+ if (mode === "slim") {
5
+ return join(filesPath, "framework", "src", "default", "storefront");
6
+ }
7
+ return storeFrontPath;
8
+ };
@@ -0,0 +1,13 @@
1
+ import { join } from "path";
2
+ import * as FilesPath from "../FilesPath/FilesPath.js";
3
+ import { readFile } from "fs/promises";
4
+
5
+ export const getCommonJsSnippet = async () => {
6
+ const snippetPath = join(
7
+ FilesPath.filesPath,
8
+ "assets",
9
+ "hack-normal-html-elements.js"
10
+ );
11
+ const snippetContent = await readFile(snippetPath, "utf8");
12
+ return snippetContent;
13
+ };
@@ -0,0 +1,115 @@
1
+ import * as ReplaceNeedle from "../ReplaceNeedle/ReplaceNeedle.js";
2
+
3
+ const RE_THIS = /(\w+)(\s*)=(\s*)(this)/;
4
+
5
+ // monkeypatch common.js to support normal html elements
6
+ export const getNewCommonJsContent = ({ content, normalHtmlSnippet }) => {
7
+ const needle0 = '"use strict"';
8
+ const needle1 = `tag:"div"`;
9
+ const needle2 = `tag: "div"`;
10
+ const needle3 = "ngOnInit(){";
11
+ const needle4 = "ngOnInit() {";
12
+ const needle5 = "onConfigChanges(){";
13
+ const needle6 = "onConfigChanges() {";
14
+ const needle7 = "=this";
15
+ const needle8 = "= this";
16
+ const needle9 = "changeDetectorRef.markForCheck()";
17
+
18
+ let newContent = content;
19
+
20
+ const indexStrict = newContent.indexOf(needle0);
21
+
22
+ if (indexStrict === -1) {
23
+ throw new Error("needle not found");
24
+ }
25
+
26
+ const occurrence0 = '"use strict"';
27
+ const replacement0 = normalHtmlSnippet;
28
+ newContent = ReplaceNeedle.replaceNeedle(
29
+ newContent,
30
+ indexStrict,
31
+ occurrence0,
32
+ replacement0
33
+ );
34
+
35
+ const needles = [needle1, needle2];
36
+ let index = -1;
37
+ for (const needle of needles) {
38
+ index = newContent.indexOf(needle);
39
+ if (index !== -1) {
40
+ index += needle.length;
41
+ break;
42
+ }
43
+ }
44
+ if (index === -1) {
45
+ throw new Error("no needle found (1)");
46
+ }
47
+
48
+ let initIndex = newContent.indexOf(needle3, index);
49
+ if (initIndex === -1) {
50
+ initIndex = newContent.indexOf(needle4, index);
51
+ }
52
+ if (initIndex === -1) {
53
+ throw new Error("no needle found (2)");
54
+ }
55
+ let this1Index = newContent.indexOf(needle7, initIndex);
56
+ if (this1Index === -1) {
57
+ this1Index = newContent.indexOf(needle8, initIndex);
58
+ }
59
+
60
+ if (this1Index === -1) {
61
+ throw new Error("no needle found (3)");
62
+ }
63
+
64
+ const occurence1 = "this";
65
+ const replacement1 = `this;globalThis.HACK__NORMAL_HTML_ELEMENTS_CHECK(this);`;
66
+
67
+ newContent = ReplaceNeedle.replaceNeedle(
68
+ newContent,
69
+ this1Index,
70
+ occurence1,
71
+ replacement1
72
+ );
73
+ let configIndex = newContent.indexOf(needle5, this1Index);
74
+ if (configIndex === -1) {
75
+ configIndex = newContent.indexOf(needle6, this1Index);
76
+ }
77
+ if (configIndex === -1) {
78
+ throw new Error("no needle found (4)");
79
+ }
80
+ let this2Index = newContent.indexOf(needle7, configIndex);
81
+ if (this2Index === -1) {
82
+ this2Index = newContent.indexOf(needle8, configIndex);
83
+ }
84
+ if (this2Index === -1) {
85
+ throw new Error("no needle found (5)");
86
+ }
87
+ const match = newContent.slice(configIndex).match(RE_THIS);
88
+ if (!match) {
89
+ throw new Error("match not found (6)");
90
+ }
91
+ const varName = match[0];
92
+ const occurrence2 = "this";
93
+ const replacement2 = `this;globalThis.HACK__NORMAL_HTML_ELEMENTS_CHECK(this);`;
94
+
95
+ newContent = ReplaceNeedle.replaceNeedle(
96
+ newContent,
97
+ this2Index,
98
+ occurrence2,
99
+ replacement2
100
+ );
101
+
102
+ const checkIndex = newContent.indexOf(needle9, configIndex);
103
+ if (checkIndex === -1) {
104
+ throw new Error("no needle found (7)");
105
+ }
106
+ const occurrence3 = "changeDetectorRef.markForCheck()";
107
+ const replacement3 = `changeDetectorRef.markForCheck();globalThis.HACK__NORMAL_HTML_ELEMENTS_RENDER(${varName});`;
108
+ newContent = ReplaceNeedle.replaceNeedle(
109
+ newContent,
110
+ checkIndex,
111
+ occurrence3,
112
+ replacement3
113
+ );
114
+ return newContent;
115
+ };
@@ -0,0 +1,21 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import * as GetBasePath from "../GetBasePath/GetBasePath.js";
4
+ import * as GetCommonJsSnippet from "../GetCommonJsSnippet/GetCommonJsSnippet.js";
5
+ import * as GetNewCommonJsContent from "../GetNewCommonJsContent/GetNewCommonJsContent.js";
6
+
7
+ export const handleCommonJs =
8
+ ({ storeFrontPath, filesPath, mode }) =>
9
+ async (req, res) => {
10
+ const basePath = GetBasePath.getBasePath(mode, storeFrontPath, filesPath);
11
+ // TODO use etag
12
+ const commonPath = join(basePath, "modules", "common.js");
13
+ const content = await readFile(commonPath, "utf8");
14
+ const normalHtmlSnippet = await GetCommonJsSnippet.getCommonJsSnippet();
15
+ const newContent = GetNewCommonJsContent.getNewCommonJsContent({
16
+ content,
17
+ normalHtmlSnippet,
18
+ });
19
+ res.setHeader("content-type", "application/javascript");
20
+ res.end(newContent);
21
+ };
@@ -1,15 +1,9 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import * as GetNewMainJsContent from "../GetNewMainJsContent/GetNewMainJsContent.js";
4
+ import * as GetBasePath from "../GetBasePath/GetBasePath.js";
4
5
  import * as GetPdfViewerSnippet from "../GetPdfViewerSnippet/GetPdfViewerSnippet.js";
5
6
 
6
- const getBasePath = (mode, storeFrontPath, filesPath) => {
7
- if (mode === "slim") {
8
- return join(filesPath, "framework", "src", "default", "storefront");
9
- }
10
- return storeFrontPath;
11
- };
12
-
13
7
  export const handleMainJs =
14
8
  ({
15
9
  storeFrontPath,
@@ -22,7 +16,7 @@ export const handleMainJs =
22
16
  mode,
23
17
  }) =>
24
18
  async (req, res) => {
25
- const basePath = getBasePath(mode, storeFrontPath, filesPath);
19
+ const basePath = GetBasePath.getBasePath(mode, storeFrontPath, filesPath);
26
20
  // TODO use etag
27
21
  const mainPath = join(basePath, "modules", "main.js");
28
22
  const content = await readFile(mainPath, "utf8");
@@ -9,7 +9,7 @@ import * as GetZipUploadMessage from "../GetZipUploadMessage/GetZipUploadMessage
9
9
  import * as NetworkProcess from "../NetworkProcess/NetworkProcess.js";
10
10
  import * as UploadZip from "../UploadZip/UploadZip.js";
11
11
 
12
- const maxRetries = 20;
12
+ const maxRetries = 50;
13
13
  const waitBetweenRetries = 60_000;
14
14
 
15
15
  export const pushCodeTo = async ({ preview, appId }) => {
@@ -0,0 +1,10 @@
1
+ export const replaceNeedle = (content, startIndex, needle, replacement) => {
2
+ const index = content.indexOf(needle, startIndex);
3
+ if (index === -1) {
4
+ throw new Error(`needle replacement: needle not found ${needle}`);
5
+ }
6
+ const pre = content.slice(0, index);
7
+ const post = content.slice(index);
8
+ const newContent = pre + replacement + post.slice(needle.length);
9
+ return newContent;
10
+ };
@@ -1 +1 @@
1
- export const version = '12.28.0'
1
+ export const version = '12.29.0'