feat(scripts): misc (#1542)

This commit is contained in:
uncenter authored and GitHub committed 2024-12-29 11:03:53 -05:00
1 parent 2c4eefa877
commit d0c973e9c9
10 files changed
+148 -101

No files matched your search

+20 -21
View File
@@ -1,7 +1,6 @@
import { REPO_ROOT } from "@/constants.ts";
import { parseArgs } from "@std/cli";
import * as fs from "@std/fs";
import * as path from "@std/path";
// @ts-types="npm:@types/less";
import less from "less";
@@ -9,31 +8,31 @@ import less from "less";
import { checkForMissingFiles } from "@/lint/file-checker.ts";
import { log } from "@/logger.ts";
import { verifyMetadata } from "@/lint/metadata.ts";
import { lint } from "@/lint/stylelint.ts";
import { getUserstylesData } from "@/utils.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 subDir = args._[0]?.toString() ?? "";
const stylesheets = fs.walk(path.join(REPO_ROOT, "styles", subDir), {
includeFiles: true,
includeDirs: false,
includeSymlinks: false,
match: [/\.user.css$/],
});
const userstyle = args._[0]?.toString().match(
/(?<base>styles\/)?(?<userstyle>[a-z0-9_\.]+)(?<trailing>\/)?(?<file>catppuccin\.user\.css)?/,
)?.groups?.userstyle;
const stylesheets = userstyle
? [path.join(REPO_ROOT, "styles", userstyle, "catppuccin.user.css")]
: getUserstylesFiles();
const { userstyles } = getUserstylesData();
let failed = false;
let didLintFail = false;
for await (const entry of stylesheets) {
const dir = path.basename(path.dirname(entry.path));
const file = path.relative(REPO_ROOT, entry.path);
for (const style of stylesheets) {
const dir = path.basename(path.dirname(style));
const file = path.relative(REPO_ROOT, style);
let content = await Deno.readTextFile(entry.path);
let content = await Deno.readTextFile(style);
// Verify the UserCSS metadata.
const { globalVars, isLess, fixed } = await verifyMetadata(
entry,
file,
content,
dir,
userstyles,
@@ -48,7 +47,7 @@ for await (const entry of stylesheets) {
// Try to compile the LESS file, report any errors.
less.render(content, { lint: true, globalVars: globalVars }).catch(
(err: Less.RenderError) => {
failed = true;
didLintFail = true;
log.error(
err.message,
{ file, startLine: err.line, endLine: err.line, content },
@@ -57,12 +56,12 @@ for await (const entry of stylesheets) {
);
// Lint with Stylelint.
await lint(entry, content, args.fix, stylelintConfig).catch(() =>
failed = true
await runStylelint(style, content, args.fix, stylelintConfig).catch(() =>
didLintFail = true
);
}
if (await checkForMissingFiles() === false) failed = true;
if (await checkForMissingFiles() === false) didLintFail = true;
// Cause the workflow to fail if any issues were found.
if (failed || log.failed) Deno.exit(1);
if (didLintFail || log.failed) Deno.exit(1);