forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
executable file
路80 lines (64 loc) 路 2.23 KB
/
Copy pathmain.ts
File metadata and controls
executable file
路80 lines (64 loc) 路 2.23 KB
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
import { REPO_ROOT } from "@/constants.ts";
import { parseArgs } from "@std/cli";
import * as path from "@std/path";
import * as color from "@std/fmt/colors";
// @ts-types="npm:@types/less";
import less from "less";
import { checkForMissingFiles } from "@/lint/file-checker.ts";
import { log } from "@/logger.ts";
import { verifyMetadata } from "@/lint/metadata.ts";
import { runStylelint } from "@/lint/stylelint.ts";
import { getUserstylesData, getUserstylesFiles } from "@/utils.ts";
import stylelintConfig from "../../.stylelintrc.js";
const args = parseArgs(Deno.args, { boolean: ["fix"] });
const userstyle = args._[0]?.toString().match(
/(?<base>styles\/)?(?<userstyle>[a-z0-9_\-.]+)(?<trailing>\/)?(?<file>catppuccin\.user\.less)?/,
)?.groups?.userstyle;
const stylesheets = userstyle
? [path.join(REPO_ROOT, "styles", userstyle, "catppuccin.user.less")]
: getUserstylesFiles();
const { userstyles } = getUserstylesData();
let didLintFail = false;
for (const style of stylesheets) {
const dir = path.basename(path.dirname(style));
const file = path.relative(REPO_ROOT, style);
let content = await Deno.readTextFile(style);
// Verify the UserCSS metadata.
const { globalVars, isLess, fixed } = await verifyMetadata(
file,
content,
dir,
userstyles,
args.fix,
);
content = fixed;
// Don't attempt to compile or lint non-LESS files.
if (!isLess) continue;
// Try to compile the LESS file, report any errors.
less.render(content, { lint: true, globalVars: globalVars }).catch(
(err: Less.RenderError) => {
didLintFail = true;
log.error(
err.message,
{ file, startLine: err.line, endLine: err.line, content },
);
},
);
// Lint with Stylelint.
await runStylelint(style, content, args.fix, stylelintConfig).catch(() =>
didLintFail = true
);
}
if (await checkForMissingFiles() === false) didLintFail = true;
// Cause the workflow to fail if any issues were found.
const THIN_SPACE = "\u2009";
if (didLintFail || log.failed) {
if (!args.fix) {
console.log(
`\n ${
color.bold(color.inverse(color.green(`${THIN_SPACE}TIP${THIN_SPACE}`)))
} Run ${color.bold("deno task lint:fix")} to fix autofixable issues.`,
);
}
Deno.exit(1);
}