forked from BoltzExchange/boltz-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseGitCommit.js
More file actions
38 lines (30 loc) · 921 Bytes
/
Copy pathparseGitCommit.js
File metadata and controls
38 lines (30 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* eslint-disable @typescript-eslint/no-require-imports */
const fs = require('fs');
const childProcess = require('child_process');
const executeCommand = (command) => {
return childProcess.execSync(command, { encoding: 'utf8' });
};
const getCommitHash = () => {
const result = executeCommand('git log -1');
return result.slice(7, 7 + 8);
};
const isDirty = () => {
const result = executeCommand('git status --short');
return result.length > 0;
};
const versionFilePath = `${__dirname}/lib/Version.ts`;
try {
// Delete the version file if it exists
if (fs.existsSync(versionFilePath)) {
fs.unlinkSync(versionFilePath);
}
} catch (error) {
console.error(`Could not delete file: ${versionFilePath}`, error);
}
const commitHash = getCommitHash();
fs.writeFileSync(
versionFilePath,
`export default '${commitHash === '' ? '' : '-' + commitHash}${
isDirty() ? '-dirty' : ''
}';\n`,
);