1
0
mirror of https://github.com/nostalgic-css/NES.css.git synced 2025-08-13 09:54:00 +02:00

build: Make build versions dynamic

Hehehehe, this is really cool. I've removed the hardcoded version number from `nes.scss` and
replaced it with a custom function. This function does all sorts of cool stuff.

1. **Injects the framework version from `package.json`
  This prevents us from having to inject the version number manually.
2. **Adds build info…**
  The branch that the CSS was built from, when it was built, what version of Node was used… All of the useful information that we could possibly provide. If it’s built on CircleCI, it even includes the build number.
3. **…but not too much build info**
  If the build is running against the `master` branch, we only inject the framework version. No need to bloat production builds with all the other junk. 😁
This commit is contained in:
Trezy
2018-12-16 21:12:04 -06:00
parent 0e66d0b81e
commit a34cac4aca
3 changed files with 33 additions and 4 deletions

View File

@@ -8,7 +8,7 @@
"stylelint": "stylelint scss/**/*.scss",
"build:stylelint": "npm run stylelint -- --fix",
"build:clean": "rimraf css",
"build:sass": "node-sass --output-style expanded --source-map true scss/nes.scss css/nes.css",
"build:sass": "node-sass --output-style expanded --source-map true --functions scss/functions.js scss/nes.scss css/nes.css",
"build:autoprefix": "postcss --use autoprefixer --map false --output css/nes.css css/nes.css",
"build:cleancss": "cleancss -o css/nes.min.css css/nes.css",
"storybook": "start-storybook -p 6006",
@@ -50,6 +50,7 @@
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"file-loader": "^2.0.0",
"git-rev-sync": "^1.12.0",
"husky": "^1.0.0",
"lint-staged": "^7.3.0",
"node-sass": "^4.9.3",

28
scss/functions.js Normal file
View File

@@ -0,0 +1,28 @@
const git = require('git-rev-sync'); /* eslint-disable-line import/no-extraneous-dependencies */
const { types } = require('node-sass'); /* eslint-disable-line import/no-extraneous-dependencies */
module.exports = {
'version()': () => {
const packageData = require('../package.json'); /* eslint-disable-line global-require */
let buildData = `
NES.css Framework
Version: ${(git.branch() === 'develop') ? 'development' : `v${packageData.version}`}
`;
if (git.branch() !== 'master') {
buildData += `
Build Date: ${(new Date()).toISOString()}
Node Version: ${process.version}
Branch: ${git.branch()}
Commit: ${git.long()}`;
}
if (process.env.CIRCLECI) {
buildData += `
Build Number (CircleCI): ${process.env.CIRCLE_BUILD_NUM}`;
}
return types.String(buildData.replace(/\n/, '').replace(/^ +/gm, ' '));
},
};

View File

@@ -1,8 +1,8 @@
@charset "utf-8";
/*!
* NES.css v0.0.2(alpha)
*/
/*****************************************************************************\
#{version()}
\*****************************************************************************/
@import "base/_index.scss";
@import "utilities/_index.scss";