-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06bb5cc
commit ceba3d4
Showing
7 changed files
with
124 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: File Generator | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
paths: | ||
- "scripts/**/*" | ||
- "catppuccin.user.css" | ||
|
||
env: | ||
HAS_USERSTYLES_TOKEN: ${{ secrets.USERSTYLES_TOKEN != '' }} | ||
|
||
jobs: | ||
generate-health-files: | ||
name: Generate health files | ||
runs-on: ubuntu-latest | ||
permissions: | ||
# Give the default GITHUB_TOKEN write permission to commit and push the | ||
# added or changed files to the repository. | ||
contents: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
if: env.HAS_USERSTYLES_TOKEN | ||
with: | ||
token: ${{ secrets.USERSTYLES_TOKEN }} | ||
ref: ${{ github.ref }} | ||
- uses: actions/checkout@v4 | ||
if: env.HAS_USERSTYLES_TOKEN == 'false' | ||
with: | ||
ref: ${{ github.ref }} | ||
|
||
- name: Setup Deno | ||
uses: nekowinston/setup-deno@main | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Generate import file | ||
run: deno task ci:generate-import | ||
|
||
- name: Push changes | ||
uses: stefanzweifel/git-auto-commit-action@v5 | ||
if: ${{ github.repository == 'catppuccin/userstyles' && github.ref == 'refs/heads/main' && env.HAS_USERSTYLES_TOKEN }} | ||
with: | ||
commit_message: "chore: generate import file" | ||
commit_author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" | ||
branch: ${{ github.ref }} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
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,64 @@ | ||
#!/usr/bin/env -S deno run -A | ||
import usercssMeta from "usercss-meta"; | ||
import { walk } from "std/fs/walk.ts"; | ||
import { parse as parseFlags } from "std/flags/mod.ts"; | ||
import { join } from "std/path/mod.ts"; | ||
|
||
import { REPO_ROOT } from "@/deps.ts"; | ||
import { checkForMissingFiles } from "@/file-checker.ts"; | ||
|
||
const flags = parseFlags(Deno.args, { boolean: ["fix"] }); | ||
const subDir = flags._[0]?.toString() ?? ""; | ||
const stylesheets = walk(join(REPO_ROOT, "styles", subDir), { | ||
includeFiles: true, | ||
includeDirs: false, | ||
includeSymlinks: false, | ||
match: [/\.user.css$/], | ||
}); | ||
|
||
// settings that we want for each user to apply | ||
const settings = JSON.stringify({ | ||
settings: { | ||
updateInterval: 24, | ||
updateOnlyEnabled: true, | ||
patchCsp: true | ||
} | ||
}) | ||
|
||
var data = '[' + settings + ','; | ||
|
||
const entries = []; | ||
for await (const entry of stylesheets) { | ||
entries.push(entry); | ||
} | ||
|
||
for (let i = 0; i < entries.length; i++) { | ||
let content = await Deno.readTextFile(entries[i].path); | ||
|
||
const {metadata} = usercssMeta.parse(content); | ||
|
||
const final = JSON.stringify({ | ||
enabled: true, | ||
name: metadata.name, | ||
description: metadata.description, | ||
author: metadata.author, | ||
url: metadata.url, | ||
updateUrl: metadata.updateURL, | ||
usercssData: metadata, | ||
sourceCode: content | ||
}); | ||
|
||
let closingTag = ','; | ||
if (i === entries.length - 1) { | ||
closingTag = ']'; | ||
} | ||
|
||
data += final + closingTag; | ||
} | ||
|
||
Deno.writeFile("compiled.json", new TextEncoder().encode(data)) | ||
|
||
// if any files are missing, cause the workflow to fail | ||
if (await checkForMissingFiles() === false) { | ||
Deno.exit(1); | ||
} |
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