Skip to content

Commit

Permalink
Fix: Re-Implement Git Rev (It Was Not the Problem)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyboar committed Mar 14, 2022
1 parent bda1e9d commit e1c85ae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules
.postcssrc.yml
dist/_tests.css
dist/_version.css

# IDE
.vscode
Expand Down
41 changes: 38 additions & 3 deletions bin/update-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,55 @@
/** Create CSS file to import that prints project version */

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

const package = require('../package.json');
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) {
const isOkay = /[\da-z]+/.test(rev);

return isOkay;
}

/**
* 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);

if ( ! isRevOkay) {
console.warn(`Revision looks odd. Is this okay?` + rev);
}

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 output = `/*! @tacc/core-styles (≥ v${ver}) | MIT License | github.com/TACC/Core-Styles */`;
// FP-1544: IF tags are annotated THEN replace version with `git describe`
const ver = package.version;
const rev = await getGitRev().substring(0, 7);

const cssVersion = `#${rev} (≥ v${ver})`;
const cssLicense = package.license;

const output = `/*! @tacc/core-styles${cssVersion} | ${cssLicense} | github.com/TACC/Core-Styles */` + "\n";

console.log(`Updating CSS version to package version ${ver}`);
console.log(`Updating CSS version to ${cssVersion}`);

fs.writeFileSync(outFile, output, 'utf8');
})();
1 change: 0 additions & 1 deletion dist/_version.css

This file was deleted.

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#bda1e9d (≥ v0.1.0) | MIT | github.com/TACC/Core-Styles */

0 comments on commit e1c85ae

Please sign in to comment.