-
Notifications
You must be signed in to change notification settings - Fork 16
/
linguist-generated.js
65 lines (64 loc) · 2.27 KB
/
linguist-generated.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
import console from "../modules/console.js";
console.info("Initialization done.");
import fs from "node:fs";
import path from "node:path";
import { warning, startGroup, endGroup } from "@actions/core";
import createCommit from "../modules/createCommit.js";
import yamlModule from "../modules/yamlModule.js";
const oldGitattributes = await fs.promises.readFile(".gitattributes", {
encoding: "utf-8",
});
startGroup("old .gitattributes:");
console.info(oldGitattributes);
endGroup();
const originalGitattributes = oldGitattributes.replace(/\n# From [^\n]+\n(?:[^\n]+\n)+(?=\n|$)/g, "").trim();
startGroup("original .gitattributes:");
console.info(originalGitattributes);
endGroup();
const newGitattributes = [""];
const cssFiles = ["dist/**/*.css"];
for (const [index, stringValue] of Object.entries(process.env)) {
if (!index.startsWith("linguist-generated-")) {
continue;
}
const key = index.replace("linguist-generated-", "");
const value = JSON.parse(stringValue);
if (!Array.isArray(value) || value.length === 0) {
warning(`${index} is not array or empty: ${stringValue}`);
continue;
}
console.info(`${key}:`, value);
newGitattributes.push(`# From ${key}`);
for (const srcPath of value) {
newGitattributes.push(`${srcPath} linguist-generated=true`);
if (path.extname(srcPath) === ".css") {
cssFiles.push(srcPath);
}
}
newGitattributes.push("");
}
startGroup("new .gitattributes:");
console.info(newGitattributes);
endGroup();
const finalGitattributes = [originalGitattributes, ...newGitattributes];
startGroup("final .gitattributes:");
console.info(finalGitattributes);
endGroup();
await fs.promises.writeFile(".gitattributes", `${finalGitattributes.join("\n").trim()}\n`, {
encoding: "utf-8",
});
await createCommit("auto: new .gitattributes generated");
startGroup("cssFiles:");
console.info(cssFiles);
endGroup();
const stylelintrc = await yamlModule.readFile(".stylelintrc.yaml");
startGroup("old .stylelintrc:");
console.info(stylelintrc);
endGroup();
stylelintrc.ignoreFiles = cssFiles;
startGroup("new .stylelintrc:");
console.info(stylelintrc);
endGroup();
await yamlModule.writeFile(".stylelintrc.yaml", stylelintrc);
await createCommit("auto: new .stylelintrc.yaml generated");
console.info("Done.");