-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathversion.js
More file actions
24 lines (19 loc) · 739 Bytes
/
version.js
File metadata and controls
24 lines (19 loc) · 739 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
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const packageJsonPath = path.resolve(__dirname, 'package.json');
const { version } = require(packageJsonPath);
let commitHash = 'unknown';
try {
commitHash = execSync('git rev-parse HEAD').toString().trim();
} catch (err) {
console.error('Failed to get Git commit hash:', err.message);
}
// Write the commit hash to a file
const outputPath = path.resolve('.', 'src', 'version.ts');
const content = `
export const GIT_COMMIT_HASH = '${commitHash}';
export const APP_VERSION = 'v${version}';
`;
fs.writeFileSync(outputPath, content, { encoding: 'utf8' });
console.log(`Git commit hash written to ${outputPath}`);