UNPKG

539 BJavaScriptView Raw
1var _child_process = require("child_process");
2const tryExec = (command, option) => {
3 try {
4 return (0, _child_process.execSync)(command, option).toString();
5 } catch (error) {
6 console.warn(`[tryExec] failed for: ${command}, error: ${error}`);
7 return "";
8 }
9};
10exports.tryExec = tryExec;
11exports.getGitBranch = (() => tryExec("git symbolic-ref --short HEAD", {
12 stdio: "pipe"
13}).replace("\n", "").trim());
14exports.getGitCommitHash = (() => tryExec('git log -1 --format="%H"', {
15 stdio: "pipe"
16}).replace("\n", "").trim());
\No newline at end of file