2021-05-27 15:24:56 +02:00
|
|
|
import { readFile } from 'fs-extra';
|
|
|
|
import { insertContentIntoFile, rootDir } from './tool-utils';
|
|
|
|
import markdownUtils, { MarkdownTableHeader, MarkdownTableJustify, MarkdownTableRow } from '@joplin/lib/markdownUtils';
|
2021-07-26 19:21:19 +02:00
|
|
|
import { GithubSponsor, OrgSponsor, Sponsors } from './website/utils/types';
|
2021-12-19 09:53:19 +02:00
|
|
|
const { escapeHtml } = require('@joplin/lib/string-utils');
|
2021-05-27 15:24:56 +02:00
|
|
|
|
|
|
|
const readmePath = `${rootDir}/README.md`;
|
|
|
|
const sponsorsPath = `${rootDir}/packages/tools/sponsors.json`;
|
|
|
|
|
2021-07-26 19:21:19 +02:00
|
|
|
async function createGitHubSponsorTable(sponsors: GithubSponsor[]): Promise<string> {
|
|
|
|
sponsors = sponsors.slice();
|
2021-05-27 15:24:56 +02:00
|
|
|
|
|
|
|
sponsors.sort((a, b) => {
|
|
|
|
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : +1;
|
|
|
|
});
|
|
|
|
|
|
|
|
const sponsorsPerRow = 4;
|
|
|
|
|
|
|
|
const headers: MarkdownTableHeader[] = [];
|
|
|
|
|
|
|
|
for (let colIndex = 0; colIndex < sponsorsPerRow; colIndex++) {
|
|
|
|
headers.push({
|
|
|
|
label: '',
|
|
|
|
name: `col${colIndex}`,
|
|
|
|
disableEscape: true,
|
|
|
|
justify: MarkdownTableJustify.Center,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const rows: MarkdownTableRow[] = [];
|
|
|
|
|
|
|
|
let sponsorIndex = 0;
|
|
|
|
for (let rowIndex = 0; rowIndex < 9999; rowIndex++) {
|
|
|
|
let sponsor = null;
|
|
|
|
const row: MarkdownTableRow = {};
|
|
|
|
for (let colIndex = 0; colIndex < sponsorsPerRow; colIndex++) {
|
|
|
|
sponsor = sponsors[sponsorIndex];
|
|
|
|
sponsorIndex++;
|
|
|
|
if (!sponsor) break;
|
|
|
|
|
|
|
|
row[`col${colIndex}`] = `<img width="50" src="https://avatars2.githubusercontent.com/u/${sponsor.id}?s=96&v=4"/></br>[${sponsor.name}](https://github.com/${sponsor.name})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object.keys(row)) rows.push(row);
|
|
|
|
|
|
|
|
if (!sponsor) break;
|
|
|
|
}
|
|
|
|
|
2021-07-26 19:21:19 +02:00
|
|
|
return markdownUtils.createMarkdownTable(headers, rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function createOrgSponsorTable(sponsors: OrgSponsor[]): Promise<string> {
|
2021-12-19 09:53:19 +02:00
|
|
|
// sponsors = ArrayUtils.shuffle(sponsors);
|
2021-07-26 19:21:19 +02:00
|
|
|
|
|
|
|
const output: string[] = [];
|
|
|
|
|
|
|
|
for (const sponsor of sponsors) {
|
|
|
|
output.push(`<a href="${escapeHtml(sponsor.url)}"><img title="${escapeHtml(sponsor.title)}" width="256" src="https://joplinapp.org/images/sponsors/${escapeHtml(sponsor.imageName)}"/></a>`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return output.join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const sponsors: Sponsors = JSON.parse(await readFile(sponsorsPath, 'utf8'));
|
|
|
|
|
|
|
|
await insertContentIntoFile(
|
|
|
|
readmePath,
|
|
|
|
'<!-- SPONSORS-GITHUB -->\n',
|
|
|
|
'\n<!-- SPONSORS-GITHUB -->',
|
|
|
|
await createGitHubSponsorTable(sponsors.github)
|
|
|
|
);
|
2021-05-27 15:24:56 +02:00
|
|
|
|
|
|
|
await insertContentIntoFile(
|
|
|
|
readmePath,
|
2021-07-26 19:21:19 +02:00
|
|
|
'<!-- SPONSORS-ORG -->\n',
|
|
|
|
'\n<!-- SPONSORS-ORG -->',
|
|
|
|
await createOrgSponsorTable(sponsors.orgs)
|
2021-05-27 15:24:56 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error('Fatal error', error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|