Skip to content

Commit

Permalink
fix(cli): git history copyright year generation
Browse files Browse the repository at this point in the history
Signed-off-by: Rifa Achrinza <[email protected]>
  • Loading branch information
achrinza authored and bajtos committed Jan 7, 2021
1 parent 6598609 commit f3373d5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/cli/generators/copyright/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ async function git(cwd, ...args) {
*/
async function getYears(file) {
file = file || '.';
let dates = await git(
const gitDates = await git(
process.cwd(),
'--no-pager log --pretty=%%ai --all -- %s',
file,
);
debug('Dates for %s', file, dates);
if (_.isEmpty(dates)) {
// if the given path doesn't have any git history, assume it is new
dates = [new Date().toJSON()];
} else {
dates = [_.head(dates), _.last(dates)];
}
const years = _.map(dates, getYear);

const consolidatedDates = [new Date().toISOString()];

// if the given path has any git history, get its dates
if (gitDates.length !== 0)
consolidatedDates.push(new Date().toISOString(), _.last(gitDates));

debug('Dates for %s', file, consolidatedDates);

const years = consolidatedDates.map(getYear);
return _.uniq(years).sort();
}

Expand Down

0 comments on commit f3373d5

Please sign in to comment.