Skip to content

Commit

Permalink
support both minCSS and minCss option keys. Fixes #34.
Browse files Browse the repository at this point in the history
  • Loading branch information
chmontgomery committed Oct 21, 2014
1 parent 9b349f1 commit c849faf
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/bower/bundle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
],
options: {
uglify: false, // don't minify js since bower already ships with one
minCss: false, // don't minify css since bower already ships with one
minCSS: false, // don't minify css since bower already ships with one
rev: false
}
},
Expand Down
2 changes: 1 addition & 1 deletion examples/bower/public/maps/vendor.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions examples/bower/public/vendor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/bundle-all-environments/bundle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
options: {
useMin: prodLikeEnvs,
uglify: false,
minCss: false,
minCSS: false,
rev: prodLikeEnvs
}
},
Expand All @@ -23,7 +23,7 @@ module.exports = {
styles: './content/**/*.css',
options: {
uglify: prodLikeEnvs,
minCss: prodLikeEnvs,
minCSS: prodLikeEnvs,
rev: prodLikeEnvs
}
}
Expand Down
4 changes: 3 additions & 1 deletion examples/bundle-all-environments/public/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/bundle-all-environments/public/maps/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions lib/is-min-enabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var isMinSrcDefinedForFile = require('./is-min-src-defined-for-file'),
isOptionEnabled = require('./is-option-enabled');

module.exports.getMinCssOption = function(opts) {
// support both "minCSS" and "minCss" in case of typo
var minCss = opts.bundleOptions.minCSS;
if (typeof minCss === 'undefined') {
minCss = opts.bundleOptions.minCss;
}
return minCss;
};

module.exports.css = function (file, opts) {
return !isMinSrcDefinedForFile(file, opts.minSrcs, opts.bundleName, opts.type) &&
isOptionEnabled(this.getMinCssOption(opts), opts.env);
};

module.exports.js = function (file, opts) {
return !isMinSrcDefinedForFile(file, opts.minSrcs, opts.bundleName, opts.type) &&
isOptionEnabled(opts.bundleOptions.uglify, opts.env);
};
10 changes: 4 additions & 6 deletions lib/stream-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ var gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
using = require('./using'),
verifySourcemaps = require('./verify-sourcemaps'),
isMinSrcDefinedForFile = require('./is-min-src-defined-for-file'),
isOptionEnabled = require('./is-option-enabled'),
addBundleResultsToFile = require('./results/add-bundle-results-to-file'),
BundleKeys = require('./model/bundle-keys');
BundleKeys = require('./model/bundle-keys'),
isMinEnabled = require('./is-min-enabled');

module.exports.scripts = function (opts) {
return gulp.src(opts.src, {base: opts.base})
Expand All @@ -21,8 +21,7 @@ module.exports.scripts = function (opts) {
.pipe(opts.bundleOptions.transforms[BundleKeys.SCRIPTS]())
.pipe(through.obj(verifySourcemaps))
.pipe(gif(function (file) {
return !isMinSrcDefinedForFile(file, opts.minSrcs, opts.bundleName, opts.type) &&
isOptionEnabled(opts.bundleOptions.uglify, opts.env);
return isMinEnabled.js(file, opts);
},
gif(function (file) {
return file.isStream();
Expand Down Expand Up @@ -53,8 +52,7 @@ module.exports.styles = function (opts) {
.pipe(opts.bundleOptions.transforms[BundleKeys.STYLES]())
.pipe(through.obj(verifySourcemaps))
.pipe(gif(function (file) {
return !isMinSrcDefinedForFile(file, opts.minSrcs, opts.bundleName, opts.type) &&
isOptionEnabled(opts.bundleOptions.minCSS, opts.env);
return isMinEnabled.css(file, opts);
}, minifyCSS()))
.pipe(concat(opts.bundleName + ((opts.isBundleAll && opts.env) ? '.' + opts.env : '') + '.css'))
.pipe(gif(isOptionEnabled(opts.bundleOptions.rev, opts.env), rev()))
Expand Down
2 changes: 1 addition & 1 deletion test/integ/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('integration tests', function () {
helpers.getJsSrcMapLine(file.relative));
} else if (file.relative === 'vendor.css') {
fileContents.should.eql(
'.bootstrap.min{background-color:#00f}\n.bootstrap-theme.min{background-color:#00f}\n' +
'.bootstrap.min {\n background-color: blue;\n}\n.bootstrap-theme.min {\n background-color: blue;\n}\n' +
helpers.getCssSrcMapLine(file.relative));
} else if (helpers.stringEndsWith(file.relative, '.map') ||
file.relative === 'dist/fonts/glyphicons-halflings-regular.eot' ||
Expand Down
73 changes: 73 additions & 0 deletions test/unit/is-min-enabled-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
var libPath = './../../lib',
should = require('should'),
sinon = require('sinon'),
proxyquire = require('proxyquire'),
File = require('vinyl');

describe('is-min-enabled', function () {

describe('when option enabled', function () {

var fileStub,
isOptionEnabledStub,
opts;

beforeEach(function () {
var fileStub = new File({
cwd: "/",
base: "/test/",
path: "/test/file",
contents: new Buffer("")
});
isOptionEnabledStub = sinon.stub().returns(true);
opts = {
bundleOptions: {}
};
});

it('and min src defined should return true', function () {
var isMinSrcDefinedForFileStub = sinon.stub().returns(false);
var isMinEnabled = proxyquire(libPath + '/is-min-enabled', {
'./is-min-src-defined-for-file': isMinSrcDefinedForFileStub,
'./is-option-enabled': isOptionEnabledStub
});
isMinEnabled.js(fileStub, opts).should.be.ok;
isMinEnabled.css(fileStub, opts).should.be.ok;
});

it('and min src NOT defined should return false', function () {
var isMinSrcDefinedForFileStub = sinon.stub().returns(true);
var isMinEnabled = proxyquire(libPath + '/is-min-enabled', {
'./is-min-src-defined-for-file': isMinSrcDefinedForFileStub,
'./is-option-enabled': isOptionEnabledStub
});
isMinEnabled.js(fileStub, opts).should.be.not.ok;
isMinEnabled.css(fileStub, opts).should.be.not.ok;
});

});

describe('when getMinCssOption called', function () {
var opts,
isMinEnabled = require(libPath + '/is-min-enabled');

beforeEach(function () {
opts = {
bundleOptions: {
}
};
});

it('should return minCSS key', function () {
opts.bundleOptions.minCSS = false;
should(isMinEnabled.getMinCssOption(opts)).eql(false);
});

it('should return minCss key', function () {
opts.bundleOptions.minCss = false;
should(isMinEnabled.getMinCssOption(opts)).eql(false);
});

});

});

0 comments on commit c849faf

Please sign in to comment.