Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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;
- Loading branch information
1 parent
f12d01e
commit 46085e6
Showing
10 changed files
with
275 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
**/.* | ||
*.iml | ||
coverage/ | ||
examples/ | ||
node_modules/ | ||
typings/ | ||
sandbox/ | ||
test/ | ||
bower.json | ||
CODE_OF_CONDUCT.md | ||
COLLABORATOR_GUIDE.md | ||
CONTRIBUTING.md | ||
COOKBOOK.md | ||
ECOSYSTEM.md | ||
Gruntfile.js | ||
karma.conf.js | ||
webpack.*.js | ||
sauce_connect.log | ||
backup/ | ||
**/* | ||
!/dist/** | ||
!/lib/** | ||
!index.js | ||
!index.d.ts | ||
!index.d.cts | ||
!CHANGELOG.md | ||
!LICENSE | ||
!MIGRATION_GUIDE.md | ||
!README.md | ||
!SECURITY.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import axios from "../index.js"; | ||
import util from "util"; | ||
import cp from "child_process"; | ||
import Handlebars from "handlebars"; | ||
import fs from "fs/promises"; | ||
|
||
const exec = util.promisify(cp.exec); | ||
|
||
const removeExtraLineBreaks = (str) => str.replace(/(?:\r\n|\r|\n){3,}/gm, '\r\n\r\n'); | ||
|
||
const cleanTemplate = template => template | ||
.replace(/\n +/g, '\n') | ||
.replace(/^ +/, '') | ||
.replace(/\n\n\n+/g, '\n\n') | ||
.replace(/\n\n$/, '\n'); | ||
|
||
const getUserInfo = ((userCache) => async (email) => { | ||
if (userCache[email] !== undefined) { | ||
return userCache[email]; | ||
} | ||
try { | ||
const {data: {items: [user]}} = await axios.get(`https://api.github.com/search/users?q=${email}`); | ||
|
||
return (userCache[email] = user ? { | ||
...user, | ||
avatar_url_sm: user.avatar_url + '&s=16' | ||
} : null); | ||
} catch (err) { | ||
console.warn(err); | ||
return {}; | ||
} | ||
})({}); | ||
|
||
|
||
const getReleaseInfo = async (version, useGithub) => { | ||
version = 'v' + version.replace(/^v/, ''); | ||
|
||
const releases = JSON.parse((await exec( | ||
`npx auto-changelog ${ | ||
version ? '--starting-version ' + version + ' --ending-version ' + version: '' | ||
} --stdout --commit-limit false --template json`)).stdout | ||
); | ||
|
||
for(const release of releases) { | ||
const authors = {}; | ||
|
||
const commits = [ | ||
...release.commits, | ||
...release.fixes.map(fix => fix.commit), | ||
...release.merges.map(fix => fix.commit) | ||
].filter(Boolean); | ||
|
||
for(const {author, email, insertions, deletions} of commits) { | ||
const user = Object.assign({ | ||
name: author, | ||
}, useGithub ? await getUserInfo(email) : null); | ||
|
||
const entry = authors[author] = (authors[author] || { | ||
insertions: 0, deletions: 0, ...user | ||
}); | ||
|
||
entry.github = entry.login ? `https://github.com/${encodeURIComponent(entry.login)}` : ''; | ||
|
||
entry.insertions += insertions; | ||
entry.deletions += deletions; | ||
entry.points = entry.insertions + entry.deletions; | ||
} | ||
|
||
release.authors = Object.values(authors).sort((a, b) => b.points - a.points); | ||
release.allCommits = commits; | ||
} | ||
|
||
return releases; | ||
} | ||
|
||
const renderContributorsList = async (version, useGithub = false, template) => { | ||
const release = (await getReleaseInfo(version, useGithub))[0]; | ||
|
||
const compile = Handlebars.compile(String(await fs.readFile(template))) | ||
|
||
const content = compile(release); | ||
|
||
return removeExtraLineBreaks(cleanTemplate(content)); | ||
} | ||
|
||
export { | ||
renderContributorsList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.