提交 2a4e37f4 编写于 作者: U ULIVZ

chore($last-updated): ensure build process success if not in git repo. (close: #1007)

During some CI context, the git command would not exist, this change just ensure that the build process does not crash.
上级 78dd14e9
......@@ -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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册