@pronto-tools-and-more/pronto 4.7.0 → 4.9.0
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 +6 -6
- package/src/parts/App/App.js +18 -46
- package/src/parts/Build/Build.js +10 -0
- package/src/parts/CommandMap/CommandMap.js +4 -2
- package/src/parts/Config/Config.js +2 -0
- package/src/parts/GetCommandFromCliArgs/GetCommandFromCliArgs.js +3 -0
- package/src/parts/GetViewsJson/GetViewsJson.js +32 -0
- package/src/parts/HandleCss/HandleCss.js +30 -0
- package/src/parts/HandleIndex/HandleIndex.js +18 -0
- package/src/parts/HandleViews/HandleViews.js +30 -0
- package/src/parts/Help/Help.js +1 -1
- package/src/parts/JsonFile/JsonFile.js +12 -0
- package/src/parts/Split/Split.js +75 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pronto-tools-and-more/pronto",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@pronto-tools-and-more/file-watcher": "4.
|
|
17
|
-
"@pronto-tools-and-more/files": "4.
|
|
18
|
-
"@pronto-tools-and-more/network-process": "4.
|
|
19
|
-
"@pronto-tools-and-more/sass-compiler": "4.
|
|
16
|
+
"@pronto-tools-and-more/file-watcher": "4.9.0",
|
|
17
|
+
"@pronto-tools-and-more/files": "4.9.0",
|
|
18
|
+
"@pronto-tools-and-more/network-process": "4.9.0",
|
|
19
|
+
"@pronto-tools-and-more/sass-compiler": "4.9.0",
|
|
20
20
|
"@lvce-editor/assert": "^1.2.0",
|
|
21
21
|
"@lvce-editor/ipc": "^9.4.0",
|
|
22
|
-
"@lvce-editor/json-rpc": "^
|
|
22
|
+
"@lvce-editor/json-rpc": "^2.0.0",
|
|
23
23
|
"@lvce-editor/verror": "^1.4.0",
|
|
24
24
|
"execa": "^9.3.1",
|
|
25
25
|
"express": "^4.19.2"
|
package/src/parts/App/App.js
CHANGED
|
@@ -1,53 +1,12 @@
|
|
|
1
1
|
import express from "express";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
2
|
import { join } from "node:path";
|
|
5
|
-
import * as CompileSass from "../CompileSass/CompileSass.js";
|
|
6
3
|
import * as Config from "../Config/Config.js";
|
|
7
4
|
import * as FilesPath from "../FilesPath/FilesPath.js";
|
|
5
|
+
import * as HandleCss from "../HandleCss/HandleCss.js";
|
|
6
|
+
import * as HandleIndex from "../HandleIndex/HandleIndex.js";
|
|
8
7
|
import * as HandleMainJs from "../HandleMainJs/HandleMainJs.js";
|
|
8
|
+
import * as HandleViews from "../HandleViews/HandleViews.js";
|
|
9
9
|
import * as ProxyPath from "../ProxyPath/ProxyPath.js";
|
|
10
|
-
import * as UpdateCss from "../UpdateCss/UpdateCss.js";
|
|
11
|
-
import * as UpdateIndexHtml from "../UpdateIndexHtml/UpdateIndexHtml.js";
|
|
12
|
-
|
|
13
|
-
const handleIndex =
|
|
14
|
-
(storeFrontPath, appId, baseUrl, contentUrl, platform) =>
|
|
15
|
-
async (req, res) => {
|
|
16
|
-
const indexHtmlPath = join(storeFrontPath, "index.html");
|
|
17
|
-
const indexHtmlContent = await readFile(indexHtmlPath, "utf8");
|
|
18
|
-
const newIndexHtml = UpdateIndexHtml.updateIndexHtml(
|
|
19
|
-
indexHtmlContent,
|
|
20
|
-
appId,
|
|
21
|
-
baseUrl,
|
|
22
|
-
contentUrl,
|
|
23
|
-
platform
|
|
24
|
-
);
|
|
25
|
-
res.end(newIndexHtml);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const handleCss = (storeFrontPath) => async (req, res, next) => {
|
|
29
|
-
const pathName = req._parsedUrl.pathname;
|
|
30
|
-
if (!pathName.endsWith(".css")) {
|
|
31
|
-
return next();
|
|
32
|
-
}
|
|
33
|
-
if (pathName === "/assets/custom.css") {
|
|
34
|
-
try {
|
|
35
|
-
const result = await CompileSass.compileSass(Config.rootSassFile);
|
|
36
|
-
res.end(result.css);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.warn(error);
|
|
39
|
-
res.end(`css error: ${error}`);
|
|
40
|
-
}
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const cssPath = join(storeFrontPath, pathName);
|
|
44
|
-
if (!existsSync(cssPath)) {
|
|
45
|
-
return next();
|
|
46
|
-
}
|
|
47
|
-
const cssContent = await readFile(cssPath, "utf8");
|
|
48
|
-
const newCss = UpdateCss.updateCss(cssContent);
|
|
49
|
-
res.end(newCss);
|
|
50
|
-
};
|
|
51
10
|
|
|
52
11
|
export const create = ({
|
|
53
12
|
root,
|
|
@@ -67,7 +26,13 @@ export const create = ({
|
|
|
67
26
|
const contentPath = join(root, "src", "default", "content");
|
|
68
27
|
app.get(
|
|
69
28
|
"/",
|
|
70
|
-
handleIndex(
|
|
29
|
+
HandleIndex.handleIndex(
|
|
30
|
+
storeFrontPath,
|
|
31
|
+
appId,
|
|
32
|
+
baseUrl,
|
|
33
|
+
contentUrl,
|
|
34
|
+
platform
|
|
35
|
+
)
|
|
71
36
|
);
|
|
72
37
|
app.get(
|
|
73
38
|
"/modules/main.js",
|
|
@@ -82,7 +47,14 @@ export const create = ({
|
|
|
82
47
|
mode,
|
|
83
48
|
})
|
|
84
49
|
);
|
|
85
|
-
app.
|
|
50
|
+
app.get(
|
|
51
|
+
"/assets/views.json",
|
|
52
|
+
HandleViews.handleViews({
|
|
53
|
+
storeFrontPath,
|
|
54
|
+
splitViews: Config.splitViews,
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
app.use("*", HandleCss.handleCss(storeFrontPath));
|
|
86
58
|
app.use(express.static(FilesPath.filesPath));
|
|
87
59
|
if (mode === "slim") {
|
|
88
60
|
app.use(
|
package/src/parts/Build/Build.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as Config from "../Config/Config.js";
|
|
|
6
6
|
import * as Cwd from "../Cwd/Cwd.js";
|
|
7
7
|
import * as FilesPath from "../FilesPath/FilesPath.js";
|
|
8
8
|
import * as SassProcess from "../SassProcess/SassProcess.js";
|
|
9
|
+
import * as GetViewsJson from "../GetViewsJson/GetViewsJson.js";
|
|
9
10
|
|
|
10
11
|
const sourceMap = false;
|
|
11
12
|
|
|
@@ -34,6 +35,15 @@ export const build = async () => {
|
|
|
34
35
|
errorOnExist: false,
|
|
35
36
|
});
|
|
36
37
|
}
|
|
38
|
+
if (Config.splitViews) {
|
|
39
|
+
const viewsJson = await GetViewsJson.getViewsJson(
|
|
40
|
+
join(Cwd.cwd, "src", "default", "storefront", "assets", "views")
|
|
41
|
+
);
|
|
42
|
+
await writeFile(
|
|
43
|
+
join(dist, "src", "default", "storefront", "assets", "views.json"),
|
|
44
|
+
JSON.stringify(viewsJson, null, 2) + "\n"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
37
47
|
} catch (error) {
|
|
38
48
|
throw new VError(error, `Failed to build`);
|
|
39
49
|
} finally {
|
|
@@ -7,15 +7,17 @@ import * as PushCode from "../PushCode/PushCode.js";
|
|
|
7
7
|
import * as Server from "../Server/Server.js";
|
|
8
8
|
import * as Upgrade from "../Upgrade/Upgrade.js";
|
|
9
9
|
import * as UploadZip from "../UploadZip/UploadZip.js";
|
|
10
|
+
import * as Split from "../Split/Split.js";
|
|
10
11
|
|
|
11
12
|
export const commandMap = {
|
|
12
13
|
"Build.build": Build.build,
|
|
13
14
|
"Help.help": Help.help,
|
|
15
|
+
"History.history": History.history,
|
|
14
16
|
"Login.login": Login.login,
|
|
15
17
|
"PullCode.pullCode": PullCode.pullCode,
|
|
16
18
|
"PushCode.pushCode": PushCode.pushCode,
|
|
17
19
|
"Server.start": Server.start,
|
|
18
|
-
"
|
|
20
|
+
"Split.split": Split.split,
|
|
19
21
|
"Upgrade.upgrade": Upgrade.upgrade,
|
|
20
|
-
"
|
|
22
|
+
"UploadZip.uploadZip": UploadZip.uploadZip,
|
|
21
23
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { VError } from "@lvce-editor/verror";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const getContents = async (folder) => {
|
|
6
|
+
const promises = [];
|
|
7
|
+
const dirents = await readdir(folder);
|
|
8
|
+
for (const dirent of dirents) {
|
|
9
|
+
const absolutePath = join(folder, dirent);
|
|
10
|
+
promises.push(readFile(absolutePath, "utf8"));
|
|
11
|
+
}
|
|
12
|
+
const contents = await Promise.all(promises);
|
|
13
|
+
return contents;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const parseContent = (content) => {
|
|
17
|
+
return JSON.parse(content);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const parseContents = (contents) => {
|
|
21
|
+
return contents.map(parseContent);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const getViewsJson = async (folder) => {
|
|
25
|
+
try {
|
|
26
|
+
const contents = await getContents(folder);
|
|
27
|
+
const parsed = parseContents(contents);
|
|
28
|
+
return parsed;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new VError(error, `Failed to generate views json`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import * as CompileSass from "../CompileSass/CompileSass.js";
|
|
5
|
+
import * as Config from "../Config/Config.js";
|
|
6
|
+
import * as UpdateCss from "../UpdateCss/UpdateCss.js";
|
|
7
|
+
|
|
8
|
+
export const handleCss = (storeFrontPath) => async (req, res, next) => {
|
|
9
|
+
const pathName = req._parsedUrl.pathname;
|
|
10
|
+
if (!pathName.endsWith(".css")) {
|
|
11
|
+
return next();
|
|
12
|
+
}
|
|
13
|
+
if (pathName === "/assets/custom.css") {
|
|
14
|
+
try {
|
|
15
|
+
const result = await CompileSass.compileSass(Config.rootSassFile);
|
|
16
|
+
res.end(result.css);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.warn(error);
|
|
19
|
+
res.end(`css error: ${error}`);
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const cssPath = join(storeFrontPath, pathName);
|
|
24
|
+
if (!existsSync(cssPath)) {
|
|
25
|
+
return next();
|
|
26
|
+
}
|
|
27
|
+
const cssContent = await readFile(cssPath, "utf8");
|
|
28
|
+
const newCss = UpdateCss.updateCss(cssContent);
|
|
29
|
+
res.end(newCss);
|
|
30
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import * as UpdateIndexHtml from "../UpdateIndexHtml/UpdateIndexHtml.js";
|
|
4
|
+
|
|
5
|
+
export const handleIndex =
|
|
6
|
+
(storeFrontPath, appId, baseUrl, contentUrl, platform) =>
|
|
7
|
+
async (req, res) => {
|
|
8
|
+
const indexHtmlPath = join(storeFrontPath, "index.html");
|
|
9
|
+
const indexHtmlContent = await readFile(indexHtmlPath, "utf8");
|
|
10
|
+
const newIndexHtml = UpdateIndexHtml.updateIndexHtml(
|
|
11
|
+
indexHtmlContent,
|
|
12
|
+
appId,
|
|
13
|
+
baseUrl,
|
|
14
|
+
contentUrl,
|
|
15
|
+
platform
|
|
16
|
+
);
|
|
17
|
+
res.end(newIndexHtml);
|
|
18
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { pipeline } from "node:stream/promises";
|
|
4
|
+
import * as JsonFile from "../JsonFile/JsonFile.js";
|
|
5
|
+
|
|
6
|
+
const handleViewsSplit = async (storeFrontPath) => {
|
|
7
|
+
const viewsFolderPath = join(storeFrontPath, "assets", "views");
|
|
8
|
+
const dirents = await readdir(viewsFolderPath);
|
|
9
|
+
const promises = [];
|
|
10
|
+
for (const dirent of dirents) {
|
|
11
|
+
const absolutePath = join(viewsFolderPath, dirent);
|
|
12
|
+
const promise = JsonFile.readJson(absolutePath);
|
|
13
|
+
promises.push(promise);
|
|
14
|
+
}
|
|
15
|
+
const contents = await Promise.all(promises);
|
|
16
|
+
const stringified = JSON.stringify(contents, null, 2) + "\n";
|
|
17
|
+
return stringified;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const handleViews =
|
|
21
|
+
({ storeFrontPath, splitViews }) =>
|
|
22
|
+
async (req, res) => {
|
|
23
|
+
if (splitViews) {
|
|
24
|
+
const content = await handleViewsSplit(storeFrontPath);
|
|
25
|
+
res.end(content);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const viewsFilePath = join(storeFrontPath, "assets", "views.json");
|
|
29
|
+
await pipeline(viewsFilePath, res);
|
|
30
|
+
};
|
package/src/parts/Help/Help.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
export const readJson = async (path) => {
|
|
4
|
+
const content = await readFile(path, "utf8");
|
|
5
|
+
const parsed = JSON.parse(content);
|
|
6
|
+
return parsed;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const writeJson = async (path, value) => {
|
|
10
|
+
const stringified = JSON.stringify(value, null, 2) + "\n";
|
|
11
|
+
await writeFile(path, stringified);
|
|
12
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as NetworkProcess from "../NetworkProcess/NetworkProcess.js";
|
|
2
|
+
import * as Cwd from "../Cwd/Cwd.js";
|
|
3
|
+
import { VError } from "@lvce-editor/verror";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
import { mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
6
|
+
import * as JsonFile from "../JsonFile/JsonFile.js";
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
|
|
9
|
+
const getFileName = (item) => {
|
|
10
|
+
if (item.path) {
|
|
11
|
+
if (item.path === "/") {
|
|
12
|
+
return item.name + ".json";
|
|
13
|
+
}
|
|
14
|
+
return item.path + ".json";
|
|
15
|
+
}
|
|
16
|
+
if (item.globalData) {
|
|
17
|
+
return `globalData.json`;
|
|
18
|
+
}
|
|
19
|
+
return `unknown.json`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const splitViewsJson = async (viewsJsonPath, viewsJsonFolder) => {
|
|
23
|
+
const viewsJsonContent = await readFile(viewsJsonPath, "utf8");
|
|
24
|
+
const viewsJsonArray = JSON.parse(viewsJsonContent);
|
|
25
|
+
const splitItems = [];
|
|
26
|
+
for (const item of viewsJsonArray) {
|
|
27
|
+
const fileName = getFileName(item);
|
|
28
|
+
const splitItem = {
|
|
29
|
+
path: join(viewsJsonFolder, fileName),
|
|
30
|
+
content: JSON.stringify(item, null, 2) + "\n",
|
|
31
|
+
};
|
|
32
|
+
splitItems.push(splitItem);
|
|
33
|
+
}
|
|
34
|
+
return splitItems;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const split = async () => {
|
|
38
|
+
try {
|
|
39
|
+
const viewsJsonPath = join(
|
|
40
|
+
Cwd.cwd,
|
|
41
|
+
"src",
|
|
42
|
+
"default",
|
|
43
|
+
"storefront",
|
|
44
|
+
"assets",
|
|
45
|
+
"views.json"
|
|
46
|
+
);
|
|
47
|
+
const viewsJsonFolder = join(
|
|
48
|
+
Cwd.cwd,
|
|
49
|
+
"src",
|
|
50
|
+
"default",
|
|
51
|
+
"storefront",
|
|
52
|
+
"assets",
|
|
53
|
+
"views"
|
|
54
|
+
);
|
|
55
|
+
if (existsSync(viewsJsonFolder)) {
|
|
56
|
+
console.info("[pronto] project is already split");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
await mkdir(viewsJsonFolder, { recursive: true });
|
|
60
|
+
const splitItems = await splitViewsJson(viewsJsonPath, viewsJsonFolder);
|
|
61
|
+
for (const splitItem of splitItems) {
|
|
62
|
+
await writeFile(splitItem.path, splitItem.content);
|
|
63
|
+
}
|
|
64
|
+
await rm(viewsJsonPath);
|
|
65
|
+
const configPath = join(Cwd.cwd, "pronto.json");
|
|
66
|
+
const config = await JsonFile.readJson(configPath);
|
|
67
|
+
const newConfig = {
|
|
68
|
+
...config,
|
|
69
|
+
splitViews: true,
|
|
70
|
+
};
|
|
71
|
+
await JsonFile.writeJson(configPath, newConfig);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new VError(error, `Failed to split views.json`);
|
|
74
|
+
}
|
|
75
|
+
};
|