From 88f0763cb4d096341cea9928e9963af9a7dd178a Mon Sep 17 00:00:00 2001 From: Wesley Bomar Date: Fri, 11 Mar 2022 16:59:13 -0600 Subject: [PATCH] Revert "Fix: Less Tricky Git Rev Acquisition" This reverts commit 1cc2c7fae17892aa3b415cdffeb0dc4ead2c4831. --- bin/update-version.js | 42 ++++++++++-------------------------------- dist/_version.css | 2 +- source/_version.css | 2 +- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/bin/update-version.js b/bin/update-version.js index 79b9fba68..adab4666b 100755 --- a/bin/update-version.js +++ b/bin/update-version.js @@ -3,22 +3,14 @@ /** 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 @@ -26,30 +18,16 @@ function isGitRevOkay(rev) { * @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'); diff --git a/dist/_version.css b/dist/_version.css index 233534c65..b315c7153 100644 --- a/dist/_version.css +++ b/dist/_version.css @@ -1 +1 @@ -/*! @tacc/core-styles#643448f (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */ \ No newline at end of file +/*! @tacc/core-styles#6c24a3e (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */ \ No newline at end of file diff --git a/source/_version.css b/source/_version.css index 233534c65..b315c7153 100644 --- a/source/_version.css +++ b/source/_version.css @@ -1 +1 @@ -/*! @tacc/core-styles#643448f (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */ \ No newline at end of file +/*! @tacc/core-styles#6c24a3e (≥ v0.1.0) | MIT License | github.com/TACC/Core-Styles */ \ No newline at end of file