Skip to content

Commit

Permalink
Fallback to default year if -r flag used in directory without git repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridha Hassoun committed Mar 14, 2017
1 parent 3fa74c7 commit c97ff08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ npm install --global @captainsafia/legit
-y --year [year] The year the license is in effect.
-r --range Year range from first commit year to current year.
Takes precedence over -y/--year.
Will fall back to default year if git repo is not found in current directory.
```

![Legit Demo](https://cloud.githubusercontent.com/assets/1857993/23821404/bea5dfc2-05f6-11e7-8525-7f5bd88a7829.gif)
Expand Down
16 changes: 10 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ program
var yearArg = this.year || new Date().getFullYear();

if (this.range) {
var firstCommitYear = firstCommitDate.sync(cwd + '/.git').getFullYear();
var currentYear = new Date().getFullYear();
if (currentYear === firstCommitYear) {
yearArg = currentYear;
} else {
yearArg = firstCommitYear + "-" + currentYear;
try {
var firstCommitYear = firstCommitDate.sync(cwd + '/.git').getFullYear();
var currentYear = new Date().getFullYear();
if (currentYear === firstCommitYear) {
yearArg = currentYear;
} else {
yearArg = firstCommitYear + "-" + currentYear;
}
} catch (error) {
console.log('git repository not found in this directory. Using', yearArg, 'as year.');
}
}

Expand Down

0 comments on commit c97ff08

Please sign in to comment.