Skip to content

Commit

Permalink
Save version on each build
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedith Mulongo committed Jul 5, 2024
1 parent 1df8ada commit e29e0a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test": "jest --verbose",
"build": "parcel build index.js",
"lint": "eslint . && prettier . --check",
"lint:fix": "eslint . --fix ; prettier . --write"
"lint:fix": "eslint . --fix ; prettier . --write",
"postbuild": "node postbuild.js"
},
"keywords": [],
"author": "",
Expand Down
23 changes: 23 additions & 0 deletions postbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require('dotenv').config();
const fs = require('fs');
const { version } = require('os');
const exec = require('child_process').exec;
const latestCommit = null;

exec('git log -n 1 --pretty=format:"%H"', (err, stdout, stderr) => {
// git rev-parse --verify HEAD
if (err) {
console.error(`error: ${err}`);
return;
}

if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
this.latestCommit = stdout;
var data = `var data = {"version": "${stdout}"};\nexport {data}`
fs.writeFileSync('dist/version.js', data);
})

0 comments on commit e29e0a9

Please sign in to comment.