MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / getYears

Function getYears

packages/cli/generators/copyright/git.js:50–70  ·  view source on GitHub ↗

* Inspect years for a given file based on git history * @param {string} file - JS/TS file

(file)

Source from the content-addressed store, hash-verified

48 * @param {string} file - JS/TS file
49 */
50async 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
73function getYear(str) {

Callers 2

buildHeaderFunction · 0.85
updateLicenseFunction · 0.85

Calls 2

getYearFunction · 0.85
gitFunction · 0.70

Tested by

no test coverage detected