-
Notifications
You must be signed in to change notification settings - Fork 41
/
build.cjs
115 lines (108 loc) · 4.4 KB
/
build.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/node
/* eslint-disable */
const fs = require("fs-extra");
class SfdxHardisBuilder {
async run() {
console.log("Start additional building of sfdx-hardis repository...");
await this.buildDeployTipsDoc();
this.truncateReadme();
}
async buildDeployTipsDoc() {
console.log("Building salesforce-deployment-assistant-error-list.md doc...");
const deployTipsDocFile = "./docs/salesforce-deployment-assistant-error-list.md";
const { getAllTips } = await import("./lib/common/utils/deployTipsList.js");
const deployTips = getAllTips();
const deployTipsMd = [
"---",
"title: Sfdx-hardis deployment assistant list of errors",
"description: List of errors that are handled by sfdx-hardis deployment assistant",
"---",
"<!-- markdownlint-disable MD013 -->",
"",
"# Salesforce deployment assistant errors list",
"",
"sfdx-hardis can help solve solve deployment errors using a predefined list of issues and associated solutions",
"",
"See how to [setup sfdx-hardis deployment assistant](salesforce-deployment-assistant-setup.md)",
"",
"If you see a deployment error which is not here yet, please [add it in this file](https://github.com/hardisgroupcom/sfdx-hardis/blob/main/src/common/utils/deployTipsList.ts) :)",
""
];
for (const tip of deployTips) {
const linkName = `sf-deployment-assistant/${tip.label.replace(/[^a-zA-Z0-9 -]|\s/g, '-')}.md`
const tipFile = `./docs/` + linkName;
this.buildIndividualMarkdownPageForTip(tip, tipFile);
this.buildMainDeployFixesMarkdown(tip, deployTipsMd, linkName);
}
fs.writeFileSync(deployTipsDocFile, deployTipsMd.join("\n") + "\n");
console.log("Written doc file " + deployTipsDocFile);
}
buildMainDeployFixesMarkdown(tip, deployTipsMd, linkName) {
if (!tip.label) {
throw new Error(`Missing label for ${JSON.stringify(tip)}`);
}
deployTipsMd.push(`## [${tip.label}](${linkName})`);
deployTipsMd.push(...["", "**Detection**", ""]);
if (tip.expressionRegex) {
deployTipsMd.push(...tip.expressionRegex.map((regEx) => "- RegExp: `" + regEx.toString().slice(1).replace("/gm", "") + "`"));
}
if (tip.expressionString) {
deployTipsMd.push(...tip.expressionString.map((str) => "- String: `" + str + "`"));
}
if (tip.examples) {
deployTipsMd.push(...["", "**Examples**", ""]);
deployTipsMd.push(...tip.examples.map((str) => "- `" + str + "`"));
}
deployTipsMd.push(...["", "**Resolution**", ""]);
if (!tip.tip) {
throw new Error(`Missing tip for ${JSON.stringify(tip)}`);
}
deployTipsMd.push("```shell");
deployTipsMd.push(...tip.tip.split("\n"));
deployTipsMd.push("```");
deployTipsMd.push("");
deployTipsMd.push("---");
}
buildIndividualMarkdownPageForTip(tip, tipFile) {
const errorDescription = tip?.examples?.length > 0 ? tip.examples[0] :
tip?.expressionString?.length > 0 ? tip?.expressionString[0] :
tip.expressionRegex[0]
const tipFileMd = [
"---",
`title: ${tip.label} (Deployment assistant)`,
`description: How to solve Salesforce deployment error ${errorDescription}`,
"---",
"<!-- markdownlint-disable MD013 -->"
];
tipFileMd.push(`# ${tip.label}`);
tipFileMd.push(...["", "## Detection", ""]);
if (tip.expressionRegex) {
tipFileMd.push(...tip.expressionRegex.map((regEx) => "- RegExp: `" + regEx.toString().slice(1).replace("/gm", "") + "`"));
}
if (tip.expressionString) {
tipFileMd.push(...tip.expressionString.map((str) => "- String: `" + str + "`"));
}
if (tip.examples) {
tipFileMd.push(...["", "## Examples", ""]);
tipFileMd.push(...tip.examples.map((str) => "- `" + str + "`"));
}
tipFileMd.push(...["", "## Resolution", ""]);
if (!tip.tip) {
throw new Error(`Missing tip for ${JSON.stringify(tip)}`);
}
tipFileMd.push("```shell");
tipFileMd.push(...tip.tip.split("\n"));
tipFileMd.push("```");
fs.writeFileSync(tipFile, tipFileMd.join("\n") + "\n");
}
truncateReadme() {
const readmeFile = "./README.md";
const readmeContent = fs.readFileSync(readmeFile, "utf-8");
const chunks = readmeContent.split("<!-- commands -->")
fs.writeFileSync(readmeFile, chunks[0] + "<!-- commands -->");
console.log("Removed README.md commands");
}
}
(async () => {
await new SfdxHardisBuilder().run();
})();