forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
57 lines (46 loc) 路 1.53 KB
/
Copy pathmain.ts
File metadata and controls
57 lines (46 loc) 路 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as path from "@std/path";
import { REPO_ROOT } from "@/constants.ts";
import { CalVer } from "@/bump-version/calver.ts";
import { parseArgs } from "@std/cli";
const args = parseArgs(Deno.args, { boolean: ["all"] });
if (!Deno.env.get("CI") && !args.all) {
throw new Error(
"This script is intended to be used in CI. Userstyle versions are automatically bumped after pull requests are merged.",
);
}
let files = [];
if (args.all) {
for (const dir of Deno.readDirSync(path.join(REPO_ROOT, "styles"))) {
if (!dir.isDirectory) continue;
files.push(path.join(REPO_ROOT, "styles", dir.name, "catppuccin.user.css"));
}
} else {
files = args._.filter((val) => typeof val == "string").map((p: string) =>
path.join(REPO_ROOT, p)
);
}
for (
const file of files
) {
const content = await Deno.readTextFile(file);
const metadataMatches = content.match(
/^\/\*\s*==UserStyle==[\s\S]*?==\/UserStyle==\s*\*\//,
);
if (!metadataMatches) {
throw new Error(`No metadata found in ${file}`);
}
const metadata = metadataMatches[0];
const post = content.slice(metadata.length);
const versionMatches = metadata.match(/@version(\s+)(.*)/);
if (!versionMatches) {
throw new Error(`No version found in ${file}`);
}
const whitespace = versionMatches[1];
const version = new CalVer(versionMatches[2]);
version.incrementWith(new Date());
const newContent = metadata.replace(
/@version\s+.*/,
`@version${whitespace}${version.toString()}`,
) + post;
await Deno.writeTextFile(file, newContent);
}