const { readFileSync, writeFileSync } = require('fs'); const { stripIndent } = require('common-tags'); // ************************************************************************** let { users } = require('../USERS.js'); users.sort((a, b) => getCurrentName(a).localeCompare(getCurrentName(b))); // ************************************************************************** const DEFAULT_WIDTH = 46; // ************************************************************************** let table = ''; let row = users.length / 4; let lastNo = users.length % 4; if (lastNo != 0) row += 1; for (let j = 1; j <= row; j++) { let data = ''; data = stripIndent` ${getImg(users[(j - 1) * 4])} ${getImg(users[(j - 1) * 4 + 1])} ${getImg(users[(j - 1) * 4 + 2])} ${getImg(users[(j - 1) * 4 + 3])} ${getName(users[(j - 1) * 4])} ${getName(users[(j - 1) * 4 + 1])} ${getName(users[(j - 1) * 4 + 2])} ${getName(users[(j - 1) * 4 + 3])} `; table += data; } table = ` ${table}
`; // ************************************************************************** const point = ''; const cnPoint = `## 图标`; const enPoint = `## Badge`; // ************************************************************************** const cn = readFileSync('./README.md', 'utf8'); const cnIn = cn.indexOf(point); const cnAfterIn = cn.indexOf(cnPoint); const cnBefore = cn.substring(0, cnIn); const cnAfter = cn.substring(cnAfterIn, cn.length); const newcn = cnBefore + table + cnAfter; writeFileSync('./README.md', newcn); console.log(`🎉 Done cn`); // ************************************************************************** const en = readFileSync('./README.en-US.md', 'utf8'); const enIn = en.indexOf(point); const enAfterIn = en.indexOf(enPoint); const enBefore = en.substring(0, enIn); const enAfter = en.substring(enAfterIn, en.length); const newen = enBefore + table + enAfter; writeFileSync('./README.en-US.md', newen); console.log(`🎉 Done en`); // ************************************************************************** function getImg(o) { if (o) { return ` `; } return ``; } function getImgWidth(o) { if (o) { let width = o.width; if (width === 'auto') { width = ''; } else { width = width ? width : DEFAULT_WIDTH; } return ` width="${width}"`; } return ''; } function getName(o) { if (o) { return `${o.url.split('/').slice(-1)[0]}`; } return ``; } function getCurrentName(o) { if (o) { return o.url.split('/').slice(-1)[0]; } return ``; } // **************************************************************************