feat(scripts): misc (#1542)
This commit is contained in:
1 parent
2c4eefa877
commit
d0c973e9c9
10 files changed
+148
-101
No files matched your search
+20
-21
@@ -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);
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Userstyles } from "@/types/userstyles.d.ts";
|
||||
import type { WalkEntry } from "@std/fs";
|
||||
import { REPO_ROOT } from "@/constants.ts";
|
||||
|
||||
import * as color from "@std/fmt/colors";
|
||||
@@ -12,7 +11,7 @@ import { log } from "@/logger.ts";
|
||||
import { formatListOfItems } from "@/utils.ts";
|
||||
|
||||
export async function verifyMetadata(
|
||||
entry: WalkEntry,
|
||||
file: string,
|
||||
content: string,
|
||||
userstyle: string,
|
||||
userstyles: Userstyles,
|
||||
@@ -22,7 +21,6 @@ export async function verifyMetadata(
|
||||
content = content.replaceAll("\r\n", "\n");
|
||||
|
||||
const assertions = generateAssertions(userstyle, userstyles);
|
||||
const file = path.relative(REPO_ROOT, entry.path);
|
||||
|
||||
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
|
||||
allowErrors: true,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { WalkEntry } from "@std/fs";
|
||||
import { REPO_ROOT } from "@/constants.ts";
|
||||
|
||||
import * as color from "@std/fmt/colors";
|
||||
@@ -11,8 +10,8 @@ import "stylelint-config-recommended";
|
||||
|
||||
import { log } from "@/logger.ts";
|
||||
|
||||
export async function lint(
|
||||
entry: WalkEntry,
|
||||
export async function runStylelint(
|
||||
file: string,
|
||||
content: string,
|
||||
fix: boolean,
|
||||
config: stylelint.Config,
|
||||
@@ -24,7 +23,7 @@ export async function lint(
|
||||
});
|
||||
|
||||
if (code) {
|
||||
Deno.writeTextFileSync(entry.path, code);
|
||||
Deno.writeTextFileSync(path.join(REPO_ROOT, file), code);
|
||||
}
|
||||
|
||||
for (const result of results) {
|
||||
@@ -36,7 +35,7 @@ export async function lint(
|
||||
) ?? "unspecified stylelint error";
|
||||
|
||||
log.log(message, {
|
||||
file: path.relative(REPO_ROOT, entry.path),
|
||||
file,
|
||||
startLine: warning.line,
|
||||
endLine: warning.endLine,
|
||||
startColumn: warning.column,
|
||||
|
||||
Reference in new issue
Block a user