Skip to content

Instantly share code, notes, and snippets.

@choffmeister
Created April 11, 2016 07:58
Show Gist options
  • Save choffmeister/650a9172e52017ca7f63cbf6deb5642d to your computer and use it in GitHub Desktop.
Save choffmeister/650a9172e52017ca7f63cbf6deb5642d to your computer and use it in GitHub Desktop.
git-info-loader.js
/* eslint-env node */
'use strict'
const Bluebird = require('bluebird')
const childProcess = require('child_process')
function gitCommand (args) {
return new Promise((resolve, reject) => {
childProcess.execFile('git', args, (err, stdout, stderr) => {
if (!err) {
resolve(stdout.trim())
} else {
reject(err)
}
})
})
}
function gitInfo (format) {
return gitCommand(['show', '--no-patch', `--pretty=${format}`])
}
module.exports = function () {
this.cacheable && this.cacheable()
const callback = this.async()
Bluebird.props({
commit: gitInfo('%H'),
describe: gitCommand(['describe']),
author: gitInfo('%aN'),
authorDate: gitInfo('%ad'),
committer: gitInfo('%cN'),
committerDate: gitInfo('%cd')
})
.then((info) => callback(null, `module.exports = ${JSON.stringify(info, null, 2)};`))
.catch((err) => callback(err))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment