UNPKG

12.5 kBJavaScriptView Raw
1const fs = require('fs');
2const _ = require('lodash');
3
4module.exports = (options, pkg) => {
5 options.replacer = options.replacer || {}
6 let replacer = 'corifeus';
7 if (typeof (options.replacer) === 'string') {
8 replacer = options.replacer;
9 } else if (options.replacer.hasOwnProperty('type')) {
10 replacer = options.replacer.type;
11 }
12
13
14 const commonBuild = `
15
16[![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://paypal.me/patrikx3) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Corifeus @ Facebook](https://img.shields.io/badge/Facebook-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) `
17
18 let opencollectiveHeader = ''
19 let opencollectiveFooter = ''
20 pkg.corifeus.opencollective = false;
21 if (options.replacer.hasOwnProperty('opencollective') && options.replacer.opencollective === true) {
22 pkg.corifeus.opencollective = true;
23
24 pkg.collective = {
25 type: "opencollective",
26 url: `https://opencollective.com/${pkg.name}`
27 }
28
29 opencollectiveHeader = ` [![Backers on Open Collective](https://opencollective.com/\${pkg.name}/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/\${pkg.name}/sponsors/badge.svg)](#sponsors)`
30 opencollectiveFooter = `
31
32# Open collective
33
34## Contributors
35
36This project exists thanks to all the people who contribute.
37
38<a href="https://github.com/patrikx3/\${pkg.corifeus.reponame}/graphs/contributors"><img src="https://opencollective.com/\${pkg.name}/contributors.svg?width=890&button=false" /></a>
39
40
41## Backers
42
43Thank you to all our backers!
44
45🙏 [Become a backer](https://opencollective.com/\${pkg.name}#backer)
46
47<a href="https://opencollective.com/\${pkg.name}#backers" target="_blank"><img src="https://opencollective.com/\${pkg.name}/backers.svg?width=890"></a>
48
49
50## Sponsors
51
52Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
53
54🙏 [Become a sponsor](https://opencollective.com/\${pkg.name}#sponsor)
55
56<a href="https://opencollective.com/\${pkg.name}/sponsor/0/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/0/avatar.svg"></a>
57<a href="https://opencollective.com/\${pkg.name}/sponsor/1/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/1/avatar.svg"></a>
58<a href="https://opencollective.com/\${pkg.name}/sponsor/2/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/2/avatar.svg"></a>
59<a href="https://opencollective.com/\${pkg.name}/sponsor/3/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/3/avatar.svg"></a>
60<a href="https://opencollective.com/\${pkg.name}/sponsor/4/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/4/avatar.svg"></a>
61<a href="https://opencollective.com/\${pkg.name}/sponsor/5/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/5/avatar.svg"></a>
62<a href="https://opencollective.com/\${pkg.name}/sponsor/6/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/6/avatar.svg"></a>
63<a href="https://opencollective.com/\${pkg.name}/sponsor/7/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/7/avatar.svg"></a>
64<a href="https://opencollective.com/\${pkg.name}/sponsor/8/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/8/avatar.svg"></a>
65<a href="https://opencollective.com/\${pkg.name}/sponsor/9/website" target="_blank"><img src="https://opencollective.com/\${pkg.name}/sponsor/9/avatar.svg"></a>
66
67`
68 }
69
70 const replaceFiles = [
71 'artifacts/**/*.md',
72 'docs/**/*.md',
73 '*.md',
74 '!node_modules',
75 '!build',
76 '!LICENSE.md',
77 '!readme.md',
78 '!README.md',
79 ]
80
81 const defaultHeader = {
82 header: true,
83 replace: `
84# \${pkg.description}
85
86 `,
87 files: replaceFiles
88 }
89
90
91 let jetbrainsUrl = 'https://www.jetbrains.com/?from=patrikx3'
92 const defaultFooter = {
93 footer: true,
94 replace: `
95---
96
97🙏 This is an open-source project. Star this repository, if you like it, or even donate to maintain the servers and the development. Thank you so much!
98
99Possible, this server, rarely, is down, please, hang on for 15-30 minutes and the server will be back up.
100
101All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://corifeus.com)) could have minor errors, since I am developing in my free time. However, it is usually stable.
102
103**Note about versioning:** Versions are cut in Major.Minor.Patch schema. Major is always the current year. Minor is either 4 (January - June) or 10 (July - December). Patch is incremental by every build. If there is a breaking change, it should be noted in the readme.
104
105
106---
107
108[**\${pkg.name.toUpperCase()}**](https://corifeus.com/\${git.repo === 'corifeus' ? 'matrix' : git.repo}) Build v\${pkg.version}
109
110[![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software)
111
112
113## P3X Sponsor
114
115[IntelliJ - The most intelligent Java IDE](${jetbrainsUrl})
116
117[![JetBrains](https://cdn.corifeus.com/assets/svg/jetbrains-logo.svg)](${jetbrainsUrl})
118
119
120${opencollectiveFooter}
121`,
122 files: replaceFiles
123 };
124
125 let angularVersion = '';
126 let nodeJsInfo = `### NodeJs LTS Version Requirement
127\`\`\`txt
128\${pkg.engines.node}
129\`\`\`
130
131### Built on NodeJs
132\`\`\`txt
133${process.version}
134\`\`\`
135
136The \`\`\`async\`\`\` and \`\`\`await\`\`\` keywords are required. Only the latest LTS variant is supported.
137
138Install NodeJs:
139https://nodejs.org/en/download/package-manager/`;
140
141 if (options.replacer.hasOwnProperty('nodejsinfo') && options.replacer.nodejsinfo === false) {
142 nodeJsInfo = '';
143 }
144
145
146 const angularPkgPath = `${process.cwd()}/node_modules/@angular/core/package.json`;
147 if (fs.existsSync(angularPkgPath)) {
148 const angularPkg = JSON.parse(fs.readFileSync(angularPkgPath).toString());
149 angularVersion = `
150# Built on Angular
151
152\`\`\`text
153${angularPkg.version}
154\`\`\`
155
156`
157 }
158
159 const hideNodeVersion = options.hasOwnProperty('replacer') && options.replacer.node === false;
160
161 let hideBuild = options.hasOwnProperty('replacer') && options.replacer.build === false;
162
163 pkg.corifeus.build = !hideBuild;
164
165// let build = hideBuild ? '' : `[![Build Status](https://travis-ci.com/patrikx3/\${git.repo}.svg?branch=master)](https://travis-ci.com/patrikx3/\${git.repo}) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master)`
166
167 let build = commonBuild
168
169 // https://api.travis-ci.com/patrikx3/redis-ui-material.svg?branch=master
170 build += hideBuild ? '' : `[![Build Status](https://api.travis-ci.com/patrikx3/\${git.repo}.svg?branch=master)](https://travis-ci.com/patrikx3/\${git.repo})
171[![Uptime Robot ratio (30 days)](https://img.shields.io/uptimerobot/ratio/m780749701-41bcade28c1ea8154eda7cca.svg)](https://uptimerobot.patrikx3.com/)
172
173`
174
175 build += opencollectiveHeader
176
177 const domainInfo = `
178
179**Bugs are evident™ - MATRIX️**
180 `
181
182 let nodeVersion = hideNodeVersion ? `# \${pkg.description} v\${pkg.version}
183
184${domainInfo}
185
186# Description
187
188` : `# \${pkg.description} v\${pkg.version}
189
190${domainInfo}
191
192${nodeJsInfo}
193
194${angularVersion}
195
196# Description
197`
198
199 const footerMain = _.clone(defaultFooter);
200
201 footerMain.files = [
202 'readme.md',
203 'README.md',
204 ];
205 switch (replacer) {
206 case 'corifeus':
207 options.config['cory-replace'] = {
208 headerMain: {
209 header: true,
210 replace: `
211 ${build}
212
213${build.trim() === '' ? '' : '---'}
214${nodeVersion}
215 `,
216 files: [
217 'readme.md',
218 'README.md',
219 ]
220 },
221 footerMain: footerMain,
222 header: defaultHeader,
223 footer: defaultFooter
224 }
225 break;
226
227 case 'p3x':
228 let nonEmptyP3x = '';
229 if (!options.empty) {
230 nonEmptyP3x = `${build}
231
232`
233 }
234
235 options.config['cory-replace'] = {
236 headerMain: {
237 header: true,
238 /* [![Trello](https://img.shields.io/badge/Trello-p3x-026aa7.svg)](https://trello.com/b/gqKHzZGy/p3x)
239 */
240
241 replace: `
242 ${nonEmptyP3x}
243
244${nodeVersion}
245 `,
246 files: [
247 'readme.md',
248 'README.md',
249 ]
250 },
251 footerMain: footerMain,
252 header: defaultHeader,
253 footer: defaultFooter
254 };
255 break;
256
257 case 'build':
258 case 'lede':
259 case 'openwrt':
260 let nonEmptyBuild = '';
261 if (!options.empty) {
262 /*
263 nonEmptyBuild = `[![Build Status](https://travis-ci.com/patrikx3/\${git.repo}.svg?branch=master)](https://travis-ci.com/patrikx3/\${git.repo}) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master)
264
265 # \${pkg.description}
266
267 `
268 */
269 nonEmptyBuild = `[![Build Status](https://travis-ci.com/patrikx3/\${git.repo}.svg?branch=master)](https://travis-ci.com/patrikx3/\${git.repo}) [![Uptime Robot ratio (30 days)](https://img.shields.io/uptimerobot/ratio/m780749701-41bcade28c1ea8154eda7cca.svg)](https://uptimerobot.patrikx3.com/)
270
271# \${pkg.description}
272
273`
274 }
275
276 if (replacer === 'openwrt') {
277 nonEmptyBuild += `
278
279`
280 }
281
282 options.config['cory-replace'] = {
283 headerMain: {
284 header: true,
285 /* [![Trello](https://img.shields.io/badge/Trello-p3x-026aa7.svg)](https://trello.com/b/gqKHzZGy/p3x)
286 */
287
288 replace: `
289 ${commonBuild} ${nonEmptyBuild}
290 `,
291 files: [
292 'readme.md',
293 'README.md',
294 ]
295 },
296 footerMain: footerMain,
297 header: defaultHeader,
298 footer: defaultFooter
299 };
300 break;
301
302 case 'home':
303 options.config['cory-replace'] = {
304 header: {
305 header: true,
306 replace: `
307# \${pkg.description}
308
309 `,
310 files: [
311 'readme.md',
312 'README.md',
313 ]
314 },
315 footer: defaultFooter,
316 }
317 break;
318
319 default:
320 throw new Error(`unknown replacer ${options.replacer}`)
321 }
322
323 if (options.replacer.hasOwnProperty('npmio') && options.replacer.npmio === true && options.config['cory-replace'].hasOwnProperty('headerMain')) {
324 const replace = options.config['cory-replace'].headerMain.replace;
325
326 const append = replace.substring(replace.indexOf('---'));
327
328 options.config['cory-replace'].headerMain.replace = replace.substring(0, replace.indexOf('---')) + `
329[![NPM](https://nodei.co/npm/\${pkg.name}.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/\${pkg.name}/)
330` + append
331 }
332
333}