Created
March 17, 2020 09:03
-
-
Save fangbinwei/1ae57d3546793680f41f53db4421233f to your computer and use it in GitHub Desktop.
record latest git info to file
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 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