mirror of
https://github.com/axios/axios.git
synced 2026-04-11 14:21:59 +08:00
* feat: implement prettier and fix all issues * fix: failing tests * fix: implement feedback from codel, ai etc * chore: dont throw in trim function Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * fix: incorrect fix --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
import { renderContributorsList, getTagRef, renderPRsList } from './contributors.js';
|
|
import asyncReplace from 'string-replace-async';
|
|
import { fileURLToPath } from 'url';
|
|
import { colorize } from './helpers/colorize.js';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
const CONTRIBUTORS_TEMPLATE = path.resolve(__dirname, '../templates/contributors.hbs');
|
|
const PRS_TEMPLATE = path.resolve(__dirname, '../templates/prs.hbs');
|
|
|
|
const injectSection = async (name, contributorsRE, injector, infile = '../CHANGELOG.md') => {
|
|
console.log(colorize()`Checking ${name} sections in ${infile}`);
|
|
|
|
infile = path.resolve(__dirname, infile);
|
|
|
|
const content = String(await fs.readFile(infile));
|
|
const headerRE = /^#+\s+\[([-_\d.\w]+)].+?$/gim;
|
|
|
|
let tag;
|
|
let index = 0;
|
|
let isFirstTag = true;
|
|
|
|
const newContent = await asyncReplace(content, headerRE, async (match, nextTag, offset) => {
|
|
const releaseContent = content.slice(index, offset);
|
|
|
|
const hasSection = contributorsRE.test(releaseContent);
|
|
|
|
const currentTag = tag;
|
|
|
|
tag = nextTag;
|
|
index = offset + match.length;
|
|
|
|
if (currentTag) {
|
|
if (hasSection) {
|
|
console.log(colorize()`[${currentTag}]: ✓ OK`);
|
|
} else {
|
|
const target = isFirstTag && !(await getTagRef(currentTag)) ? '' : currentTag;
|
|
|
|
console.log(colorize()`[${currentTag}]: ❌ MISSED` + (!target ? ' (UNRELEASED)' : ''));
|
|
|
|
isFirstTag = false;
|
|
|
|
console.log(`Generating section...`);
|
|
|
|
const section = await injector(target);
|
|
|
|
if (!section) {
|
|
return match;
|
|
}
|
|
|
|
console.log(colorize()`\nRENDERED SECTION [${name}] for [${currentTag}]:`);
|
|
console.log('-------------BEGIN--------------\n');
|
|
console.log(section);
|
|
console.log('--------------END---------------\n');
|
|
|
|
return section + '\n' + match;
|
|
}
|
|
}
|
|
|
|
return match;
|
|
});
|
|
|
|
await fs.writeFile(infile, newContent);
|
|
};
|
|
|
|
await injectSection('PRs', /^\s*### PRs/im, (tag) =>
|
|
tag ? '' : renderPRsList(tag, PRS_TEMPLATE, { awesome_threshold: 5, comments_threshold: 7 })
|
|
);
|
|
|
|
await injectSection('contributors', /^\s*### Contributors/im, (tag) =>
|
|
renderContributorsList(tag, CONTRIBUTORS_TEMPLATE)
|
|
);
|