const childProcess = require('child_process'); const { writeFileSync } = require('fs'); const rootDir = __dirname.replace('\\version',''); const longSHA = childProcess.execSync("git rev-parse HEAD").toString().trim(); const shortSHA = childProcess.execSync("git rev-parse --short HEAD").toString().trim(); const branch = childProcess.execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); const authorName = childProcess.execSync("git log -1 --pretty=format:'%an'").toString().trim(); const commitTime = childProcess.execSync("git log -1 --pretty=format:'%cd'").toString().trim(); const commitMsg = childProcess.execSync("git log -1 --pretty=%B").toString().trim(); const totalCommitCount = childProcess.execSync("git rev-list --count HEAD").toString().trim(); const change = childProcess.execSync(`git diff -- ":!/version/git-version.ts" ":!/version/git-version.json" `,{cwd: rootDir }).toString().trim(); const changeStatus = childProcess.execSync("git status").toString().trim(); const changeAuthor = childProcess.execSync("whoami").toString().trim(); const versionInfo = { shortSHA: shortSHA, SHA : longSHA, branch: branch, lastCommitAuthor: authorName, lastCommitTime: commitTime, lastCommitMessage: commitMsg, lastCommitNumber: totalCommitCount, change, changeStatus, changeAuthor, } const versionInfoJson = JSON.stringify(versionInfo, null, 2); //console.log("versionInfo", versionInfo.diff) writeFileSync('./version/git-version.ts', "export let versionData = "+versionInfoJson); // writeFileSync('./version/git-version.json', versionInfoJson);