fix(lib,scripts): import locally for linting, snapshot tests, dev server (#2172)
Co-authored-by: WalkQuackBack <[email protected]>
This commit is contained in:
1 parent
dc1fac9639
commit
acd47ee987
8 files changed
+302
-18
No files matched your search
+15
-3
@@ -24,12 +24,19 @@ const stylesheets = userstyle
|
||||
const { userstyles } = getUserstylesData();
|
||||
|
||||
let didLintFail = false;
|
||||
const patches = [
|
||||
["https://userstyles.catppuccin.com/lib", path.join(REPO_ROOT, "lib")],
|
||||
];
|
||||
|
||||
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);
|
||||
// Apply patches.
|
||||
for (const [search, replace] of patches) {
|
||||
content = content.replaceAll(search, replace);
|
||||
}
|
||||
|
||||
// Verify the UserCSS metadata.
|
||||
const { globalVars, isLess, fixed } = await verifyMetadata(
|
||||
@@ -56,10 +63,15 @@ for (const style of stylesheets) {
|
||||
},
|
||||
);
|
||||
|
||||
// Reverse apply patches.
|
||||
for (const [search, replace] of patches) {
|
||||
content = content.replaceAll(replace, search);
|
||||
}
|
||||
|
||||
// Lint with Stylelint.
|
||||
await runStylelint(style, content, args.fix, stylelintConfig).catch(() =>
|
||||
didLintFail = true
|
||||
);
|
||||
const results = await runStylelint(style, content, args.fix, stylelintConfig)
|
||||
.catch(() => didLintFail = true);
|
||||
Deno.writeTextFileSync(file, typeof results === "string" ? results : content);
|
||||
}
|
||||
|
||||
if (await checkForMissingFiles() === false) didLintFail = true;
|
||||
|
||||
@@ -85,8 +85,6 @@ export async function verifyMetadata(
|
||||
}
|
||||
}
|
||||
|
||||
Deno.writeTextFileSync(file, content);
|
||||
|
||||
const template = (await Deno.readTextFile(
|
||||
path.join(REPO_ROOT, "template/catppuccin.user.less"),
|
||||
))
|
||||
|
||||
@@ -12,17 +12,13 @@ export async function runStylelint(
|
||||
content: string,
|
||||
fix: boolean,
|
||||
config: stylelint.Config,
|
||||
) {
|
||||
): Promise<string | undefined> {
|
||||
const { results, code } = await stylelint.lint({
|
||||
code: content,
|
||||
config,
|
||||
fix,
|
||||
});
|
||||
|
||||
if (code) {
|
||||
Deno.writeTextFileSync(file, code);
|
||||
}
|
||||
|
||||
for (const result of results) {
|
||||
for (const warning of result.warnings) {
|
||||
// Some cleanup for fancier logging - dims the rule name.
|
||||
@@ -43,4 +39,6 @@ export async function runStylelint(
|
||||
|
||||
if (result.warnings.length > 0) throw new Error("stylelint error");
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
Reference in new issue
Block a user