-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfomantic-patch.js
81 lines (72 loc) · 2.45 KB
/
fomantic-patch.js
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
const chalk = require("chalk");
const fs = require("fs");
const logSymbols = require("log-symbols");
const path = require("path");
const nodeModulesPath = path.resolve(process.cwd(), "node_modules");
const hasPackage = (packageName) => {
return fs.existsSync(path.resolve(nodeModulesPath, packageName));
};
const replaceDoubleSemiColon = (input) =>
input.replace("utf-8;;base64", "utf-8;base64");
const run = async () => {
if (hasPackage("fomantic-ui-css")) {
console.log(logSymbols.info, `Detected "fomantic-ui-css" package...`);
const fileToPatchPath = path.resolve(
nodeModulesPath,
"fomantic-ui-css",
"semantic.css",
);
if (fs.existsSync(fileToPatchPath)) {
fs.writeFileSync(
fileToPatchPath,
replaceDoubleSemiColon(
fs.readFileSync(fileToPatchPath, { encoding: "utf8" }),
),
);
console.log(logSymbols.info, `Patch was successfully applied`);
} else {
console.log(
logSymbols.error,
chalk.bgRed.bold(
`Failed to find "${path.resolve(
process.cwd(),
fileToPatchPath,
)}", please check your installation of "fomantic-ui-less"`,
),
);
}
} else if (hasPackage("semantic-ui-css")) {
const filesToPatchPath = [
path.resolve(nodeModulesPath, "semantic-ui-css", "semantic.css"),
path.resolve(
nodeModulesPath,
"semantic-ui-css",
"semantic.min.css",
),
path.resolve(
nodeModulesPath,
"semantic-ui-css",
"components",
"step.css",
),
path.resolve(
nodeModulesPath,
"semantic-ui-css",
"components",
"step.min.css",
),
];
filesToPatchPath.forEach((fileToPatchPath) => {
fs.writeFileSync(
fileToPatchPath,
replaceDoubleSemiColon(
fs.readFileSync(fileToPatchPath, { encoding: "utf8" }),
),
);
});
console.log(logSymbols.info, `Patch was successfully applied`);
} else {
console.log(logSymbols.info, `No supported packages found`);
}
};
run();