Created
April 11, 2016 07:58
-
-
Save choffmeister/650a9172e52017ca7f63cbf6deb5642d to your computer and use it in GitHub Desktop.
git-info-loader.js
This file contains hidden or 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
/* 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