minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / scripts / get-contributors.js
1 // Credit for the script goes to svelte:
2 // https://github.com/sveltejs/svelte/blob/ce3a5791258ec6ecf8c1ea022cb871afe805a45c/site/scripts/get-contributors.js
3
4 const fs = require("fs")
5 const fetch = require("node-fetch")
6 const Jimp = require("jimp")
7
8 process.chdir(__dirname)
9
10 const base = `https://api.github.com/repos/ajv-validator/ajv/contributors`
11 const {GH_TOKEN_PUBLIC} = process.env
12
13 const SIZE = 64
14
15 async function main() {
16   const contributors = []
17   let page = 1
18
19   // eslint-disable-next-line no-constant-condition
20   while (true) {
21     const res = await fetch(`${base}?per_page=100&page=${page++}`, {
22       headers: {Authorization: `token ${GH_TOKEN_PUBLIC}`},
23     })
24     const list = await res.json()
25     if (list.length === 0) break
26     contributors.push(...list)
27   }
28
29   const bots = ["dependabot-preview[bot]", "greenkeeper[bot]", "greenkeeperio-bot"]
30
31   const authors = contributors
32     .filter((a) => !bots.includes(a.login))
33     .sort((a, b) => b.contributions - a.contributions)
34
35   const sprite = new Jimp(SIZE * authors.length, SIZE)
36
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)
45   }
46
47   await sprite.quality(80).write(`../docs/.vuepress/components/Contributors/contributors.jpg`)
48
49   const str = `[\n  ${authors.map((a) => `"${a.login}"`).join(",\n  ")},\n]\n`
50
51   fs.writeFileSync(
52     `../docs/.vuepress/components/Contributors/_contributors.js`,
53     `module.exports = ${str}`
54   )
55 }
56
57 main()