2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00
Files
axios/bin/injectContributorsList.js
T
Dmitriy Mozgovoy 46085e6ffc chore(ci): fix release action;
* chore(ci): Add release-it script;
* fix(utils): redesigned logic for obtaining the global link;;
* chore(git): updated .gitignore;
chore(npm): updated .npmignore;
* chore(git): fix husky prepare script;
* chore(github): reworked npm release action step;
* chore(ci): add CHANGELOG.md contributors section generator;
* chore(deps): add `auto-changelog` to package.json;
2022-12-20 20:45:24 +02:00

48 lines
1.3 KiB
JavaScript

import fs from 'fs/promises';
import path from 'path';
import {renderContributorsList} from './contributors.js';
import asyncReplace from 'string-replace-async';
import {fileURLToPath} from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const injectContributors = async (infile, injector) => {
console.log(`Checking contributors sections in ${infile}`);
infile = path.resolve(__dirname, infile);
const content = String(await fs.readFile(infile));
const headerRE = /^##\s+\[([-_\d.\w]+)]\s+-.+/mig;
const contributorsRE = /^\s*### Contributors/mi;
let tag;
let index = 0;
const newContent = await asyncReplace(content, headerRE, async (match, nextTag, offset) => {
const releaseContent = content.slice(index, offset);
const hasContributorsSection = contributorsRE.test(releaseContent);
const currentTag = tag;
tag = nextTag;
index = offset + match.length;
if(currentTag && !hasContributorsSection) {
console.log(`Adding contributors for ${currentTag}`);
return (await injector(currentTag)) + match;
}
return match;
});
await fs.writeFile(infile, newContent);
}
await injectContributors(
'../CHANGELOG.md',
(tag) => renderContributorsList(tag, true, path.resolve(__dirname, '../templates/contributors.hbs')
));