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
路66 lines (55 loc) 路 1.88 KB
/
Copy pathmain.ts
File metadata and controls
executable file
路66 lines (55 loc) 路 1.88 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
#!/usr/bin/env -S deno run -A
import { walk } from "std/fs/walk.ts";
import { parse as parseFlags } from "std/flags/mod.ts";
import { basename, dirname, join, relative } from "std/path/mod.ts";
// @deno-types="npm:@types/less";
import less from "less";
import { REPO_ROOT } from "@/deps.ts";
import { checkForMissingFiles } from "@/lint/file-checker.ts";
import { log } from "@/lint/logger.ts";
import { verifyMetadata } from "@/lint/metadata.ts";
import { lint } from "@/lint/stylelint.ts";
import { getUserstylesData } from "@/utils.ts";
import stylelintConfig from "../../.stylelintrc.js";
const flags = parseFlags(Deno.args, { boolean: ["fix"] });
const subDir = flags._[0]?.toString() ?? "";
const stylesheets = walk(join(REPO_ROOT, "styles", subDir), {
includeFiles: true,
includeDirs: false,
includeSymlinks: false,
match: [/\.user.css$/],
});
const { userstyles } = getUserstylesData();
let failed = false;
for await (const entry of stylesheets) {
const dir = basename(dirname(entry.path));
const file = relative(REPO_ROOT, entry.path);
const content = await Deno.readTextFile(entry.path);
// Verify the UserCSS metadata.
const { globalVars, isLess } = await verifyMetadata(
entry,
content,
dir,
userstyles,
);
// 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) => {
failed = true;
log(
err.message,
{ file, startLine: err.line, endLine: err.line, content },
"error",
);
},
);
// Lint with Stylelint.
await lint(entry, content, flags.fix, stylelintConfig).catch(() =>
failed = true
);
}
if (await checkForMissingFiles() === false) failed = true;
// Cause the workflow to fail if any issues were found.
if (failed) Deno.exit(1);