|
| 1 | +import { getPkg } from "../_utils"; |
| 2 | +import { defineGenerator } from "../generator"; |
| 3 | + |
| 4 | +export const contributors = defineGenerator({ |
| 5 | + name: "contributors", |
| 6 | + async generate({ config, args }) { |
| 7 | + const { github } = await getPkg(config.dir, args); |
| 8 | + |
| 9 | + if (!github) { |
| 10 | + throw new Error("`github` is required!"); |
| 11 | + } |
| 12 | + |
| 13 | + const lines: string[] = []; |
| 14 | + |
| 15 | + // License |
| 16 | + if (typeof args.license === "string") { |
| 17 | + lines.push( |
| 18 | + `Published under the [${args.license.toUpperCase()}](https://github.com/${github}/blob/main/LICENSE) license.`, |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + // Made by |
| 23 | + let madeBy = `[community](https://github.com/${github}/graphs/contributors) 💛`; |
| 24 | + if (typeof args.author === "string") { |
| 25 | + const authors = args.author |
| 26 | + .split(",") |
| 27 | + .map((author) => author.trim()) |
| 28 | + .map((user) => `[@${user}](https://github.com/${user})`) |
| 29 | + .join(", "); |
| 30 | + if (authors.length > 0) { |
| 31 | + madeBy = `${authors} and ${madeBy}`; |
| 32 | + } |
| 33 | + } |
| 34 | + lines.push(`Made by ${madeBy}`); |
| 35 | + |
| 36 | + // Contributors |
| 37 | + const params = [["repo", github]]; |
| 38 | + if (args.max) { |
| 39 | + params.push(["max", args.max]); |
| 40 | + } |
| 41 | + if (args.anon) { |
| 42 | + params.push(["anon", args.anon]); |
| 43 | + } |
| 44 | + const paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&"); |
| 45 | + lines.push( |
| 46 | + `<br><br>`, |
| 47 | + `<a href="https://github.com/${github}/graphs/contributors">`, |
| 48 | + `<img src="https://contrib.rocks/image?${paramsStr}" />`, |
| 49 | + `</a>`, |
| 50 | + ); |
| 51 | + |
| 52 | + return { |
| 53 | + contents: lines.join("\n"), |
| 54 | + }; |
| 55 | + }, |
| 56 | +}); |
0 commit comments