mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
71efff6827
* Update eslint config * Applied linter to lib * Applied eslint config to CliClient/app * Removed prettier due to https://github.com/prettier/prettier/pull/4765 * First pass on test units * Applied linter config to test units * Applied eslint config to clipper * Applied to plugin dir * Applied to root of ElectronClient * Applied on RN root * Applied on CLI root * Applied on Clipper root * Applied config to tools * test hook * test hook * test hook * Added pre-commit hook * Applied rule no-trailing-spaces * Make sure root packages are installed when installing sub-dir * Added doc
103 lines
2.3 KiB
JavaScript
103 lines
2.3 KiB
JavaScript
require('app-module-path').addPath(__dirname + '/../ReactNativeClient');
|
|
|
|
'use strict';
|
|
|
|
const request = require('request');
|
|
|
|
const readmePath = __dirname + '/../README.md';
|
|
const { insertContentIntoFile } = require('./tool-utils.js');
|
|
|
|
async function gitHubContributors(page) {
|
|
return new Promise((resolve, reject) => {
|
|
request.get({
|
|
url: 'https://api.github.com/repos/laurent22/joplin/contributors' + (page ? '?page=' + page : ''),
|
|
json: true,
|
|
headers: {'User-Agent': 'Joplin Readme Updater'},
|
|
}, (error, response, data) => {
|
|
if (error) {
|
|
reject(error);
|
|
} else if (response.statusCode !== 200) {
|
|
reject(new Error('Error HTTP ' + response.statusCode));
|
|
} else {
|
|
resolve(data);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function contributorTable(contributors) {
|
|
let rows = [];
|
|
|
|
let row = [];
|
|
rows.push(row);
|
|
let rowLength = 5;
|
|
let contributorIndex = 0;
|
|
while (contributorIndex < contributors.length) {
|
|
const c = contributors[contributorIndex];
|
|
contributorIndex++;
|
|
|
|
const cell = `<img width="50" src="${c.avatar_url}"/></br>[${c.login}](${c.url})`;
|
|
|
|
row.push(cell);
|
|
|
|
if (row.length >= rowLength) {
|
|
row = [];
|
|
rows.push(row);
|
|
}
|
|
}
|
|
|
|
while (rows[rows.length - 1].length < rowLength) rows[rows.length - 1].push('');
|
|
|
|
const header = [];
|
|
const headerLine = [];
|
|
for (let i = 0; i < rowLength; i++) {
|
|
header.push(' ');
|
|
headerLine.push(':---:');
|
|
}
|
|
|
|
const lines = [];
|
|
lines.push('| ' + header.join(' | ') + ' |');
|
|
lines.push('| ' + headerLine.join(' | ') + ' |');
|
|
|
|
for (const row of rows) {
|
|
lines.push('| ' + row.join(' | ') + ' |');
|
|
}
|
|
|
|
return lines.join('\n');
|
|
}
|
|
|
|
async function main(argv) {
|
|
let contributors = [];
|
|
let pageIndex = 0;
|
|
const doneNames = [];
|
|
while (true) {
|
|
const response = await gitHubContributors(pageIndex);
|
|
pageIndex++;
|
|
if (!response.length) break;
|
|
|
|
// Remove duplicates
|
|
const temp = [];
|
|
for (const r of response) {
|
|
if (doneNames.indexOf(r.login) >= 0) continue;
|
|
doneNames.push(r.login);
|
|
temp.push(r);
|
|
}
|
|
|
|
contributors = contributors.concat(temp);
|
|
}
|
|
|
|
const tableHtml = contributorTable(contributors);
|
|
|
|
await insertContentIntoFile(
|
|
readmePath,
|
|
'<!-- CONTRIBUTORS-TABLE-AUTO-GENERATED -->\n',
|
|
'\n<!-- CONTRIBUTORS-TABLE-AUTO-GENERATED -->',
|
|
tableHtml
|
|
);
|
|
}
|
|
|
|
main(process.argv).catch((error) => {
|
|
console.error('Fatal error', error);
|
|
process.exit(1);
|
|
});
|