-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreadInfoFile.ts
More file actions
41 lines (36 loc) · 988 Bytes
/
readInfoFile.ts
File metadata and controls
41 lines (36 loc) · 988 Bytes
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
import { getLatestInfo } from "./plugins.ts";
import { createAsyncLazy } from "./utils/mod.ts";
const infoLazy = createAsyncLazy<Readonly<PluginsData>>(async () => {
const data = await Deno.readTextFile("./info.json");
return JSON.parse(data);
});
// only typing what's used on the server
export interface PluginsData {
latest: PluginData[];
}
export interface PluginData {
name: string;
url: string;
version: string;
}
export async function readInfoFile(): Promise<Readonly<PluginsData>> {
const infoObj = await infoLazy.get();
return {
...infoObj,
latest: await getLatest(infoObj.latest),
};
async function getLatest(latest: Readonly<PluginData>[]) {
const results = [];
for (const plugin of latest) {
const info = await getLatestInfo("dprint", plugin.name);
if (info != null) {
results.push({
...plugin,
version: info.version,
url: info.url,
});
}
}
return results;
}
}