Skip to content

Commit

Permalink
Polish: Simplify CSS Version Script
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyboar committed Mar 14, 2022
1 parent e1c85ae commit 9ca6af0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 49 deletions.
58 changes: 10 additions & 48 deletions bin/update-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,17 @@
/** Create CSS file to import that prints project version */

const fs = require('fs');
const path = require('../package.json');
const childProcess = require('child_process');

const package = require('../package.json');
const root = __dirname;
const outFile = root + '/../source/_version.css';
// Get data
const appLicense = path.license;
const appGitRef = childProcess.execSync('git describe --always').toString();
const filePath = __dirname + '/../source/_version.css';
const fileContent = `/*! @tacc/core-styles ${appGitRef} | ${appLicense} | github.com/TACC/Core-Styles */` + "\n";

/**
* 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);
// Tell user
console.log(`Updating CSS version to ${appGitRef}`);

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() {
// 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 ${cssVersion}`);

fs.writeFileSync(outFile, output, 'utf8');
})();
// Write version
fs.writeFileSync( filePath, fileContent );
3 changes: 2 additions & 1 deletion source/_version.css
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/*! @tacc/core-styles#bda1e9d (≥ v0.1.0) | MIT | github.com/TACC/Core-Styles */
/*! @tacc/core-styles v0.1.0-6-ge1c85ae
| MIT | github.com/TACC/Core-Styles */

0 comments on commit 9ca6af0

Please sign in to comment.