diff --git a/DEVELOPING.md b/DEVELOPING.md index b3d82a6c3..d22fd04ca 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -36,6 +36,14 @@ ESBuild must also be used to compile the CSS supporting the MAPP and MAPP.UI ele $ npx esbuild --bundle public/css/_ui.css --outfile=public/css/ui.css --loader:.svg=dataurl +## version.js hash + +The mapp module object holds a hash of the latest release commit which can be generated by executing the version.js script in the root. + +The version script will complete by executing the ESBuild process. + + $ node version.js + ## Express [Express.js](https://expressjs.com/) will be installed by npm as a development dependency. You can run a zero config instance by loading the express.js script in your node runtime. diff --git a/lib/mapp.mjs b/lib/mapp.mjs index 97c6b483d..94b5605cc 100644 --- a/lib/mapp.mjs +++ b/lib/mapp.mjs @@ -72,7 +72,7 @@ self.mapp = { version: '4.12.0β', - hash: 'd81f870a553c53aa8d06bef154edb5eff6792209', + hash: '5684e47d2ddded000d6944caf7a0c8f89159616e', host: document.head?.dataset?.dir || '', diff --git a/version.js b/version.js index 8fe9d9332..bb1106dd4 100644 --- a/version.js +++ b/version.js @@ -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'); \ No newline at end of file +// Run the build script defined in package.json +// Execute build command +execSync('npm run _build');