Skip to content

Commit e79d3c7

Browse files
Implement last commit date time (tests / docs not done)
1 parent 884ca6e commit e79d3c7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var runGitCommand = require('./helpers/run-git-command')
44
var COMMITHASH_COMMAND = 'rev-parse HEAD'
55
var VERSION_COMMAND = 'describe --always'
66
var BRANCH_COMMAND = 'rev-parse --abbrev-ref HEAD'
7+
var LASTCOMMITDATETIME_COMMAND = 'log -1 --format=%cI'
78

89
function GitRevisionPlugin (options) {
910
options = options || {}
@@ -21,6 +22,9 @@ function GitRevisionPlugin (options) {
2122
this.branchCommand = options.branchCommand ||
2223
BRANCH_COMMAND
2324

25+
this.lastCommitDateTimeCommand = options.lastCommitDateTimeCommand ||
26+
LASTCOMMITDATETIME_COMMAND
27+
2428
if (options.versionCommand && options.lightweightTags) {
2529
throw new Error('lightweightTags can\'t be used together versionCommand')
2630
}
@@ -43,6 +47,14 @@ GitRevisionPlugin.prototype.apply = function (compiler) {
4347
asset: 'VERSION'
4448
})
4549

50+
buildFile({
51+
compiler: compiler,
52+
gitWorkTree: this.gitWorkTree,
53+
command: this.lastCommitDateTimeCommand,
54+
replacePattern: /\[git-revision-last-commit-datetime\]/gi,
55+
asset: 'LASTCOMMITDATETIME'
56+
})
57+
4658
if (this.createBranchFile) {
4759
buildFile({
4860
compiler: compiler,
@@ -75,4 +87,11 @@ GitRevisionPlugin.prototype.branch = function () {
7587
)
7688
}
7789

90+
GitRevisionPlugin.prototype.lastcommitdatetime = function () {
91+
return runGitCommand(
92+
this.gitWorkTree,
93+
this.lastCommitDateTimeCommand
94+
)
95+
}
96+
7897
module.exports = GitRevisionPlugin

0 commit comments

Comments
 (0)