-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1592 from RobAndrewHurst/version_docs
Update version docs
- Loading branch information
Showing
3 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,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'); | ||
const { execSync } = require('child_process'); // For executing shell commands synchronously | ||
|
||
// Regular expression pattern to match 'hash: ' followed by any characters | ||
const key = 'hash:.*'; | ||
const hash = execSync('git rev-parse HEAD').toString().trim(); | ||
|
||
let data = fs.readFileSync('./lib/mapp.mjs', 'utf-8'); | ||
data = data.replace(new RegExp(key, 'g'), `hash: '${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( | ||
|
||
fs.writeFileSync('./lib/mapp.mjs', data); | ||
// Path to the file | ||
'./lib/mapp.mjs', | ||
|
||
// Updated content | ||
data); | ||
|
||
execSync('npm run _build'); | ||
// Run the build script defined in package.json | ||
// Execute build command | ||
execSync('npm run _build'); |