-
Notifications
You must be signed in to change notification settings - Fork 227
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
Showing
19 changed files
with
598 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,3 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" |
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,5 @@ | ||
=== HEAD | ||
|
||
=== 0.1.1 (March 24, 2014) | ||
|
||
* Initial release |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Nicolas Gallagher, Segment.io | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,65 @@ | ||
# suitcss-preprocessor | ||
|
||
Preprocessor for working with SUIT CSS packages. | ||
|
||
[](http://travis-ci.org/suitcss/preprocessor) | ||
|
||
## Installation | ||
|
||
``` | ||
npm install suitcss-preprocessor | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
suitcss input.css output.css | ||
``` | ||
|
||
## Features | ||
|
||
Provides a CLI and Node.js interface for a preprocessor that combines | ||
[rework-suit](https://github.com/suitcss/rework-suit) with | ||
[autoprefixer](https://github.com/ai/autoprefixer). | ||
|
||
## API | ||
|
||
#### Command Line | ||
|
||
``` | ||
Usage: suitcss [<input>] [<output>] | ||
Options: | ||
-h, --help output usage information | ||
-V, --version output the version number | ||
-w, --watch watch the input file for changes | ||
-v, --verbose log verbose output for debugging | ||
Examples: | ||
# pass an input and output file: | ||
$ suitcss input.css output.css | ||
# watch the input file for changes: | ||
$ suitcss --watch input.css output.css | ||
# unix-style piping to stdin and stdout: | ||
$ cat input.css | suitcss | grep background-color | ||
``` | ||
|
||
#### Node.js | ||
|
||
```js | ||
var suitcss = require('suitcss'); | ||
var fs = require('fs'); | ||
|
||
var css = fs.readFileSync('index.css', 'utf8'); | ||
var converted = myth(css); | ||
|
||
fs.writeFileSync('converted.css', converted); | ||
``` | ||
|
||
## Acknowledgements | ||
|
||
Based on [Myth](https://github.com/segmentio/myth) by Segment.io. |
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,117 @@ | ||
var colors = require('colors'); | ||
var pad = require('pad-component').left; | ||
|
||
/** | ||
* Log. | ||
* | ||
* @param {String} type | ||
* @param {String} message | ||
*/ | ||
|
||
exports.log = function (type, message) { | ||
padding(); | ||
log(type, message); | ||
}; | ||
|
||
/** | ||
* Fatal, exits the process with an error. | ||
* | ||
* @param {String} type | ||
* @param {String} message | ||
*/ | ||
|
||
exports.fatal = function (type, message) { | ||
if (padded) console.log(); | ||
padding(); | ||
error(type, message, 'red'); | ||
process.exit(1); | ||
}; | ||
|
||
/** | ||
* Throw a pretty fatal error from an `err`. | ||
* | ||
* @param {Error} err | ||
*/ | ||
|
||
exports.throw = function (err) { | ||
if (padded) console.log(); | ||
padding(); | ||
|
||
// node errors (or faulty plugins) | ||
if (!err.position) { | ||
error('error', err.toString(), 'red', 'red'); | ||
err.stack.split('\n').slice(1).forEach(function (line) { | ||
error('', line.slice(2)); | ||
}); | ||
} | ||
|
||
// rework plugin errors | ||
else { | ||
var pos = err.position; | ||
var start = pos.start; | ||
var end = pos.end; | ||
var lines = err.css.split('\n'); | ||
|
||
error('error', err.toString(), 'red', 'red'); | ||
error('', ' at ' + pos.source + ':' + start.line + ':' + start.column); | ||
error(); | ||
|
||
for (var i = start.line - 3; i < end.line + 2; i++) { | ||
var line = lines[i]; | ||
if (line === undefined) continue; | ||
var color = i == start.line - 1 ? 'red' : 'grey'; | ||
error((i + 1).toString(), ' ' + line, color, color); | ||
} | ||
} | ||
|
||
process.exit(1); | ||
}; | ||
|
||
/** | ||
* Log to stdout. | ||
*/ | ||
|
||
function log () { | ||
var msg = format.apply(this, arguments); | ||
console.log(msg); | ||
} | ||
|
||
/** | ||
* Log to stderr. | ||
*/ | ||
|
||
function error () { | ||
var msg = format.apply(this, arguments); | ||
console.error(msg); | ||
} | ||
|
||
/** | ||
* Format a `type` and `msg` with `typeColor` and `msgColor`. | ||
* | ||
* @param {String} type | ||
* @param {String} msg | ||
* @param {String} typeColor (optional) | ||
* @param {String} msgColor (optional) | ||
*/ | ||
|
||
function format (type, msg, typeColor, msgColor) { | ||
type = type || ''; | ||
msg = msg || ''; | ||
typeColor = typeColor || 'blue'; | ||
msgColor = msgColor || 'grey'; | ||
type = pad(type, 12); | ||
return type[typeColor] + ' · ' + msg[msgColor]; | ||
} | ||
|
||
/** | ||
* Add padding to the output. | ||
*/ | ||
|
||
var padded = false; | ||
|
||
function padding () { | ||
if (padded) return; | ||
console.log(); | ||
process.on('exit', function () { console.log(); }); | ||
padded = true; | ||
} |
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,97 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
var exists = fs.existsSync; | ||
var logger = require('./logger'); | ||
var suitcss = require('..'); | ||
var path = require('path'); | ||
var resolve = path.resolve; | ||
var program = require('commander'); | ||
var read = require('read-file-stdin'); | ||
var watch = require('node-watch'); | ||
var write = require('write-file-stdout'); | ||
|
||
/** | ||
* Usage. | ||
*/ | ||
|
||
program | ||
.version(require('../package.json').version) | ||
.usage('[<input>] [<output>]') | ||
.option('-w, --watch', 'watch the input file for changes') | ||
.option('-v, --verbose', 'log verbose output for debugging'); | ||
|
||
/** | ||
* Examples. | ||
*/ | ||
|
||
program.on('--help', function () { | ||
console.log(' Examples:'); | ||
console.log(); | ||
console.log(' # pass an input and output file:'); | ||
console.log(' $ suitcss input.css output.css'); | ||
console.log(); | ||
console.log(' # watch the input file for changes:'); | ||
console.log(' $ suitcss --watch input.css output.css'); | ||
console.log(); | ||
console.log(' # unix-style piping to stdin and stdout:'); | ||
console.log(' $ cat input.css | suitcss | grep background-color'); | ||
console.log(); | ||
}); | ||
|
||
/** | ||
* Parse. | ||
*/ | ||
|
||
program.parse(process.argv); | ||
|
||
/** | ||
* Settings. | ||
*/ | ||
|
||
var input = program.args[0] ? resolve(program.args[0]) : null; | ||
var output = program.args[1] ? resolve(program.args[1]) : null; | ||
var verbose = program.verbose; | ||
var regen = program.watch && input && output; | ||
|
||
/** | ||
* Exists? | ||
*/ | ||
|
||
if (input && !exists(input)) logger.fatal('not found', input); | ||
|
||
/** | ||
* Run. | ||
*/ | ||
|
||
run(); | ||
|
||
/** | ||
* Watch? | ||
*/ | ||
|
||
if (regen) { | ||
watch(input, run); | ||
if (verbose) logger.log('watch', input); | ||
} | ||
|
||
/** | ||
* Run for the given input and output. | ||
*/ | ||
|
||
function run () { | ||
read(input, function (err, buffer) { | ||
if (err) logger.throw(err); | ||
var css = buffer.toString(); | ||
|
||
try { | ||
css = suitcss(css, { source: input }); | ||
} catch (e) { | ||
e.css = css; | ||
logger.throw(e); | ||
} | ||
|
||
write(output, css + '\n'); | ||
if (verbose && output) logger.log('write', output); | ||
}); | ||
} |
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,42 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
|
||
var autoprefixer = require('autoprefixer'); | ||
var rework = require('rework'); | ||
var suit = require('rework-suit'); | ||
|
||
/** | ||
* Module export | ||
*/ | ||
|
||
module.exports = preprocessor; | ||
|
||
/** | ||
* Process CSS | ||
* | ||
* @param {String} css | ||
* @return {String} | ||
*/ | ||
|
||
function preprocessor(css, options) { | ||
if (typeof css !== 'string') { | ||
throw new Error('suitcss-preprocessor: did not receive a String'); | ||
} | ||
|
||
var browserConfig = [ | ||
'Explorer >= 8', | ||
'last 2 Chrome versions', | ||
'last 2 Firefox versions', | ||
'last 2 Safari versions', | ||
'last 2 iOS versions', | ||
'Android 4' | ||
]; | ||
|
||
css = rework(css, options).use(suit).toString(); | ||
|
||
// vendor prefixes | ||
css = autoprefixer(browserConfig).process(css).css; | ||
|
||
return css; | ||
} |
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,36 @@ | ||
{ | ||
"name": "suitcss-preprocessor", | ||
"version": "0.1.1", | ||
"description": "A CSS preprocessor for working with SUIT CSS packages", | ||
"keywords": [ | ||
"css", | ||
"preprocessor", | ||
"pure", | ||
"rework", | ||
"suit" | ||
], | ||
"main": "lib/index.js", | ||
"bin": { | ||
"suitcss": "bin/suitcss" | ||
}, | ||
"scripts": { | ||
"test": "mocha --reporter spec --slow 400", | ||
"watch": "mocha --watch --reporter spec --slow 400" | ||
}, | ||
"dependencies": { | ||
"autoprefixer": "~1.1.20140319", | ||
"colors": "~0.6.2", | ||
"commander": "~2.1.0", | ||
"node-watch": "0.3.4", | ||
"pad-component": "0.0.1", | ||
"read-file-stdin": "0.0.3", | ||
"rework": "~0.20.1", | ||
"rework-suit": "~1.0.0", | ||
"write-file-stdout": "0.0.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.15.1" | ||
}, | ||
"repository": "git://github.com/suitcss/preprocessor.git", | ||
"license": "MIT" | ||
} |
Oops, something went wrong.