Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add a update downloads file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 7, 2023
1 parent 1c40506 commit 9e96686
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions UpdateDownloads.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const user = "ArchiDog1998";
const repos = [
"RotationSolver",
];

const clearText = (str) => {
return str
.replace(/\p{Extended_Pictographic}/gu, "") // remove emojis
.replace(/\*\*(.*)\*\*/g, "$1") // extract markdown bold text
.replace(/\[([^\)]+)\]\([^\)]+\)/g, "$1") // extract markdown link label
.split(/\r?\n/g)
.map(line => line.replace(/^#+\s+/g, ""))
.join("\n");
};

const output = await Promise.all(repos.map(async (repo) => {
const res = await fetch(`https://api.github.com/repos/${user}/${repo}/releases/latest`);
const data = await res.json();
const base = {
AssemblyVersion: data.tag_name.replace(/^v/, ""),
Changelog: clearText(data.body),
DownloadCount: data.assets[0].download_count,
LastUpdate: new Date(data.published_at).valueOf() / 1000,
DownloadLinkInstall: data.assets[0].browser_download_url,
DownloadLinkUpdate: data.assets[0].browser_download_url,
};

const manifestAsset = data.assets.find(asset => asset.name == "manifest.json");
if (!manifestAsset) {
return Object.assign({
Author: user,
Name: repo,
InternalName: repo,
RepoUrl: `https://github.com/${user}/${repo}`,
ApplicableVersion: "any",
DalamudApiLevel: 6,
}, base);
}

const manifestRes = await fetch(manifestAsset.browser_download_url);
const manifest = await manifestRes.json();
return Object.assign(manifest, base);
}));

await Deno.writeTextFile("repo.json", JSON.stringify(output, null, 2));

0 comments on commit 9e96686

Please sign in to comment.