Skip to content

Commit

Permalink
feat(import-styles): init
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Dec 13, 2023
1 parent 06bb5cc commit ceba3d4
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 3 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/generate-import.yml
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 }}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ giving it a unique and appealing aesthetic in line with Catppuccin's color palet

## 🖥️ Install

To install these userstyles:
To install all userstyles with recomended settings:

1. Download [this](./compiled.json?raw=true).
2. Open the stylus manage page.
3. Locate backup (on the left bar) and select import.
- And select the downloaded file.
4. Enjoy!

To install these indvidual userstyles:

1. Install [Stylus](https://github.com/openstyles/stylus).
- [Firefox](https://addons.mozilla.org/en-GB/firefox/addon/styl-us/)/[Chrome](https://chrome.google.com/webstore/detail/stylus/clngdbkpkpeebahjckkjfobafhncgmne)
Expand Down
1 change: 1 addition & 0 deletions compiled.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
},
"tasks": {
"ci:generate": "deno run -A ./scripts/generate/main.ts",
"ci:generate-import": "deno run -A ./scripts/import-styles/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 ./scripts/update-types.ts"
},
"nodeModulesDir": true
}
}
File renamed without changes.
64 changes: 64 additions & 0 deletions scripts/import-styles/main.ts
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);
}
2 changes: 1 addition & 1 deletion scripts/lint/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { basename, dirname, join, relative } from "std/path/mod.ts";
import less from "less";

import { REPO_ROOT } from "@/deps.ts";
import { checkForMissingFiles } from "@/lint/file-checker.ts";
import { checkForMissingFiles } from "@/file-checker.ts";
import { log } from "@/lint/logger.ts";
import { verifyMetadata } from "@/lint/metadata.ts";
import { lint } from "@/lint/stylelint.ts";
Expand Down

0 comments on commit ceba3d4

Please sign in to comment.