refactor(tree-wide): add & use calver implementation (#1534)

Co-authored-by: Hammy <[email protected]>
This commit is contained in:
uncenterandHammy authored and GitHub committed 2024-12-28 17:52:30 -05:00
1 parent 0a9cfae2c9
commit fb505120bd
122 files changed
+272 -127

No files matched your search

+57
View File
@@ -0,0 +1,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);
}