mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
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;
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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')
|
||||
));
|
||||
Reference in New Issue
Block a user