Skip to content

Commit

Permalink
refactor: use handlebars, split generate script
Browse files Browse the repository at this point in the history
  • Loading branch information
nekowinston committed Nov 19, 2023
1 parent c3f013a commit 03330a6
Show file tree
Hide file tree
Showing 20 changed files with 629 additions and 348 deletions.
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@actions/core": "npm:@actions/[email protected]",
"@octokit/rest": "npm:@octokit/[email protected]",
"ajv": "npm:[email protected]",
"handlebars": "npm:[email protected]",
"less": "npm:[email protected]",
"usercss-meta": "npm:[email protected]"
},
Expand All @@ -14,6 +15,6 @@
"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: 250 additions & 70 deletions deno.lock

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions scripts/generate/labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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";

export const syncIssueLabels = (userstyles: UserStylesSchema.Userstyles) => {
const ISSUE_PREFIX = "lbl:";

const issuesLabelerPath = join(REPO_ROOT, ".github/issue-labeler.yml");
const issuesLabelerContent = Object.entries(userstyles)
.map(([key]) => `${key}: ["(${ISSUE_PREFIX + key})"]`)
.join("\n");
updateFile(issuesLabelerPath, issuesLabelerContent);

const userstyleIssuePath = join(
REPO_ROOT,
"scripts/generate/templates/userstyle-issue.yml",
);
const userstyleIssueContent = Deno.readTextFileSync(userstyleIssuePath);

const replacedUserstyleIssueContent = userstyleIssueContent.replace(
"$PORTS",
`${
Object.entries(userstyles)
.map(([key]) => `'${ISSUE_PREFIX + key}'`)
.join(", ")
}`,
);
Deno.writeTextFileSync(
join(REPO_ROOT, ".github/ISSUE_TEMPLATE/userstyle.yml"),
replacedUserstyleIssueContent,
);

const pullRequestLabelerPath = join(REPO_ROOT, ".github/pr-labeler.yml");
const pullRequestLabelerContent = Object.entries(userstyles)
.map(([key]) => `${key}: styles/${key}/**/*`)
.join("\n");
updateFile(pullRequestLabelerPath, pullRequestLabelerContent);

const syncLabels = join(REPO_ROOT, ".github/labels.yml");
const syncLabelsContent = Object.entries(userstyles)
.map(
([key, style]) =>
`- name: ${key}
description: ${style.name}
color: "#8aadf4"`,
).join("\n");
updateFile(syncLabels, syncLabelsContent);
};
Loading

0 comments on commit 03330a6

Please sign in to comment.