-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-manifest.js
71 lines (58 loc) · 2.05 KB
/
make-manifest.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
import chalk from 'chalk';
import fetch from 'node-fetch';
import fs from 'fs';
const MANIFEST_FILE_NAME = 'manifest.json';
// do-not-use: rewrite for rate-limiting first, not feasible on public api
async function hydrateManifest() {
return manifest.map(async (item) => {
let repoStats;
try {
repoStats = await (await fetch(`https://api.github.com/repos/${item.id}`)).json()
} catch (e) {
}
console.log(repoStats);
return {
...item,
stars: repoStats?.stargazers_counts
}
});
}
async function makeManifest() {
let manifest = [];
const VITE_AWESOME_URL = 'https://raw.githubusercontent.com/vitejs/awesome-vite/master/README.md';
const awViteMd =
Buffer.from(
await (
await fetch(VITE_AWESOME_URL)
).arrayBuffer()
).toString();
const delimeter = ['## Templates\n', '\n## '];
const offset = awViteMd.indexOf(delimeter[0]) + delimeter[0].length;
const end = awViteMd.indexOf(delimeter[1], offset);
const extract = awViteMd.substring(offset, end).trim();
const portions = extract.split("\n#### ");
const linePattern = /(\[(.*)\])(\((.*)\)) - (.*)/;
portions.forEach(portion => {
const lines = portion.trim().split('\n');
const category = lines[0];
manifest.push(...lines.slice(2).map(line => {
console.log(line.match(linePattern));
const [string, , name, , url, desc] = line.match(linePattern);
const delimiter = /, and | and |, |\s\+\s|\+/;
const description = desc.replace(/\.+$/, "");
return {
framework: category.toLowerCase(),
name,
url,
id: new URL(url).pathname.slice(1),
description,
tokens: description.split(delimiter).map(token => token.trim().replace())
};
}));
});
console.log(chalk.greenBright('_'), `Fetched ${manifest.length} templates`);
return manifest;
}
const manifest = await makeManifest();
fs.writeFileSync(`./${MANIFEST_FILE_NAME}`, JSON.stringify(manifest));
console.log(chalk.greenBright('_'), "Done writing to", chalk.greenBright(MANIFEST_FILE_NAME), "\n");