[Various] New env JS file, AuthorGen
This commit is contained in:
parent
f2ac90299c
commit
ea51962e77
|
@ -1,9 +1,6 @@
|
||||||
node_modules
|
node_modules
|
||||||
.cache
|
.cache
|
||||||
|
|
||||||
clones
|
clones
|
||||||
src/gh_pat.json
|
src/env.js
|
||||||
# dist
|
|
||||||
|
|
||||||
devDist
|
devDist
|
||||||
devTemp
|
devTemp
|
||||||
|
|
11
README.md
11
README.md
|
@ -2,4 +2,13 @@
|
||||||
|
|
||||||
Builder for Module Store v2.
|
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`.**
|
To run this yourself, you **need** to:
|
||||||
|
1. [Get your own GitHub Personal Access Token](https://docs.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)
|
||||||
|
2. Get a Discord bot token
|
||||||
|
3. Make a `src/env.js` file like:
|
||||||
|
```js
|
||||||
|
export default {
|
||||||
|
github: '<your github pat>',
|
||||||
|
discord: '<your discord bot token>
|
||||||
|
}
|
||||||
|
```
|
|
@ -0,0 +1,25 @@
|
||||||
|
import Env from './env.js';
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const userCache = {};
|
||||||
|
|
||||||
|
const getUser = async (id) => userCache[id] || (userCache[id] = (await axios.get(`https://discord.com/api/v9/users/${id}`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bot ${Env.discord}`
|
||||||
|
}
|
||||||
|
})).data);
|
||||||
|
|
||||||
|
export default async (id) => {
|
||||||
|
const user = await getUser(id);
|
||||||
|
|
||||||
|
console.log(user);
|
||||||
|
|
||||||
|
return { // Use semi-minified keys as to avoid size
|
||||||
|
i: id, // id
|
||||||
|
|
||||||
|
n: `${user.username}#${user.discriminator}`, // name
|
||||||
|
|
||||||
|
a: user.avatar // avatar
|
||||||
|
}
|
||||||
|
};
|
20
src/index.js
20
src/index.js
|
@ -1,23 +1,23 @@
|
||||||
import ModuleRepos from './modules/index.js';
|
import ModuleRepos from './modules/index.js';
|
||||||
|
|
||||||
import AutoTag from './autoTag.js';
|
import AutoTag from './autoTag.js';
|
||||||
import WebhookSend from './webhook.js';
|
import WebhookSend from './webhook.js';
|
||||||
import ImageCDN from './imageCdn.js';
|
import ImageCDN from './imageCdn.js';
|
||||||
|
import authorGen from './authorGen.js';
|
||||||
|
|
||||||
import Parcel from 'parcel-bundler';
|
import Parcel from 'parcel-bundler';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import glob from 'glob';
|
import glob from 'glob';
|
||||||
|
|
||||||
import { rmSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, existsSync, rmdirSync } from 'fs';
|
import { rmSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, existsSync } from 'fs';
|
||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
|
|
||||||
import { dirname, sep } from 'path';
|
import { dirname, sep } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
let file;
|
|
||||||
let githubPAT;
|
|
||||||
try {
|
try {
|
||||||
file = JSON.parse(readFileSync('./gh_pat.json'));
|
import Env from './env.js';
|
||||||
githubPAT = file.token;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code !== 'ENOENT') throw error;
|
if (error.code !== 'ENOENT') throw error;
|
||||||
githubPAT = process.env.GHTOKEN;
|
githubPAT = process.env.GHTOKEN;
|
||||||
|
@ -80,7 +80,7 @@ const getGithubInfo = async (repo) => {
|
||||||
|
|
||||||
const info = (await axios.get(`https://api.github.com/repos/${repo}`, {
|
const info = (await axios.get(`https://api.github.com/repos/${repo}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `token ${githubPAT}`
|
'Authorization': `token ${Env.github}`
|
||||||
}
|
}
|
||||||
})).data;
|
})).data;
|
||||||
|
|
||||||
|
@ -222,6 +222,14 @@ for (const parentRepo of ModuleRepos) {
|
||||||
|
|
||||||
manifestJson.images = await ImageCDN(manifestJson);
|
manifestJson.images = await ImageCDN(manifestJson);
|
||||||
|
|
||||||
|
manifestJson.authors = await Promise.all(manifestJson.authors.map(async (x) => {
|
||||||
|
if (x.match(/^[0-9]{17,18}$/)) {
|
||||||
|
return await authorGen(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}));
|
||||||
|
|
||||||
moduleJson.modules.push(manifestJson);
|
moduleJson.modules.push(manifestJson);
|
||||||
|
|
||||||
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
||||||
|
|
Loading…
Reference in New Issue