Created
April 29, 2020 13:01
-
-
Save FergusInLondon/70abfd98133e187f728ce91df174d9ef to your computer and use it in GitHub Desktop.
Get git stats for static site generation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const run = require('util').promisify(require('child_process').exec) | |
async function getGitStats() { | |
const {stdout: refHash } = await run('git rev-parse HEAD') | |
const {stdout: message } = await run(`git log --format=%B -n 1 ${refHash}`) | |
const {stdout: branch } = await run('git rev-parse --abbrev-ref HEAD') | |
return { refHash, message, branch } | |
} | |
getGitStats().then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When executed in a directory located within a git repository, an object is returned with the commit message, commit hash, and branch name. Useful for displaying meta-information in static site builds.
Requires no external dependencies -
util
andchild_process
are both core to Node.Example Output: