* Inspect years for a given file based on git history * @param {string} file - JS/TS file
(file)
| 48 | * @param {string} file - JS/TS file |
| 49 | */ |
| 50 | async function getYears(file) { |
| 51 | file = file || '.'; |
| 52 | const gitDates = await git( |
| 53 | process.cwd(), |
| 54 | '--no-pager log --pretty=%%ai --all -- %s', |
| 55 | file, |
| 56 | ); |
| 57 | |
| 58 | const currentYear = new Date().getFullYear(); |
| 59 | |
| 60 | if (!gitDates.length) return [currentYear]; |
| 61 | |
| 62 | const latestGitYear = getYear(gitDates[0]); |
| 63 | const oldestGitYear = getYear(gitDates.slice(-1)[0]); |
| 64 | const latestYear = currentYear > latestGitYear ? currentYear : latestGitYear; |
| 65 | const yearRange = [oldestGitYear]; |
| 66 | |
| 67 | if (latestYear !== yearRange[0]) yearRange.push(latestYear); |
| 68 | |
| 69 | return yearRange; |
| 70 | } |
| 71 | |
| 72 | // assumes ISO-8601 (or similar) format |
| 73 | function getYear(str) { |
no test coverage detected