-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: refactor & use handlebars for
generate
templating (#343)
- Loading branch information
1 parent
b1f864c
commit f48eba6
Showing
23 changed files
with
682 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
/scripts/ | ||
|
||
# auto-generated files | ||
/.github/ISSUE_TEMPLATE/userstyle.yml | ||
/.github/*.yml | ||
/styles/**/*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}; |
Oops, something went wrong.