Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan Kravchenko
committed
Oct 30, 2013
1 parent
8c60a48
commit 7bc6560
Showing
5 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ results | |
|
||
npm-debug.log | ||
node_modules | ||
|
||
index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
|
||
var main = require(__dirname + '/../'); | ||
|
||
|
||
var input = function(cb) { | ||
var inputFilename = process.argv[2]; | ||
if (inputFilename) { | ||
cb(fs.readFileSync(inputFilename, "utf8")); | ||
} else { | ||
var data = ""; | ||
process.stdin.resume(); | ||
process.stdin.setEncoding('utf8'); | ||
|
||
process.stdin.on('data', function(chunk) { | ||
data += chunk; | ||
}); | ||
|
||
process.stdin.on('end', function() { | ||
cb(data); | ||
}); | ||
} | ||
}; | ||
|
||
var output = function(data) { | ||
var outputFilename = process.argv[3]; | ||
if (outputFilename) { | ||
fs.writeFileSync(outputFilename, data); | ||
} else { | ||
console.log(data); | ||
} | ||
}; | ||
|
||
input(function(data) { | ||
result = main(data); | ||
output(result); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# take gorgeous visionmedia's css utilities | ||
parse = require 'css-parse' | ||
stringify = require 'css-stringify' | ||
|
||
module.exports = (css) -> | ||
# parse it | ||
parsed = parse css | ||
|
||
# extract and group medias and root rules | ||
medias = {} | ||
rootRules = [] | ||
for rule in parsed.stylesheet.rules | ||
if rule.type is 'media' | ||
medias[rule.media] = [] if not medias[rule.media] | ||
medias[rule.media] = medias[rule.media].concat rule.rules | ||
else | ||
rootRules.push rule | ||
|
||
# generate media rules | ||
mediaRules = [] | ||
for media, rules of medias | ||
mediaRules.push | ||
type: "media" | ||
media: media | ||
rules: rules | ||
|
||
# modify parsed AST | ||
parsed.stylesheet.rules = rootRules.concat mediaRules | ||
|
||
# output | ||
stringify parsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "group-css-media-queries", | ||
"description": "CSS postprocessing: group media queries. Useful for postprocessing preprocessed CSS files :)", | ||
"keywords": [ "css", "group", "media", "queries", "postprocessing", "postprocessor" ], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Ivan Kravchenko", | ||
"email": "i@se7ensky.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Se7enSky/group-css-media-queries.git" | ||
}, | ||
"version": "1.0.0", | ||
"main": "index", | ||
"bin": { | ||
"group-css-media-queries": "./bin/group-css-media-queries" | ||
}, | ||
"dependencies": { | ||
"css-parse": "*", | ||
"css-stringify": "*" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "*" | ||
}, | ||
"scripts": { | ||
"prepublish": "./node_modules/.bin/coffee -c index.coffee" | ||
} | ||
} |