From 08f4d4fb4539b64ba7149b0022b318169f9965d4 Mon Sep 17 00:00:00 2001 From: Stephen James Date: Tue, 18 Aug 2015 10:54:01 -0400 Subject: [PATCH] Update grunt modules with getPackage() --- Gruntfile.js | 8 ++++++-- grunt/config/less.js | 11 ++++++++--- grunt/config/replace.js | 6 +++++- grunt/config/saucelabs-qunit.js | 12 +++++++----- grunt/config/shell.js | 8 ++++++-- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index bee1c549a..0674d3800 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -11,12 +11,16 @@ module.exports = function (grunt) { * since it has not been initialized yet, until grunt.initConfig() is executed. */ + function getPackage() { + return grunt.file.readJSON('./package.json'); + } + // use --no-livereload to disable livereload. Helpful to 'serve' multiple projects var isLivereloadEnabled = (typeof grunt.option('livereload') !== 'undefined') ? grunt.option('livereload') : true; // external libraries var semver = require('semver'); - var packageVersion = require('./package.json').version; + var packageVersion = getPackage().version; var fs = require('fs'); var path = require('path'); var commonJSBundledReferenceModule = require('./grunt/other/commonjs-reference-module.js'); @@ -49,7 +53,7 @@ module.exports = function (grunt) { jqueryCheck: 'if (typeof jQuery === \'undefined\') { throw new Error(\'Fuel UX\\\'s JavaScript requires jQuery\') }\n\n', bootstrapCheck: 'if (typeof jQuery.fn.dropdown === \'undefined\' || typeof jQuery.fn.collapse === \'undefined\') ' + '{ throw new Error(\'Fuel UX\\\'s JavaScript requires Bootstrap\') }\n\n', - pkg: grunt.file.readJSON('package.json'), + pkg: getPackage(), // Try ENV variables (export SAUCE_ACCESS_KEY=XXXX), if key doesn't exist, try key file sauceLoginFile: grunt.file.exists('SAUCE_API_KEY.yml') ? grunt.file.readYAML('SAUCE_API_KEY.yml') : undefined, cdnLoginFile: grunt.file.exists('FUEL_CDN.yml') ? grunt.file.readYAML('FUEL_CDN.yml') : undefined, diff --git a/grunt/config/less.js b/grunt/config/less.js index cec3cfb40..496215b67 100644 --- a/grunt/config/less.js +++ b/grunt/config/less.js @@ -2,6 +2,13 @@ module.exports = function (grunt) { var minifiedOutput = 'dist/css/' + '<%= pkg.name %>' + '.min.css'; + var minifyFiles = function() { + var minifyFiles = {}; + var output = 'dist/css/' + '<%= pkg.name %>' + '.min.css' + minifyFiles[output] = 'dist/css/' + '<%= pkg.name %>' + '.css' + return minifyFiles + }; + return { dev: { options: { @@ -33,9 +40,7 @@ module.exports = function (grunt) { compress: true, report: 'min' }, - files: { - minifiedOutput : 'dist/css/' + '<%= pkg.name %>' + '.css' - } + files: minifyFiles() } } diff --git a/grunt/config/replace.js b/grunt/config/replace.js index 18a1c9d36..6e1a7b304 100644 --- a/grunt/config/replace.js +++ b/grunt/config/replace.js @@ -1,12 +1,16 @@ module.exports = function (grunt) { + function getPackage() { + return grunt.file.readJSON('./package.json'); + } + return { readme: { src: ['DETAILS.md', 'README.md'], overwrite: true, replacements: [{ from: /fuelux\/\d\.\d\.\d/g, - to: 'fuelux/' + grunt.config('pkg.version') + to: 'fuelux/' + getPackage().version }] } } diff --git a/grunt/config/saucelabs-qunit.js b/grunt/config/saucelabs-qunit.js index 140eb4718..fa2909951 100644 --- a/grunt/config/saucelabs-qunit.js +++ b/grunt/config/saucelabs-qunit.js @@ -1,5 +1,7 @@ module.exports = function (grunt) { - var packageVersion = require('../../package.json').version; + function getPackage() { + return grunt.file.readJSON('./package.json'); + } return { trickyBrowsers: { @@ -10,7 +12,7 @@ module.exports = function (grunt) { testInterval: 3000, tags: ['<%= sauceUser %>' + '@' + process.env.TRAVIS_BRANCH || '<%= sauceUser %>' + '@local'], browsers: grunt.file.readYAML('sauce_browsers_tricky.yml'), - build: process.env.TRAVIS_BUILD_NUMBER || '<%= pkg.version %>', + build: process.env.TRAVIS_BUILD_NUMBER || getPackage().version, testname: process.env.TRAVIS_JOB_ID || Math.floor((new Date()).getTime() / 1000 - 1230768000).toString(), urls: ['http://localhost:<%= connect.testServer.options.port %>/test/?testdist=true'] } @@ -21,10 +23,10 @@ module.exports = function (grunt) { key: '<%= sauceKey %>', tunnelTimeout: 45, testInterval: 3000, - tags: [packageVersion, '<%= sauceUser %>' + '@' + process.env.TRAVIS_BRANCH || '<%= sauceUser %>@local'], + tags: [getPackage().version, '<%= sauceUser %>' + '@' + process.env.TRAVIS_BRANCH || '<%= sauceUser %>@local'], browsers: grunt.file.readYAML('sauce_browsers.yml'), - build: process.env.TRAVIS_BUILD_NUMBER || packageVersion, - testname: process.env.TRAVIS_JOB_ID || packageVersion + '-<%= grunt.template.today("dddd, mmmm dS, yyyy, h:MM:ss TT") %>', + build: process.env.TRAVIS_BUILD_NUMBER || getPackage().version, + testname: process.env.TRAVIS_JOB_ID || getPackage().version + '-<%= grunt.template.today("dddd, mmmm dS, yyyy, h:MM:ss TT") %>', urls: ['http://localhost:<%= connect.testServer.options.port %>/test/?testdist=true'], maxPollRetries: 4, throttled: 3, diff --git a/grunt/config/shell.js b/grunt/config/shell.js index 638719846..93b1f8884 100644 --- a/grunt/config/shell.js +++ b/grunt/config/shell.js @@ -1,6 +1,10 @@ module.exports = function (grunt) { var semver = require('semver'); + function getPackage() { + return grunt.file.readJSON('./package.json'); + } + return { // Compile release notes while waiting for tests to pass. Needs Ruby gem and ONLY LOOKS AT THE REMOTE NAMED ORIGIN. // Install with: gem install github_changelog_generator @@ -30,14 +34,14 @@ module.exports = function (grunt) { }, commit: { command: function() { - var command = 'git commit -m "release ' + grunt.config('pkg.version') + '"'; + var command = 'git commit -m "release ' + getPackage().version + '"'; grunt.log.write('Committing: ' + command); return command; } }, tag: { command: function() { - var command = 'git tag -a "' + grunt.config('pkg.version') + '" -m "' + grunt.config('pkg.version') + '"'; + var command = 'git tag -a "' + getPackage().version + '" -m "' + getPackage().version + '"'; grunt.log.write('Tagging: ' + command); return command; }