Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
vdemedes committed Jan 23, 2016
0 parents commit 466ef73
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
.nyc_output
21 changes: 21 additions & 0 deletions License.md
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Vadim Demedes <vdemedes@gmail.com> (https://github.com/vdemedes)

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.
69 changes: 69 additions & 0 deletions Readme.md
@@ -0,0 +1,69 @@
# cssor

<h1 align="center">
<br>
<img width="300" src="https://cdn.rawgit.com/vdemedes/cssor/master/media/logo.svg" alt="OhCrash">

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

Nice logo!

Oh, and check the alt attribute ;)

This comment has been minimized.

Copy link
@vadimdemedes

vadimdemedes Jan 24, 2016

Owner

Oh damn, thought I got it all :)

This comment has been minimized.

Copy link
@vadimdemedes

vadimdemedes Jan 24, 2016

Owner

Nice logo!

Thank you!

<br>
<br>
<br>
</h1>

Browserify for CSS.

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

I would linkify Browserify for those that don't know what it is.

This comment has been minimized.

Copy link
@vadimdemedes

vadimdemedes Jan 24, 2016

Owner

Good point, haha



## Installation

```
$ npm install --global cssor
```


## Usage

```
$ cssor --help
Usage

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

Should be an empty line above here.

$ cssor [options] [file]
Options
--transform, -t Use a transformer for source files
--output, -o Write output to file
--basedir, -b Set base dir for input file
Examples
$ cat app.css | cssor -t myth -o dist/app.css
$ cssor -i app.css -t myth > dist/app.css
```


## Options

### transform

Add a transformer ([rework](https://github.com/reworkcss/rework) plugin).
Can be set multiple times.

```
$ cssor -t rework-npm -t myth
```

### output

Write output to the file, instead of stdout.

```
$ cssor -o dist/app.css
```

### basedir

Change base directory for @import in stylesheets.

```
$ cssor -b styles
```


## License

MIT © [Vadim Demedes](https://github.com/vdemedes)
75 changes: 75 additions & 0 deletions cli.js
@@ -0,0 +1,75 @@
#!/usr/bin/env node
'use strict';

/**
* Dependencies
*/

var resolveFrom = require('resolve-from');
var getStdin = require('get-stdin');
var arrify = require('arrify');
var rework = require('rework');
var meow = require('meow');
var fs = require('mz/fs');


/**
* CLI
*/

var cli = meow([
'Usage',
' $ cssor [options] [file]',
'',
'Options',
' --transform, -t Use a transformer for source files',
' --output, -o Write output to file',
' --basedir, -b Set base dir for input file',
'',
'Examples',
' $ cat app.css | cssor -t myth -o dist/app.css',
' $ cssor -i app.css -t myth > dist/app.css'
].join('\n'), {
alias: {
t: 'transform',
b: 'basedir',
i: 'input',
o: 'output'
}
});

var filename;
var input;

if (cli.input.length > 0) {
filename = cli.input[0];
input = fs.readFile(filename, 'utf8');
} else {
filename = 'app.css';
input = getStdin();
}

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

Would welcome some feedback on sindresorhus/meow#22, which tries to simplify this.

This comment has been minimized.

Copy link
@vadimdemedes

vadimdemedes Jan 24, 2016

Owner

Will do ;)


input.then(function (source) {
var processor = rework(source, { source: filename });
var transformers = arrify(cli.flags.transform);

transformers.forEach(function (name) {
var path = resolveFrom(process.cwd(), name);

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

You could save 14 characters by using https://github.com/sindresorhus/resolve-cwd instead.

It might sound stupid that it's a separate module, but resolving from cwd is the most common use-case, so I wanted a shortcut.


processor.use(require(path)());
});

if (cli.flags.basedir) {
process.chdir(cli.flags.basedir);
}

var output = processor.toString();

if (cli.flags.output) {
fs.writeFile(cli.flags.output, output, 'utf8');

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

utf8 is moot here as it's the default.

} else {
process.stdout.write(output);
}
}).catch(function (err) {

This comment has been minimized.

Copy link
@sindresorhus
console.error(err.stack);
});
16 changes: 16 additions & 0 deletions media/logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions package.json
@@ -0,0 +1,38 @@
{
"name": "cssor",
"version": "1.0.0",
"description": "Browserify for CSS",
"license": "MIT",
"main": "index.js",

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

You're probably aware, but this is moot when the main file is index.js.

This comment has been minimized.

Copy link
@vadimdemedes

vadimdemedes Jan 24, 2016

Owner

Yeah, just doing it for super extra explicitness :)

"repository": "vdemedes/cssor",
"author": {
"name": "Vadim Demedes",
"email": "vdemedes@gmail.com",
"url": "https://github.com/vdemedes"
},
"scripts": {
"test": "xo"

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

No actual tests '(

See example for simple CLI testing here: https://github.com/sindresorhus/sparkly-cli/blob/master/test.js

This comment has been minimized.

Copy link
@vadimdemedes

vadimdemedes Jan 24, 2016

Owner

It's just a matter of time :) I had to move on fast

},
"bin": {
"cssor": "cli.js"
},

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jan 24, 2016

Can be "bin": "cli.js",

This comment has been minimized.

Copy link
@vadimdemedes

vadimdemedes Jan 24, 2016

Owner

Damn, almost 5 years and I did not know that, thanks!

"files": [
"cli.js"
],
"xo": {
"extends": "vdemedes",
"env": "node"
},
"devDependencies": {
"eslint-config-vdemedes": "^1.0.1",
"xo": "^0.12.1"
},
"dependencies": {
"arrify": "^1.0.1",
"get-stdin": "^5.0.1",
"meow": "^3.7.0",
"mz": "^2.1.0",
"resolve-from": "^2.0.0",
"rework": "^1.0.1"
}
}

1 comment on commit 466ef73

@vadimdemedes
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus Thank you for the tips!

Please sign in to comment.