1 // Credit for the script goes to svelte:
2 // https://github.com/sveltejs/svelte/blob/ce3a5791258ec6ecf8c1ea022cb871afe805a45c/site/scripts/get-contributors.js
4 const fs = require("fs")
5 const fetch = require("node-fetch")
6 const Jimp = require("jimp")
8 process.chdir(__dirname)
10 const base = `https://api.github.com/repos/ajv-validator/ajv/contributors`
11 const {GH_TOKEN_PUBLIC} = process.env
15 async function main() {
16 const contributors = []
19 // eslint-disable-next-line no-constant-condition
21 const res = await fetch(`${base}?per_page=100&page=${page++}`, {
22 headers: {Authorization: `token ${GH_TOKEN_PUBLIC}`},
24 const list = await res.json()
25 if (list.length === 0) break
26 contributors.push(...list)
29 const bots = ["dependabot-preview[bot]", "greenkeeper[bot]", "greenkeeperio-bot"]
31 const authors = contributors
32 .filter((a) => !bots.includes(a.login))
33 .sort((a, b) => b.contributions - a.contributions)
35 const sprite = new Jimp(SIZE * authors.length, SIZE)
37 for (let i = 0; i < authors.length; i += 1) {
38 const author = authors[i]
39 console.log(`${i + 1} / ${authors.length}: ${author.login}`)
40 const image_data = await fetch(author.avatar_url)
41 const buffer = await image_data.arrayBuffer()
42 const image = await Jimp.read(buffer)
43 image.resize(SIZE, SIZE)
44 sprite.composite(image, i * SIZE, 0)
47 await sprite.quality(80).write(`../docs/.vuepress/components/Contributors/contributors.jpg`)
49 const str = `[\n ${authors.map((a) => `"${a.login}"`).join(",\n ")},\n]\n`
52 `../docs/.vuepress/components/Contributors/_contributors.js`,
53 `module.exports = ${str}`