Add GitHub info to modules.json

This commit is contained in:
Ducko 2021-01-24 10:49:41 +00:00
parent ffb3ed56b9
commit 393f194162
6 changed files with 44 additions and 2 deletions

1
.gitignore vendored
View file

@ -2,4 +2,5 @@ node_modules
.cache
clones
src/gh_pat.js
# dist

View file

@ -1,2 +1,4 @@
# MS2Builder
Builder for Module Store v2.
**To run this yourself, you need to [get your own GitHub Personal Access Token](https://docs.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) and export it in `src/gh_pat.js`.

2
dist/modules.json vendored

File diff suppressed because one or more lines are too long

13
package-lock.json generated
View file

@ -1242,6 +1242,14 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
},
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"babel-plugin-dynamic-import-node": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz",
@ -2800,6 +2808,11 @@
}
}
},
"follow-redirects": {
"version": "1.13.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz",
"integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg=="
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",

View file

@ -17,6 +17,7 @@
},
"homepage": "https://github.com/GooseMod/MS2Builder#readme",
"dependencies": {
"axios": "^0.21.1",
"parcel-bundler": "^1.12.4"
},
"alias": {

View file

@ -1,6 +1,7 @@
import ModuleRepos from './modules.js';
import Parcel from 'parcel-bundler';
import axios from 'axios';
import { rmSync, mkdirSync, readFileSync, writeFileSync, copyFileSync } from 'fs';
import { createHash } from 'crypto';
@ -8,6 +9,8 @@ import { createHash } from 'crypto';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import githubPAT from './gh_pat.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const clonesDir = `${__dirname.replace('/src', '')}/clones`;
@ -38,10 +41,27 @@ const parcelOptions = {
let moduleJson = [];
const githubCache = {};
const getGithubInfo = async (repo) => {
if (githubCache[repo]) return githubCache[repo];
const info = (await axios.get(`https://api.github.com/repos/${repo}`, {
headers: {
'Authorization': `token ${githubPAT}`
}
})).data;
githubCache[repo] = info;
return info;
};
for (const repo of ModuleRepos) {
// console.log(repo);
console.time(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
const githubInfo = await getGithubInfo(repo[0]);
const url = `https://github.com/${repo[0]}.git`;
const commitHash = repo[1];
@ -88,7 +108,12 @@ for (const repo of ModuleRepos) {
version: manifest.version,
tags: manifest.tags,
authors: manifest.authors,
hash: jsHash
hash: jsHash,
github: {
stars: githubInfo.stargazers_count,
repo: repo[0]
}
});
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);