Skip to content

Commit 2a4e37f

Browse files
committed
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.
1 parent 78dd14e commit 2a4e37f

File tree

1 file changed

+9
-3
lines changed
  • packages/@vuepress/plugin-last-updated

1 file changed

+9
-3
lines changed

packages/@vuepress/plugin-last-updated/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ module.exports = (options = {}, context) => ({
44
extendPageData ($page) {
55
const { transformer } = options
66
const timestamp = getGitLastUpdatedTimeStamp($page._filePath)
7-
const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp
8-
$page.lastUpdated = lastUpdated
7+
if (timestamp) {
8+
const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp
9+
$page.lastUpdated = lastUpdated
10+
}
911
}
1012
})
1113

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

0 commit comments

Comments
 (0)