Skip to content

Commit

Permalink
Merge branch 'autoprefixer'. Closes #64
Browse files Browse the repository at this point in the history
* autoprefixer:
  Added autoprefixer transform to buildProduction transform and binary
  Added autoprefixer transform
  Added test scaffold
  Aded autoprefixer to package.json
  • Loading branch information
Munter committed Jan 19, 2014
2 parents 233d23f + beaff44 commit 375fc14
Show file tree
Hide file tree
Showing 12 changed files with 626 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bin/buildProduction
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ var optimist = require('optimist'),
type: 'boolean',
default: false
})
.options('autoprefix', {
describe: 'Automatically prefix all css based on the rules supplied. See https://github.com/ai/autoprefixer#browsers',
type: 'string',
demand: false
})
.options('debug', {
describe: 'Keep statement level console.*() calls and debugger statements in JavaScript assets',
type: 'boolean',
Expand Down Expand Up @@ -229,6 +234,10 @@ if (commandLineOptions.inlinesize) {
inlineByRelationType.CssImage = 8192;
}

if (commandLineOptions.autoprefix && typeof commandLineOptions === 'string') {
commandLineOptions.autoprefix = [commandLineOptions.autoprefix];
}

(commandLineOptions.define ? _.flatten(_.flatten([commandLineOptions.define])) : []).forEach(function (define) {
var matchDefine = define.match(/^(\w+)(?:=(.*))?$/);
if (matchDefine) {
Expand Down Expand Up @@ -314,6 +323,7 @@ new AssetGraph({root: rootUrl})
less: !commandLineOptions.noless,
optimizeImages: commandLineOptions.optimizeimages,
inlineByRelationType: inlineByRelationType,
autoprefix: commandLineOptions.autoprefix,
gzip: commandLineOptions.gzip,
defines: defines,
reservedNames: reservedNames,
Expand Down
27 changes: 27 additions & 0 deletions lib/transforms/autoprefixer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* autoprefixer transform
*
* - Runs autoprefixer with the supplied options on each css asset
* - Removes all references to prefixfree
*/

var autoprefix = require('autoprefixer');

module.exports = function (options) {
// See https://github.com/ai/autoprefixer#browsers
var browsers = options;

return function autoprefixer(assetGraph) {
assetGraph.findAssets({type: 'Css'}).forEach(function (cssAsset) {
cssAsset.text = autoprefix(browsers).process(cssAsset.text).css;
});

assetGraph.findRelations({
to: {
fileName: /prefixfree(\.min)?\.js/
}
}).forEach(function (relation) {
relation.remove();
});
};
};
3 changes: 3 additions & 0 deletions lib/transforms/buildProduction.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ module.exports = function (options) {
return assetGraph;
})
.removeNobundleAttribute({type: ['HtmlScript', 'HtmlStyle']})
.if(options.autoprefix)
.autoprefixer(options.autoprefix)
.endif()
.if(inlineByRelationType.CssImage)
.inlineCssImagesWithLegacyFallback({type: 'Html', isInline: false, isFragment: false}, inlineByRelationType.CssImage)
.endif()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dependencies": {
"assetgraph": "=1.6.2",
"async": "=0.2.9",
"autoprefixer": "~1.0.20140117",
"extend": "=1.2.1",
"chalk": "=0.4.0",
"express-processimage": "=0.1.12",
Expand Down
55 changes: 55 additions & 0 deletions test/autoprefixer-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var vows = require('vows'),
assert = require('assert'),
AssetGraph = require('../lib/AssetGraph');

vows.describe('transforms.autoprefixer').addBatch({
'After loading an unprefixed test case': {
topic: function () {
new AssetGraph({root: __dirname + '/autoprefixer/'})
.loadAssets('index.html')
.populate()
.run(this.callback);
},
'the graph should contain 2 HtmlStyle relations': function (assetGraph) {
assert.equal(assetGraph.findRelations({type: 'HtmlStyle'}).length, 2);
},
'the graph should contain 1 CssImage relation': function (assetGraph) {
assert.equal(assetGraph.findRelations({type: 'CssImage'}).length, 1);
},
'then running the autoprefixer transform': {
topic: function (assetGraph) {
assetGraph
.autoprefixer()
.run(this.callback);
},
'the graph should contain 2 HtmlStyle relations': function (assetGraph) {
assert.equal(assetGraph.findRelations({type: 'HtmlStyle'}).length, 2);
},
'the graph should contain 3 CssImage relation': function (assetGraph) {
assert.equal(assetGraph.findRelations({type: 'CssImage'}).length, 3);
}
}
},
'After loading an test case using prefixfree.js': {
topic: function () {
new AssetGraph({root: __dirname + '/autoprefixer/'})
.loadAssets('prefixfree.html')
.populate()
.run(this.callback);
},
'the graph should contain 2 HtmlScript relations': function (assetGraph) {
assert.equal(assetGraph.findRelations({type: 'HtmlScript'}).length, 2);
},
'then running the autoprefixer transform': {
topic: function (assetGraph) {
assetGraph
.autoprefixer()
.run(this.callback);
},
'the graph should contain 0 HtmlScript relations': function (assetGraph) {
assert.equal(assetGraph.findRelations({type: 'HtmlScript'}).length, 0);
}
}
}

})['export'](module);
3 changes: 3 additions & 0 deletions test/autoprefixer/borderimage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
border-image: url(borderimage.png) 30 30 repeat;
}
Binary file added test/autoprefixer/borderimage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions test/autoprefixer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="userselect.css">
<link rel="stylesheet" type="text/css" href="borderimage.css">
</head>
<body>

</body>
</html>
13 changes: 13 additions & 0 deletions test/autoprefixer/prefixfree.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>

<script src="prefixfree.js"></script>
<script src="prefixfree.min.js"></script>
</head>
<body>

</body>
</html>
Loading

0 comments on commit 375fc14

Please sign in to comment.