Skip to content

Commit

Permalink
Merge pull request #55 from areusjs/feature/plugin-options
Browse files Browse the repository at this point in the history
add pluginOptions config option. Fixes #50
  • Loading branch information
chmontgomery committed May 7, 2015
2 parents 5940020 + 8294156 commit 155efd7
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 20 deletions.
7 changes: 6 additions & 1 deletion examples/full/bundle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function isLessFile(file) {
}

var styleTransforms = lazypipe()
.pipe(function() {
.pipe(function () {
return gif(isLessFile, less());
});

Expand Down Expand Up @@ -82,6 +82,11 @@ module.exports = {
transforms: {
scripts: transformHelper.coffee(),
styles: styleTransforms // stream that will transform less
},
pluginOptions: { // pass additional options to underlying gulp plugins. By default the options object is empty
'gulp-minify-css': {processImport: false},
'gulp-uglify': {mangle: false},
'gulp-concat': {stat: {mode: 0666}}
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions examples/full/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"scripts": "<script src='/public/vendor-b9c14db4.js' type='text/javascript'></script>"
},
"header": {
"scripts": "<script src='/public/header-c380f873.js' type='text/javascript'></script>",
"styles": "<link href='/public/header-450a885f.css' media='all' rel='stylesheet' type='text/css'/>"
"styles": "<link href='/public/header-450a885f.css' media='all' rel='stylesheet' type='text/css'/>",
"scripts": "<script src='/public/header-c380f873.js' type='text/javascript'></script>"
},
"article": {
"styles": "<link href='/public/article-eb84c68e.css' media='all' rel='stylesheet' type='text/css'/>",
"scripts": "<script src='/public/article-1abef37b.js' type='text/javascript'></script>"
"scripts": "<script src='/public/article-19f4f978.js' type='text/javascript'></script>"
},
"main": {
"scripts": "<script src='/public/main-a2f0720d.js' type='text/javascript'></script>",
"styles": "<link href='/public/main-56c9e7f7.css' media='all' rel='stylesheet' type='text/css'/>"
"styles": "<link href='/public/main-56c9e7f7.css' media='all' rel='stylesheet' type='text/css'/>",
"scripts": "<script src='/public/main-a2f0720d.js' type='text/javascript'></script>"
}
}
4 changes: 4 additions & 0 deletions examples/full/public/article-19f4f978.js

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

4 changes: 0 additions & 4 deletions examples/full/public/article-1abef37b.js

This file was deleted.

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

4 changes: 4 additions & 0 deletions lib/init-option-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ module.exports = function (bundle) {
bundle[BundleKeys.OPTIONS].transforms[BundleKeys.SCRIPTS] = bundle[BundleKeys.OPTIONS].transforms[BundleKeys.SCRIPTS] || gutil.noop;
bundle[BundleKeys.OPTIONS].transforms[BundleKeys.STYLES] = bundle[BundleKeys.OPTIONS].transforms[BundleKeys.STYLES] || gutil.noop;
bundle[BundleKeys.OPTIONS].watch = bundle[BundleKeys.OPTIONS].watch || {};
bundle[BundleKeys.OPTIONS].pluginOptions = bundle[BundleKeys.OPTIONS].pluginOptions || {};
bundle[BundleKeys.OPTIONS].pluginOptions['gulp-minify-css'] = bundle[BundleKeys.OPTIONS].pluginOptions['gulp-minify-css'] || {};
bundle[BundleKeys.OPTIONS].pluginOptions['gulp-uglify'] = bundle[BundleKeys.OPTIONS].pluginOptions['gulp-uglify'] || {};
bundle[BundleKeys.OPTIONS].pluginOptions['gulp-concat'] = bundle[BundleKeys.OPTIONS].pluginOptions['gulp-concat'] || {};
};
19 changes: 12 additions & 7 deletions lib/stream-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var gulp = require('gulp'),
isOptionEnabled = require('./is-option-enabled'),
addBundleResultsToFile = require('./results/add-bundle-results-to-file'),
BundleKeys = require('./model/bundle-keys'),
isMinEnabled = require('./is-min-enabled');
isMinEnabled = require('./is-min-enabled'),
defaults = require('lodash').defaults;

module.exports.handleTransformError = function (thisStream, isWatch, bundleName, bundleKey, err) {
logger.log(gutil.colors.red("ERROR in custom transforms for '" + bundleName + "." + bundleKey + "':"));
Expand All @@ -38,7 +39,11 @@ module.exports.attachStreamOptions = function (file, opts) {
};

module.exports.scripts = function (opts) {
var self = this;
var self = this,
concatOpts = defaults({
path: opts.bundleName + ((opts.isBundleAll && opts.env) ? '.' + opts.env : '') + '.js'
}, opts.bundleOptions.pluginOptions['gulp-concat']);

return gulp.src(opts.src, {base: opts.base})
.pipe(using.bundle(opts.bundleName, BundleKeys.SCRIPTS, opts.env, opts.isBundleAll))
.pipe(through.obj(function (file, enc, cb) {
Expand All @@ -65,17 +70,17 @@ module.exports.scripts = function (opts) {
return file.isStream();
},
streamify(
uglify()),
uglify()
uglify(opts.bundleOptions.pluginOptions['gulp-uglify'])),
uglify(opts.bundleOptions.pluginOptions['gulp-uglify'])
)))
.on('error', function (e) {
self.handleTransformError(this, opts.isWatch, opts.bundleName, BundleKeys.SCRIPTS, e);
})
.pipe(gif(function (file) {
return file.isStream();
},
streamify(concat(opts.bundleName + ((opts.isBundleAll && opts.env) ? '.' + opts.env : '') + '.js')),
concat(opts.bundleName + ((opts.isBundleAll && opts.env) ? '.' + opts.env : '') + '.js')
streamify(concat(concatOpts)),
concat(concatOpts)
))
.pipe(gif(isOptionEnabled(opts.bundleOptions.rev, opts.env),
gif(function (file) {
Expand Down Expand Up @@ -113,7 +118,7 @@ module.exports.styles = function (opts) {
))
.pipe(gif(function (file) {
return isMinEnabled.css(file, opts);
}, minifyCSS()))
}, minifyCSS(opts.bundleOptions.pluginOptions['gulp-minify-css'])))
.pipe(concat(opts.bundleName + ((opts.isBundleAll && opts.env) ? '.' + opts.env : '') + '.css'))
.pipe(gif(isOptionEnabled(opts.bundleOptions.rev, opts.env), rev()))
.pipe(gif(function (file) {
Expand Down
4 changes: 2 additions & 2 deletions test/integ/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('integration tests', function () {
VENDOR_CSS_CONTENT_MIN_MINIFIED = '.angular-csp-min {\n font-weight: bold;\n}\n',
VENDOR_CSS_CONTENT_NOT_MINIFIED = '.angular-csp {\n font-weight: bold;\n}\n',
ARTICLE_CONTENT_NOT_UGLIFIED = 'console.log(\"page\")\nconsole.log(\"scroll\")\n(function() {\n var number, square;\n\n number = 42;\n\n square = function(x) {\n return x * x;\n };\n\n}).call(this);\n\n',
ARTICLE_CONTENT_UGLIFIED = 'console.log(\"page\");\nconsole.log(\"scroll\");\n(function(){var n,t;n=42,t=function(n){return n*n}}).call(this);\n',
ARTICLE_CONTENT_UGLIFIED = 'console.log(\"page\");\nconsole.log(\"scroll\");\n(function(){var number,square;number=42,square=function(x){return x*x}}).call(this);\n',
ARTICLE_CSS_CONTENT_MINIFIED = '.page{background-color:red}\n',
ARTICLE_CSS_CONTENT_NOT_MINIFIED = '.other-sass {\n background-color: darkred; }\n\n.page {\n background-color: red;\n}\n\n',
MAIN_CONTENT_NOT_UGLIFIED = 'console.log(\"app\")\nconsole.log(\"controllers\")\nconsole.log(\"directives\")\nconsole.log(\"filters\")\n',
Expand Down Expand Up @@ -406,7 +406,7 @@ describe('integration tests', function () {
fileContents.should.eql(
VENDOR_CSS_CONTENT_MIN_MINIFIED +
helpers.getCssSrcMapLine(file.relative));
} else if (file.relative === 'article-1abef37b.js') {
} else if (file.relative === 'article-19f4f978.js') {
fileContents.should.eql(
ARTICLE_CONTENT_UGLIFIED +
helpers.getJsSrcMapLine(file.relative));
Expand Down
10 changes: 10 additions & 0 deletions test/unit/stream-files-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ describe('stream-files', function () {
result: null,
transforms: {
styles: transformHelper.less()
},
pluginOptions: {
'gulp-minify-css': {},
'gulp-uglify': {},
'gulp-concat': {}
}
}
};
Expand Down Expand Up @@ -64,6 +69,11 @@ describe('stream-files', function () {
result: null,
transforms: {
scripts: transformHelper.coffee()
},
pluginOptions: {
'gulp-minify-css': {},
'gulp-uglify': {},
'gulp-concat': {}
}
}
};
Expand Down

0 comments on commit 155efd7

Please sign in to comment.