Skip to content

Commit edb904c

Browse files
authored
Merge pull request #28 from juliamertz/main
Unify theme format & update workflows
2 parents 367fb45 + bd64787 commit edb904c

54 files changed

Lines changed: 8102 additions & 10233 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: main
6+
pull_request:
7+
types: [opened, synchronize, reopened, ready_for_review]
8+
9+
jobs:
10+
check:
11+
name: Continuous integration
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Deno
18+
uses: denoland/setup-deno@v2
19+
with:
20+
deno-version: v2.x
21+
22+
- name: Check formatting
23+
run: deno fmt --check

.github/workflows/release.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
name: Update release
1+
name: Release
22

33
on:
44
push:
55
branches:
66
- main
77
paths:
8-
- 'styles/**/rose-pine.user.css'
8+
- "styles/**/rose-pine.user.css"
99

1010
permissions:
1111
contents: write
1212

1313
jobs:
1414
release:
15-
name: Update release
15+
name: Release
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout
19-
uses: actions/checkout@v2
20-
- name: Build
21-
run: |
22-
bash ./build.sh
23-
cd ./scripts && npm install && cd ..
24-
node ./scripts/generate-imports.js
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Deno
22+
uses: denoland/setup-deno@v2
23+
with:
24+
deno-version: v2.x
25+
26+
- name: Build import lists
27+
run: ./scripts/generate-imports
28+
2529
- name: Release
2630
env:
2731
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28-
run: gh release upload userstyle-imports import.json --clobber
32+
run: gh release upload userstyle-imports rose-pine*-import.json --clobber

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
scripts/node_modules
22
package-lock.json
33
bun.lockb
4-
import.json
4+
rose-pine*-import.json

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

build.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

readme.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111

1212
# Getting started
1313

14-
1. Install the [Stylus](https://github.com/openstyles/stylus) extension for [Chrome](https://chrome.google.com/webstore/detail/stylus/clngdbkpkpeebahjckkjfobafhncgmne) or [Firefox](https://addons.mozilla.org/en-GB/firefox/addon/styl-us/).
14+
1. Install the [Stylus](https://github.com/openstyles/stylus) extension for
15+
[Chrome](https://chrome.google.com/webstore/detail/stylus/clngdbkpkpeebahjckkjfobafhncgmne)
16+
or [Firefox](https://addons.mozilla.org/en-GB/firefox/addon/styl-us/).
1517
2. Downloading Userstyles:
1618
- Open the folder of the userstyle you want to install.
17-
- Then, click on the "Stylus Install" button or open `rose-pine.user.css` and click on "Raw."
18-
> To download all userstyles at once, go to the [releases](https://github.com/rose-pine/userstyles/releases/tag/userstyle-imports) page and follow the instructions listed there.
19-
3. Optionally, you can configure any available options that you want to change. Then, click on the "Install Style" button.
20-
4. Some might require extra steps to work correctly, so make sure to check its readme page for additional information.
19+
- Then, click on the "Stylus Install" button or open `rose-pine.user.less`
20+
and click on "Raw."
21+
> To download all userstyles at once, go to the
22+
> [releases](https://github.com/rose-pine/userstyles/releases/tag/userstyle-imports)
23+
> page and follow the instructions listed there.
24+
3. Optionally, you can configure any available options that you want to change.
25+
Then, click on the "Install Style" button.
26+
4. Some might require extra steps to work correctly, so make sure to check its
27+
readme page for additional information.
2128

2229
## Userstyles
2330

@@ -56,4 +63,9 @@
5663

5764
## Contributing
5865

59-
Contributions are welcome and appreciated! Please run `sh build.sh` to format the repository before submitting a pull request.
66+
We use [deno](https://docs.deno.com/runtime/getting_started/installation/) to
67+
format this repo and for automation, make sure you have it installed.
68+
69+
Contributions are welcome and appreciated! You can create a new userstyle from
70+
the template by running `./scripts/init Website` Please run `deno fmt` to format
71+
the repository before submitting a pull request.

scripts/generate-imports

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env -S deno --allow-read --allow-write
2+
// vim:ft=javascript
3+
4+
import usercssMeta from "npm:usercss-meta@0.12.0";
5+
6+
async function readTheme(name) {
7+
const path = `./styles/${name}/rose-pine.user.less`;
8+
const text = await Deno.readTextFile(path);
9+
const metadata = usercssMeta.parse(text).metadata;
10+
return {
11+
enabled: true,
12+
name: metadata.name ?? "",
13+
description: metadata.description ?? "",
14+
author: "Rose Piné",
15+
updateUrl: metadata.updateURL ?? "",
16+
usercssData: metadata,
17+
sourceCode: text.toString(),
18+
};
19+
}
20+
21+
function patchMetadata(theme, defaultVariant) {
22+
if (!theme.usercssData?.vars) return theme;
23+
const keys = Object.keys(theme.usercssData.vars);
24+
if (keys.includes("lightVariant") && keys.includes("darkVariant")) {
25+
theme.usercssData.vars.lightVariant.default = "dawn";
26+
theme.usercssData.vars.darkVariant.default = defaultVariant;
27+
} else if (keys.includes("variant")) {
28+
theme.usercssData.vars.variant.default = defaultVariant;
29+
} else {
30+
console.warn(`Theme ${theme.name} has no variant variable`);
31+
}
32+
return theme;
33+
}
34+
35+
let result = [];
36+
for await (const entry of Deno.readDir(`./styles`)) {
37+
try {
38+
const theme = await readTheme(entry.name);
39+
result.push(theme);
40+
} catch (err) {
41+
console.error(`ignoring ${entry.name}: ${err}`);
42+
}
43+
}
44+
45+
const settings = {
46+
settings: {
47+
updateInterval: 24,
48+
updateOnlyEnabled: true,
49+
patchCsp: true,
50+
},
51+
};
52+
53+
for (const variant of ["main", "moon", "dawn"]) {
54+
const patched = result.map((theme) => patchMetadata(theme, variant));
55+
const serialized = JSON.stringify([settings, ...patched], null, 2);
56+
const filename = `rose-pine${variant == "main" ? "" : `-${variant}`}-import.json`;
57+
await Deno.writeTextFile(filename, serialized);
58+
}

scripts/generate-imports.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

scripts/init

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env -S deno --allow-read --allow-write
2+
// vim:ft=typescript
3+
4+
function replace(
5+
source: string,
6+
identifier: string,
7+
replacement: string,
8+
): string {
9+
const pattern = new RegExp(`\{\{\s*${identifier}\s*\}\}`, "g");
10+
return source.replace(pattern, replacement);
11+
}
12+
13+
function replaceMap(
14+
source: string,
15+
substitutions: Record<string, string>,
16+
): string {
17+
let buff = source;
18+
for (const [key, value] of Object.entries(substitutions)) {
19+
buff = replace(buff, key, value);
20+
}
21+
return buff;
22+
}
23+
24+
const substitutions = {
25+
title: Deno.args[0],
26+
directory: Deno.args[0].toLowerCase(),
27+
year: new Date().getUTCFullYear(),
28+
};
29+
30+
const themePath = `./styles/${substitutions.directory}`;
31+
await Deno.mkdir(themePath);
32+
33+
const userstyleTemplate = await Deno.readTextFile( "./template/rose-pine.user.less",);
34+
const readmeTemplate = await Deno.readTextFile("./template/readme.md");
35+
const licenseTemplate = await Deno.readTextFile("./template/license");
36+
37+
await Deno.writeTextFile(
38+
`${themePath}/rose-pine.user.less`,
39+
replaceMap(userstyleTemplate, substitutions),
40+
);
41+
await Deno.writeTextFile(
42+
`${themePath}/readme.md`,
43+
replaceMap(readmeTemplate, substitutions),
44+
);
45+
await Deno.writeTextFile(
46+
`${themePath}/license`,
47+
replaceMap(licenseTemplate, substitutions),
48+
);

scripts/package.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)