-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (49 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*!
* first-commit-date <https://github.com/jonschlinkert/first-commit-date>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var firstCommit = require('get-first-commit');
/**
* Asynchronously get the first commit date from a git repository.
*
* ```js
* firstCommitDate('foo/.git', function(err, date) {
* if (err) return console.log(err);
* // do stuff with commit date
* });
* ```
* @param {String} `cwd` current working directory
* @param {Function} `callback`
* @return {Object}
* @api public
*/
module.exports = function(cwd, cb) {
if (typeof cwd === 'function') {
cb = cwd;
cwd = process.cwd();
}
if (typeof cb !== 'function') {
throw new TypeError('expected callback to be a function');
}
firstCommit(cwd, function(err, commit) {
if (err) return cb(err);
cb(null, new Date(commit.date));
});
};
/**
* Synchronously get the first commit date from a git repository.
*
* ```js
* var date = firstCommitDate.sync('foo/.git');
* ```
* @param {String} `cwd` current working directory
* @return {Object}
* @api public
*/
module.exports.sync = function(cwd) {
var commit = firstCommit.sync(cwd);
return new Date(commit.date);
};