Skip to content

Instantly share code, notes, and snippets.

@fangbinwei
Created March 17, 2020 09:03
Show Gist options
  • Save fangbinwei/1ae57d3546793680f41f53db4421233f to your computer and use it in GitHub Desktop.
Save fangbinwei/1ae57d3546793680f41f53db4421233f to your computer and use it in GitHub Desktop.
record latest git info to file
const fs = require('fs')
const path = require('path')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const mkdirp = require('mkdirp')
const outputPath = 'dist/static'
async function main() {
try {
const { stdout: changesStdout } = await exec('git log --name-status -1')
const { stdout: statusStdout } = await exec('git status -s')
mkdirp.sync(outputPath)
const gitInfo = fs.createWriteStream(path.join(outputPath, 'gitInfo.txt'), 'utf-8')
gitInfo.write(`Files' changes:\n${changesStdout}\nFiles' status:\n${statusStdout}`)
gitInfo.end()
} catch (err) {
console.error(
'# Failed to generate Git commit info, please install Git or commit your changes.'
)
console.error(`# error message:
--------------------->
${err.message}
<--------------------`)
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment