forked from GEOLYTIX/xyz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.js
58 lines (41 loc) · 1.39 KB
/
version.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
## Version script
This script is used for developers to update the commit SHA in the attribution of the mapp bundle.
This is used to track deployed applications and what exact version of the xyz framework it is using.
To run this script you can execute `node version.js` in your terminal.
@requires module:fs
@module version
*/
// File system module for reading/writing files
const fs = require('fs');
const { execSync } = require('child_process'); // For executing shell commands synchronously
// Regular expression pattern to match 'hash: ' followed by any characters
const key = 'hash:.*';
// Get the current git commit hash
// Execute git command to get current commit hash
const hash = execSync('git rev-parse HEAD')
// Convert Buffer to string
.toString()
// Remove any whitespace
.trim();
// Read the contents of mapp.mjs file
let data = fs.readFileSync(
// Path to the file
'./lib/mapp.mjs',
// Specify encoding
'utf-8');
// Replace all occurrences of the old hash with the new commit hash
data = data.replace(
// Global regex to match all occurrences
new RegExp(key, 'g'),
// Replace with new hash string
`hash: '${hash}',`);
// Write the updated content back to the file
fs.writeFileSync(
// Path to the file
'./lib/mapp.mjs',
// Updated content
data);
// Run the build script defined in package.json
// Execute build command
execSync('npm run _build');