Skip to content

Commit

Permalink
refactor(scripts): use deno's std on jsr
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter committed Jul 19, 2024
1 parent 6975e59 commit e576f12
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 287 deletions.
23 changes: 14 additions & 9 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
{
"imports": {
"@/": "./scripts/",
"std/": "https://deno.land/[email protected]/",
"catppuccin-repo/": "https://raw.githubusercontent.com/catppuccin/catppuccin/d4f2666c2b04337f0a8632713de0889d9a7d332d/",
"@catppuccin/palette": "npm:@catppuccin/[email protected]",
"@actions/core": "npm:@actions/[email protected]",
"@catppuccin/palette": "npm:@catppuccin/[email protected]",
"@octokit/rest": "npm:@octokit/[email protected]",
"@std/assert": "jsr:@std/assert@^1.0.0",
"@std/cli": "jsr:@std/cli@^1.0.0",
"@std/fmt": "jsr:@std/fmt@^0.225.6",
"@std/fs": "jsr:@std/fs@^0.229.3",
"@std/path": "jsr:@std/path@^1.0.1",
"@std/yaml": "jsr:@std/yaml@^0.224.3",
"ajv": "npm:[email protected]",
"type-fest": "npm:[email protected]",
"catppuccin-repo/": "https://raw.githubusercontent.com/catppuccin/catppuccin/d4f2666c2b04337f0a8632713de0889d9a7d332d/",
"handlebars": "npm:[email protected]",
"less": "npm:[email protected]",
"usercss-meta": "npm:[email protected]",
"json-schema-to-typescript": "npm:[email protected]",
"less": "npm:[email protected]",
"postcss-less": "npm:[email protected]",
"postcss-value-parser": "npm:[email protected]",
"stylelint": "npm:[email protected]",
"stylelint-config-standard": "npm:[email protected]",
"stylelint-config-recommended": "npm:[email protected]",
"postcss-value-parser": "npm:[email protected]",
"svgo": "npm:[email protected]"
"stylelint-config-standard": "npm:[email protected]",
"svgo": "npm:[email protected]",
"type-fest": "npm:[email protected]",
"usercss-meta": "npm:[email protected]"
},
"tasks": {
"ci:generate": "deno run -A ./scripts/generate/main.ts",
Expand Down
291 changes: 79 additions & 212 deletions deno.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import userStylesSchema from "@/userstyles.schema.json" with {
type: "json",
};

import { join } from "std/path/mod.ts";
import { join } from "@std/path";

const ROOT = import.meta.dirname;
if (!ROOT) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate/labels.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join } from "std/path/mod.ts";
import { join } from "@std/path";

import { REPO_ROOT } from "@/deps.ts";
import { updateFile } from "@/generate/utils.ts";
import { UserStylesSchema } from "@/types/mod.ts";
import { stringify } from "std/yaml/stringify.ts";
import { stringify } from "@std/yaml";
import { type ColorName, flavors } from "@catppuccin/palette";

/**
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S deno run -A
import { join } from "std/path/mod.ts";
import { join } from "@std/path";
import { portsSchema, REPO_ROOT, userStylesSchema } from "@/deps.ts";
import type { PortsSchema, UserStylesSchema } from "@/types/mod.ts";

Expand Down Expand Up @@ -53,7 +53,7 @@ await syncIssueLabels(userstylesData.userstyles);
* Keep `.github/CODEOWNERS` in sync with the userstyle metadata.
*/
const maintainersCodeOwners = () => {
return Object.entries(userstylesData.userstyles)
return Object.entries(userstylesData.userstyles!)
.filter(([_, { "current-maintainers": currentMaintainers }]) =>
currentMaintainers.length > 0
)
Expand Down
18 changes: 10 additions & 8 deletions scripts/generate/readme-repo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from "std/path/mod.ts";
import { join } from "@std/path";
import Handlebars from "handlebars";

import { REPO_ROOT } from "@/deps.ts";
Expand Down Expand Up @@ -52,13 +52,15 @@ export const generateMainReadme = async (
return {
emoji: meta.emoji,
name: meta.name,
ports: ports.map(({ name, path, "current-maintainers": currentMaintainers }) => {
return {
name: [name].flat(),
maintained: currentMaintainers.length > 0,
path,
};
}),
ports: ports.map(
({ name, path, "current-maintainers": currentMaintainers }) => {
return {
name: [name].flat(),
maintained: currentMaintainers.length > 0,
path,
};
},
),
};
}),
});
Expand Down
48 changes: 30 additions & 18 deletions scripts/generate/readme-styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UserStylesSchema } from "@/types/mod.ts";
import { join } from "std/path/mod.ts";
import { join } from "@std/path";
import { REPO_ROOT } from "@/deps.ts";
import Handlebars from "handlebars";

Expand Down Expand Up @@ -53,21 +53,33 @@ export const generateStyleReadmes = (
);
const stylesReadmeContent = Deno.readTextFileSync(stylesReadmePath);

Object.entries(userstyles).map(([slug, { name, readme, "current-maintainers": currentMaintainers, "past-maintainers": pastMaintainers }]) => {
console.log(`Generating README for ${slug}`);
const readmeContent = Handlebars.compile(stylesReadmeContent)({
heading: heading(name, readme["app-link"]),
slug,
usage: readme.usage,
faq: readme.faq,
collaborators: {
currentMaintainers: extractName(currentMaintainers),
pastMaintainers: extractName(pastMaintainers),
},
});
Deno.writeTextFile(
join(REPO_ROOT, "styles", slug.toString(), "README.md"),
readmeContent,
).catch((e) => console.error(e));
});
Object.entries(userstyles).map(
(
[
slug,
{
name,
readme,
"current-maintainers": currentMaintainers,
"past-maintainers": pastMaintainers,
},
],
) => {
console.log(`Generating README for ${slug}`);
const readmeContent = Handlebars.compile(stylesReadmeContent)({
heading: heading(name, readme["app-link"]),
slug,
usage: readme.usage,
faq: readme.faq,
collaborators: {
currentMaintainers: extractName(currentMaintainers),
pastMaintainers: extractName(pastMaintainers),
},
});
Deno.writeTextFile(
join(REPO_ROOT, "styles", slug.toString(), "README.md"),
readmeContent,
).catch((e) => console.error(e));
},
);
};
5 changes: 2 additions & 3 deletions scripts/import-styles/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env -S deno run -A
import usercssMeta from "usercss-meta";
import { ensureDir } from "std/fs/mod.ts";
import { walk } from "std/fs/walk.ts";
import { join } from "std/path/mod.ts";
import { ensureDir, walk } from "@std/fs";
import { join } from "@std/path";

import { REPO_ROOT } from "@/deps.ts";

Expand Down
6 changes: 3 additions & 3 deletions scripts/lint/file-checker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { exists } from "std/fs/exists.ts";
import { join, relative } from "std/path/mod.ts";
import { exists } from "@std/fs";
import { join, relative } from "@std/path";
import core from "@actions/core";

import { REPO_ROOT } from "@/deps.ts";
import { log } from "@/lint/logger.ts";
import * as color from "std/fmt/colors.ts";
import * as color from "@std/fmt/colors";

const requiredFiles = [
"catppuccin.user.css",
Expand Down
4 changes: 2 additions & 2 deletions scripts/lint/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sprintf } from "std/fmt/printf.ts";
import * as color from "std/fmt/colors.ts";
import { sprintf } from "@std/fmt/printf";
import * as color from "@std/fmt/colors";
import core from "@actions/core";

export type LoggerProps = core.AnnotationProperties & { content?: string };
Expand Down
16 changes: 8 additions & 8 deletions scripts/lint/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/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 { walk } from "@std/fs";
import { parseArgs } from "@std/cli";
import { basename, dirname, join, relative } from "@std/path";
// @ts-types="npm:@types/less";
import less from "less";

import { REPO_ROOT } from "@/deps.ts";
Expand All @@ -13,8 +13,8 @@ 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 args = parseArgs(Deno.args, { boolean: ["fix"] });
const subDir = args._[0]?.toString() ?? "";
const stylesheets = walk(join(REPO_ROOT, "styles", subDir), {
includeFiles: true,
includeDirs: false,
Expand All @@ -37,7 +37,7 @@ for await (const entry of stylesheets) {
content,
dir,
userstyles,
flags.fix,
args.fix,
);

content = fixed;
Expand All @@ -58,7 +58,7 @@ for await (const entry of stylesheets) {
);

// Lint with Stylelint.
await lint(entry, content, flags.fix, stylelintConfig).catch(() =>
await lint(entry, content, args.fix, stylelintConfig).catch(() =>
failed = true
);
}
Expand Down
20 changes: 12 additions & 8 deletions scripts/lint/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @deno-types="@/types/usercss-meta.d.ts";
import usercssMeta from "usercss-meta";
import * as color from "std/fmt/colors.ts";
import { sprintf } from "std/fmt/printf.ts";
import type { WalkEntry } from "std/fs/walk.ts";
import { join, relative } from "std/path/mod.ts";
import * as color from "@std/fmt/colors";
import { sprintf } from "@std/fmt/printf";
import type { WalkEntry } from "@std/fs";
import { join, relative } from "@std/path";

import { REPO_ROOT } from "@/deps.ts";
import { log } from "@/lint/logger.ts";
Expand Down Expand Up @@ -47,7 +47,10 @@ export const verifyMetadata = async (
.findIndex((line) => line.includes(key)) + 1;

const message = current === undefined
? sprintf("Metadata `%s` should not be undefined", color.bold(key))
? sprintf(
"Metadata `%s` should not be undefined",
color.bold(key),
)
: sprintf(
'Metadata `%s` should be "%s" but is "%s"',
color.bold(key),
Expand All @@ -63,9 +66,10 @@ export const verifyMetadata = async (
}
}

const template =
(await Deno.readTextFile(join(REPO_ROOT, "template/catppuccin.user.css")))
.split("\n");
const template = (await Deno.readTextFile(
join(REPO_ROOT, "template/catppuccin.user.css"),
))
.split("\n");

for (const variable of ["darkFlavor", "lightFlavor", "accentColor"]) {
const declaration = `@var select ${variable}`;
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint/stylelint-custom/optimizedSvgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const ruleFunction = (primary, _secondary, context) => {
"mergePaths",
"removeComments",
"removeUselessDefs",
"removeScriptElement"
"removeScriptElement",
],
}).data;

Expand Down
6 changes: 3 additions & 3 deletions scripts/lint/stylelint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as color from "std/fmt/colors.ts";
import type { WalkEntry } from "std/fs/walk.ts";
import { relative } from "std/path/mod.ts";
import * as color from "@std/fmt/colors";
import type { WalkEntry } from "@std/fs";
import { relative } from "@std/path";

import "postcss-less";
import stylelint from "stylelint";
Expand Down
2 changes: 1 addition & 1 deletion scripts/sync-maintainers/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S deno run -A
import * as assert from "std/assert/mod.ts";
import * as assert from "@std/assert";
import { Octokit } from "@octokit/rest";

import type { UserStylesSchema } from "@/types/mod.ts";
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S deno run -A
// deno-lint-ignore-file no-explicit-any
import { join } from "std/path/mod.ts";
import { join } from "@std/path";
import { compile, Options } from "json-schema-to-typescript";
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";

Expand Down
9 changes: 4 additions & 5 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Ajv, { Schema } from "ajv";
import { parse } from "std/yaml/parse.ts";
import { join } from "std/path/join.ts";
import { parse } from "@std/yaml";
import { join } from "@std/path";
import { SetRequired } from "type-fest/source/set-required.d.ts";

import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
import { UserstylesSchema } from "@/types/userstyles.d.ts";
import { YAMLError } from "std/yaml/_error.ts";
import { log } from "@/lint/logger.ts";
import { sprintf } from "std/fmt/printf.ts";
import { sprintf } from "@std/fmt/printf";

/**
* @param content A string of YAML content
Expand Down Expand Up @@ -64,7 +63,7 @@ export const getUserstylesData = (): Userstyles => {

return data as Userstyles;
} catch (err) {
if (err instanceof YAMLError) {
if (err.name === "YAMLError") {
const groups =
/(?<message>.*) at line (?<line>\d+), column (?<column>\d+):[\S\s]*/
.exec(err.message)?.groups;
Expand Down

0 comments on commit e576f12

Please sign in to comment.