Skip to content

Commit

Permalink
Revert "Fix: Less Tricky Git Rev Acquisition"
Browse files Browse the repository at this point in the history
This reverts commit 1cc2c7f.
  • Loading branch information
wesleyboar committed Mar 11, 2022
1 parent 1cc2c7f commit 88f0763
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
42 changes: 10 additions & 32 deletions bin/update-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,31 @@
/** Create CSS file to import that prints project version */

const fs = require('fs');
const childProcess = require('child_process');

const root = __dirname;
const outFile = root + '/../source/_version.css';

/**
* Whether a Git revision look like something we can use
* @param {string} rev - The revision to check
* @return {boolean}
*/
function isGitRevOkay(rev) {
console.debug(rev);
const isOkay = /[\da-z]+/.test(rev);
const ver = process.env.npm_package_version;
const rev = getGitRev().substring(0, 7);

return isOkay;
}
const output = `/*! @tacc/core-styles#${rev} (≥ v${ver}) | MIT License | github.com/TACC/Core-Styles */`;

/**
* Get the Git revision of the current working directory code
* @return {string}
* @see https://stackoverflow.com/a/34518749/11817077
*/
function getGitRev() {
const rev = childProcess.execSync('git rev-parse HEAD').toString();
const isRevOkay = isGitRevOkay(rev);
let rev = fs.readFileSync('.git/HEAD').toString().trim();
const revFile = '.git/' + rev.substring(5);

if ( ! isRevOkay) {
console.warn(`Revision looks odd. Is this okay?` + rev);
if (rev.indexOf(':') !== -1) {
console.log('Reading Git revision from: ' + revFile);
rev = fs.readFileSync(revFile).toString().trim();
}

return rev;
}

/**
* Get data and write content to version file
* @return {string}
* @see https://stackoverflow.com/a/34518749/11817077
*/
(async function writeRevToFile() {
const ver = process.env.npm_package_version;
const rev = await getGitRev().substring(0, 7);
const output = `/*! @tacc/core-styles#${rev} (≥ v${ver}) | MIT License | github.com/TACC/Core-Styles */`;

console.log('Updating CSS version to' +
`package version ${ver} and` +
`Git revision ${rev}[...]`
);

fs.writeFileSync(outFile, output, 'utf8');
})();
console.log(`Updating CSS version to package version ${ver} and Git revision ${rev}[...]`);
fs.writeFileSync(outFile, output, 'utf8');
2 changes: 1 addition & 1 deletion dist/_version.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! @tacc/core-styles#643448f (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */
/*! @tacc/core-styles#6c24a3e (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */
2 changes: 1 addition & 1 deletion source/_version.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! @tacc/core-styles#643448f (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */
/*! @tacc/core-styles#6c24a3e (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */

0 comments on commit 88f0763

Please sign in to comment.