-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreadInfoFile.ts
More file actions
49 lines (45 loc) · 1.32 KB
/
readInfoFile.ts
File metadata and controls
49 lines (45 loc) · 1.32 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
import infoJson from "./info.json" with { type: "json" };
import { getLatestInfo } from "./plugins.js";
import { getAllDownloadCount } from "./utils/github.js";
// only typing what's used on the server
export interface PluginsData {
latest: PluginData[];
}
export interface PluginData {
name: string;
url: string;
version: string;
downloadCount: {
currentVersion: number;
allVersions: number;
};
}
export async function readInfoFile(origin: string): Promise<Readonly<PluginsData>> {
return {
...infoJson,
latest: await getLatest(infoJson.latest),
};
async function getLatest(latest: typeof infoJson.latest) {
const results = [];
for (const plugin of latest) {
const [username, pluginName] = plugin.name.split("/");
const info = pluginName
? await getLatestInfo(username, pluginName, origin)
: await getLatestInfo("dprint", plugin.name, origin);
if (info != null) {
results.push({
...plugin,
version: info.version,
url: info.url,
downloadCount: {
currentVersion: info.downloadCount,
allVersions: pluginName
? await getAllDownloadCount(username, pluginName)
: await getAllDownloadCount("dprint", plugin.name),
},
});
}
}
return results;
}
}