mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.8 KiB
63 lines
1.8 KiB
6 years ago
|
require('dotenv/config');
|
||
6 years ago
|
const fs = require('fs');
|
||
|
const fetch = require('node-fetch');
|
||
6 years ago
|
const Jimp = require('jimp');
|
||
6 years ago
|
|
||
3 years ago
|
const force = process.env.FORCE_UPDATE === 'true';
|
||
|
|
||
6 years ago
|
process.chdir(__dirname);
|
||
|
|
||
3 years ago
|
const outputFile = `../src/routes/_contributors.js`;
|
||
|
if (!force && fs.existsSync(outputFile)) {
|
||
|
console.info(`[update/contributors] ${outputFile} exists. Skipping`);
|
||
|
process.exit(0);
|
||
|
}
|
||
|
|
||
6 years ago
|
const base = `https://api.github.com/repos/sveltejs/svelte/contributors`;
|
||
|
const { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } = process.env;
|
||
|
|
||
6 years ago
|
const SIZE = 64;
|
||
6 years ago
|
|
||
6 years ago
|
async function main() {
|
||
6 years ago
|
const contributors = [];
|
||
|
let page = 1;
|
||
|
|
||
|
while (true) {
|
||
|
const res = await fetch(`${base}?client_id=${GITHUB_CLIENT_ID}&client_secret=${GITHUB_CLIENT_SECRET}&per_page=100&page=${page++}`);
|
||
|
const list = await res.json();
|
||
|
|
||
|
if (list.length === 0) break;
|
||
|
|
||
|
contributors.push(...list);
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
const authors = contributors
|
||
4 years ago
|
.filter(({ login }) => !login.includes('[bot]'))
|
||
6 years ago
|
.sort((a, b) => b.contributions - a.contributions);
|
||
6 years ago
|
|
||
|
const sprite = new Jimp(SIZE * authors.length, SIZE);
|
||
|
|
||
|
for (let i = 0; i < authors.length; i += 1) {
|
||
|
const author = authors[i];
|
||
|
console.log(`${i + 1} / ${authors.length}: ${author.login}`);
|
||
|
|
||
|
const image_data = await fetch(author.avatar_url);
|
||
|
const buffer = await image_data.arrayBuffer();
|
||
|
|
||
|
const image = await Jimp.read(buffer);
|
||
|
image.resize(SIZE, SIZE);
|
||
|
|
||
|
sprite.composite(image, i * SIZE, 0);
|
||
|
}
|
||
|
|
||
|
await sprite.quality(80).write(`../static/contributors.jpg`);
|
||
5 years ago
|
// TODO: Optimizing the static/contributors.jpg image should probably get automated as well
|
||
5 years ago
|
console.log('remember to additionally optimize the resulting /static/contributors.jpg image file via e.g. https://squoosh.app ');
|
||
6 years ago
|
|
||
|
const str = `[\n\t${authors.map(a => `'${a.login}'`).join(',\n\t')}\n]`;
|
||
|
|
||
3 years ago
|
fs.writeFileSync(outputFile, `export default ${str};`);
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
main();
|