Skip to content

Commit

Permalink
chore($last-updated): ensure build process success if not in git repo. (
Browse files Browse the repository at this point in the history
close: #1007)

During some CI context, the git command would not exist, this change just ensure that the build process does not crash.
  • Loading branch information
ulivz committed Nov 17, 2018
1 parent 78dd14e commit 2a4e37f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/@vuepress/plugin-last-updated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ module.exports = (options = {}, context) => ({
extendPageData ($page) {
const { transformer } = options
const timestamp = getGitLastUpdatedTimeStamp($page._filePath)
const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp
$page.lastUpdated = lastUpdated
if (timestamp) {
const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp
$page.lastUpdated = lastUpdated
}
}
})

function getGitLastUpdatedTimeStamp (filePath) {
return parseInt(spawn.sync('git', ['log', '-1', '--format=%ct', filePath]).stdout.toString('utf-8')) * 1000
let lastUpdated
try {
lastUpdated = parseInt(spawn.sync('git', ['log', '-1', '--format=%ct', filePath]).stdout.toString('utf-8')) * 1000
} catch (e) { /* do not handle for now */ }
return lastUpdated
}

0 comments on commit 2a4e37f

Please sign in to comment.