Skip to content

Commit

Permalink
chore: add print=verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 15, 2024
1 parent 29fb53d commit 762a852
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 7 additions & 7 deletions bin/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ module.exports = white(`
${gray('$')} git-authors-cli ${gray('[options]')}
Options
${gray('--')}cwd ${gray(
'Specify the path for running the command (defaults to process.cwd())'
${gray('--')}cwd ${gray('Specify the path for running the command (defaults to process.cwd())')}
${gray('--')}ignore-pattern ${gray(
'Skip authors if their name or email match pattern (allow multiple)'
)}
${gray('--')}save ${gray(
'Write contributors into package.json if it exists (defaults to true)'
${gray('--')}print ${gray(
'Show information from the terminal, also `print=verbose` to show more information. (defaults to true)'
)}
${gray('--')}print ${gray('Show information from the terminal (defaults to true)')}
${gray('--')}ignore-pattern ${gray(
'Skip authors if their name or email match pattern (allow multiple)'
${gray('--')}save ${gray(
'Write contributors into package.json if it exists (defaults to true)'
)}
Examples
Expand Down
24 changes: 22 additions & 2 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ const isSameEmail = (email1 = '', email2 = '') => normalizeEmail(email1) === nor
const flags = mri(process.argv.slice(2), {
default: {
cwd: process.cwd(),
print: true,
print: '',
save: true,
ignorePattern: []
}
})

if (flags.print === '') flags.print = true

const loadPkg = path => {
try {
return jsonFuture.loadAsync(path)
Expand All @@ -49,6 +51,19 @@ const indent = (maxIndentation, prop = '') => {
return Array.from({ length: indentSize }, () => ' ').join('')
}

const renderContributorsVerbose = (contributors, maxIndent) => {
const maxIndexIndent = String(contributors.length).length

console.log()
contributors.forEach(({ author, commits, name }, index) => {
const prettyAuthor = colors.gray(author.replace(name, colors.white(name)))
const prettyCommits = colors.white(`${indent(maxIndent, commits)}${commits}`)
const humanIndex = index + 1
const prettyIndex = colors.gray(`${indent(maxIndexIndent, humanIndex)}${humanIndex}`)
console.log(` ${prettyIndex} ${prettyCommits} ${prettyAuthor}`)
})
}

const renderContributors = (contributors, maxIndent) => {
console.log()
contributors.forEach(({ author, commits, name }) => {
Expand Down Expand Up @@ -134,7 +149,12 @@ const getContributors = async () => {
const maxIndent = contributors.length ? getMaxIndent(contributors, 'commits') : ''

if (contributors.length) {
if (print) renderContributors(contributors, maxIndent)
if (print) {
(print === 'verbose' ? renderContributorsVerbose : renderContributors)(
contributors,
maxIndent
)
}
const pkg = await loadPkg(pkgPath)

if (pkg && save) {
Expand Down

0 comments on commit 762a852

Please sign in to comment.