1 | import { getPeopleHTML, getFileUrl, getLink } from './util.js'
|
2 | import { getBadgesInCategory } from './badge.js'
|
3 | import type { Github, FilenamesForReadmeFiles } from './types'
|
4 | import type Fellow from 'fellow'
|
5 | import type { BadgesField } from 'badges'
|
6 |
|
7 | function getSponsorsText(data: {
|
8 | badges: BadgesField
|
9 | sponsors: Fellow[]
|
10 | github: Github
|
11 | }): string {
|
12 | let result = ''
|
13 |
|
14 | if (data.sponsors.length === 0) {
|
15 |
|
16 | result +=
|
17 | 'No sponsors yet! Will you be the first?\n\n' +
|
18 | getBadgesInCategory('funding', data)
|
19 | } else {
|
20 | result +=
|
21 | 'These amazing people have contributed finances to this project:\n\n' +
|
22 | getPeopleHTML(data.sponsors) +
|
23 | `\n\nBecome a sponsor!\n\n${getBadgesInCategory('funding', data)}`
|
24 | }
|
25 |
|
26 | return result
|
27 | }
|
28 |
|
29 | function getMaintainersText(data: {
|
30 | maintainers: Fellow[]
|
31 | github: Github
|
32 | }): string {
|
33 | let result = ''
|
34 |
|
35 | if (data.maintainers.length === 0) {
|
36 |
|
37 | result += 'No maintainers yet! Will you be the first?'
|
38 | } else {
|
39 | result +=
|
40 | 'These amazing people are maintaining this project:\n\n' +
|
41 | getPeopleHTML(data.maintainers, {
|
42 | displayContributions: true,
|
43 | githubRepoSlug: data.github.slug,
|
44 | })
|
45 | }
|
46 |
|
47 | return result
|
48 | }
|
49 |
|
50 | function getContributeLink(
|
51 | data: { filenamesForReadmeFiles: FilenamesForReadmeFiles; github: Github },
|
52 | optional = false
|
53 | ): string {
|
54 |
|
55 | const file = data.filenamesForReadmeFiles.contributing
|
56 | if (!file) {
|
57 | if (optional) {
|
58 | return ''
|
59 | } else {
|
60 | throw new Error(
|
61 | 'Contributing section requires a CONTRIBUTING file to exist'
|
62 | )
|
63 | }
|
64 | }
|
65 | const url = getFileUrl(data, file)
|
66 | const text = `Discover how you can contribute by heading on over to the <code>${file}</code> file.`
|
67 |
|
68 |
|
69 | return getLink({ url, text })
|
70 | }
|
71 |
|
72 | function getContributorsText(data: {
|
73 | filenamesForReadmeFiles: FilenamesForReadmeFiles
|
74 | contributors: Fellow[]
|
75 | github: Github
|
76 | }): string {
|
77 | let result = ''
|
78 |
|
79 | if (data.contributors.length === 0) {
|
80 |
|
81 | result +=
|
82 | 'No contributors yet! Will you be the first?' +
|
83 | `\n\n${getContributeLink(data, true)}`
|
84 | } else {
|
85 | result +=
|
86 | 'These amazing people have contributed code to this project:\n\n' +
|
87 | getPeopleHTML(data.contributors, {
|
88 | displayContributions: true,
|
89 | githubRepoSlug: data.github.slug,
|
90 | }) +
|
91 | `\n\n${getContributeLink(data, true)}`
|
92 | }
|
93 |
|
94 | return result
|
95 | }
|
96 |
|
97 | interface BackerOptions {
|
98 | filenamesForReadmeFiles: FilenamesForReadmeFiles
|
99 | badges: BadgesField
|
100 | maintainers: Fellow[]
|
101 | sponsors: Fellow[]
|
102 | contributors: Fellow[]
|
103 | github: Github
|
104 | }
|
105 | export function getBackerSection(data: BackerOptions): string {
|
106 |
|
107 | const result = [
|
108 | '<h2>Backers</h2>',
|
109 | '',
|
110 | '<h3>Maintainers</h3>',
|
111 | '',
|
112 | getMaintainersText(data),
|
113 | '',
|
114 | '<h3>Sponsors</h3>',
|
115 | '',
|
116 | getSponsorsText(data),
|
117 | '',
|
118 | '<h3>Contributors</h3>',
|
119 | '',
|
120 | getContributorsText(data),
|
121 | ].join('\n')
|
122 |
|
123 |
|
124 | return result
|
125 | }
|
126 |
|
127 | export function getBackerFile(data: BackerOptions): string {
|
128 |
|
129 | const result = [
|
130 | '<h1>Backers</h1>',
|
131 | '',
|
132 | '<h2>Maintainers</h2>',
|
133 | '',
|
134 | getMaintainersText(data),
|
135 | '',
|
136 | '<h2>Sponsors</h2>',
|
137 | '',
|
138 | getSponsorsText(data),
|
139 | '',
|
140 | '<h2>Contributors</h2>',
|
141 | '',
|
142 | getContributorsText(data),
|
143 | ].join('\n')
|
144 |
|
145 |
|
146 | return result
|
147 | }
|
148 |
|
149 | export function getContributeSection(data: {
|
150 | filenamesForReadmeFiles: FilenamesForReadmeFiles
|
151 | github: Github
|
152 | }): string {
|
153 |
|
154 | const result = ['<h2>Contribute</h2>', '', getContributeLink(data)].join('\n')
|
155 |
|
156 |
|
157 | return result
|
158 | }
|