Skip to content

Commit

Permalink
build: refactor & use handlebars for generate templating (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekowinston authored Nov 20, 2023
1 parent b1f864c commit f48eba6
Show file tree
Hide file tree
Showing 23 changed files with 682 additions and 409 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/scripts/

# auto-generated files
/.github/ISSUE_TEMPLATE/userstyle.yml
/.github/*.yml
/styles/**/*.md
8 changes: 4 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"catppuccin-repo/": "https://raw.githubusercontent.com/catppuccin/catppuccin/91d6b5433730103c504dcf43583b594e418ee7c1/",
"@actions/core": "npm:@actions/[email protected]",
"@octokit/rest": "npm:@octokit/[email protected]",
"usercss-meta": "npm:[email protected]",
"ajv": "npm:[email protected]",
"chalk": "npm:[email protected]",
"less": "npm:[email protected]"
"handlebars": "npm:[email protected]",
"less": "npm:[email protected]",
"usercss-meta": "npm:[email protected]"
},
"tasks": {
"ci:generate": "deno run -A ./scripts/generate/main.ts",
"ci:sync-maintainers": "deno run -A ./scripts/sync-maintainers/main.ts",
"lint": "deno run -A ./scripts/lint/main.ts",
"lint:fix": "deno task lint --fix",
"update-types": "deno run -A 'npm:json-schema-to-typescript' ./scripts/userstyles.schema.json ./scripts/types/userstyles.d.ts"
"update-types": "deno run -A ./scripts/update-types.ts"
}
}
320 changes: 252 additions & 68 deletions deno.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions scripts/deps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import schema from "./userstyles.schema.json" assert { type: "json" };
import portsSchema from "catppuccin-repo/resources/ports.schema.json" assert {
type: "json",
};
import userStylesSchema from "@/userstyles.schema.json" assert {
type: "json",
};

import { join } from "std/path/mod.ts";
const ROOT = new URL(".", import.meta.url).pathname;
/** absolute path to the repository */
/**
* absolute path to the repository
*/
export const REPO_ROOT = join(ROOT, "..");

export { portsSchema, schema };
export { portsSchema, userStylesSchema };
76 changes: 76 additions & 0 deletions scripts/generate/labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { join } from "std/path/mod.ts";

import { REPO_ROOT } from "@/deps.ts";
import { updateFile } from "@/generate/utils.ts";
import { UserStylesSchema } from "@/types/mod.d.ts";
import { stringify } from "std/yaml/stringify.ts";
import palette from "https://raw.githubusercontent.com/catppuccin/palette/v0.2.0/palette-porcelain.json" assert {
type: "json",
};

/**
* Macchiato color definitions as hex values.
*/
const macchiatoHex = Object.entries(palette.macchiato)
.reduce((acc, [k, v]) => {
acc[k] = `#${v.hex}`;
return acc;
}, {} as Record<keyof typeof palette.macchiato, string>);

const toIssueLabel = (slug: string | number) => `lbl:${slug}`;

export const syncIssueLabels = async (
userstyles: UserStylesSchema.Userstyles,
) => {
updateFile(
join(REPO_ROOT, ".github/issue-labeler.yml"),
stringify(
Object.entries(userstyles)
.reduce((acc, [key]) => {
acc[key.toString()] = [`(${toIssueLabel(key)})`];
return acc;
}, {} as Record<string, string[]>),
),
);

const userstyleIssueContent = Deno.readTextFileSync(join(
REPO_ROOT,
"scripts/generate/templates/userstyle-issue.yml",
));
Deno.writeTextFileSync(
join(REPO_ROOT, ".github/ISSUE_TEMPLATE/userstyle.yml"),
userstyleIssueContent.replace(
`"$LABELS"`,
`${
Object.entries(userstyles)
.map(([key]) => `"${toIssueLabel(key)}"`)
.join(", ")
}`,
),
);

// .github/pr-labeler.yml
updateFile(
join(REPO_ROOT, ".github/pr-labeler.yml"),
stringify(
Object.entries(userstyles)
.reduce((acc, [key]) => {
acc[`${key}`] = `styles/${key}/**/*`;
return acc;
}, {} as Record<string, string>),
),
);

// .github/labels.yml
const syncLabelsContent = Object.entries(userstyles)
.map(([slug, style]) => {
return {
name: slug,
description: [style.name].flat().join(", "),
color: style.color ? macchiatoHex[style.color] : macchiatoHex.blue,
};
});
const syncLabels = join(REPO_ROOT, ".github/labels.yml");
// deno-lint-ignore no-explicit-any
await updateFile(syncLabels, stringify(syncLabelsContent as any));
};
Loading

0 comments on commit f48eba6

Please sign in to comment.