-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-indexes.js
120 lines (113 loc) · 3.35 KB
/
update-indexes.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env -S deno run -A
import * as CSV from "npm:csv/sync";
import { readFile, rm, writeFile } from "node:fs/promises";
import { $ } from "npm:execa";
import { temporaryDirectoryTask } from "npm:tempy";
import { join } from "node:path";
const $json = (...a) => $(...a).then((r) => JSON.parse(r.stdout));
const text = await readFile("./_data/things.csv", "utf8");
const things = CSV.parse(text, {
columns: true,
skip_empty_lines: true,
cast: true,
});
const features = [];
const templates = [];
console.log("things.length", things.length);
for (const thing of things) {
console.log("processing", thing);
let manifest;
try {
manifest = await $json`oras manifest fetch ${thing.specifier}:latest`;
} catch (error) {
console.log("error fetching manifest. skipping.", thing, error);
continue;
}
if (
manifest.annotations?.["com.github.package.type"] ===
"devcontainer_collection"
) {
await $`oras pull ${thing.specifier}:latest -o /tmp/marketplace`;
const collection = JSON.parse(
await readFile("/tmp/marketplace/devcontainer-collection.json"),
);
await rm("/tmp/marketplace", { force: true, recursive: true });
for (const feature of collection.features || []) {
features.push({
specifier: `${thing.specifier}/${feature.id}`,
documentationURL: feature.documentationURL,
source: "",
author: "",
stars: "",
downloads: "",
name: feature.name || "",
description: feature.description,
version: feature.version,
});
}
for (const template of collection.templates || []) {
let downloads;
templates.push({
specifier: `${thing.specifier}/${template.id}`,
documentationURL: template.documentationURL,
source: "",
author: "",
stars: "",
downloads: "",
name: template.name || "",
description: template.description,
version: template.version,
});
}
} else if (
manifest.annotations?.["com.github.package.type"] === "devcontainer_feature"
) {
const feature = JSON.parse(manifest.annotations["dev.containers.metadata"]);
features.push({
specifier: thing.specifier,
documentationURL: feature.documentationURL,
source: "",
author: "",
stars: "",
downloads: downloads || "",
name: feature.name || "",
description: feature.description,
version: feature.version,
});
} else if (
manifest.annotations?.["com.github.package.type"] ===
"devcontainer_template"
) {
const template = JSON.parse(
manifest.annotations["dev.containers.metadata"],
);
templates.push({
specifier: thing.specifier,
documentationURL: template.documentationURL,
source: "",
author: "",
stars: "",
downloads: downloads || "",
name: template.name || "",
description: template.description,
version: template.version,
});
} else {
console.log("no manifest annotations. skipping.", thing, manifest);
continue;
}
}
{
console.log("features.length", features.length);
const text = CSV.stringify(features, {
header: true,
});
await writeFile("_data/features.csv", text);
}
{
console.log("templates.length", templates.length);
const text = CSV.stringify(templates, {
header: true,
});
await writeFile("_data/templates.csv", text);
}