@@ -10,29 +10,131 @@ This is the new JavaScript version, based on powerful CSS parser [Gonzales PE](h
1010
1111## Installation
1212
13+ Global installation (use as a command-line tool):
14+
15+ ``` bash
16+ npm install csscomb -g
17+ ```
18+
19+ Local installation (use as a command-line tool within current directory):
20+
1321``` bash
1422npm install csscomb
1523```
1624
17- To run ` csscomb ` , you can use the following command from the project root:
25+ To install as a project dependency (package will appear in your dependencies):
26+
27+ ``` bash
28+ npm install csscomb --save
29+ ```
30+
31+ To install as a dev dependency (package will appear in your devDependencies):
32+
33+ ``` bash
34+ npm install csscomb --save-dev
35+ ```
36+
37+ ## CLI usage
38+
39+ To run ` csscomb ` :
40+
41+ ``` bash
42+ csscomb path[ path[...]]
43+ ` ` `
44+
45+ If you installed the package locally, in the project' s directory run:
1846
1947```bash
2048./node_modules/.bin/csscomb path[ path[...]]
2149```
2250
51+ If you run `csscomb -h`, it will show some helpful information:
52+
2353```bash
24- ./node_modules/.bin/ csscomb --help
54+ csscomb -h
2555
2656 Usage: csscomb [options] <file ...>
2757
2858 Options:
2959
3060 -h, --help output usage information
3161 -V, --version output the version number
62+ -v, --verbose verbose mode
3263 -c, --config [path] configuration file path
3364 -l, --lint in case some fixes needed returns an error
3465```
3566
67+ ## Node.js module usage
68+
69+ Besides being a great CLI, `csscomb` can be used in Node.js projects (inside
70+ a plugin or as a dev tool):
71+
72+ ```js
73+ // Require:
74+ var Comb = require(' csscomb' );
75+
76+ // Configure:
77+ var comb = new Comb();
78+ comb.configure(config);
79+
80+ // Use:
81+ comb.processPath(' style.css' );
82+ ```
83+
84+ ### configure(config)
85+
86+ You must configure csscomb before using and config must be a valid JSON.
87+ See [configuration section](#configuration) for more information.
88+
89+ ### processPath(path)
90+
91+ Comb a file or a directory.
92+ Warning: This method rewrites the file.
93+
94+ ```js
95+ // One file:
96+ comb.processPath(' main.scss' );
97+
98+ // Whole directory:
99+ comb.processPath(' assets/styles' );
100+ ```
101+
102+ ### processDirectory(path)
103+
104+ Comb all supported files in a directory.
105+ Warning: This method rewrites the files.
106+
107+ ```js
108+ comb.processDirectory(' public/css' );
109+ ```
110+
111+ ### processFile(path)
112+
113+ Comb one file.
114+ If file' s syntax is not supported, the file will be ignored.
115+ Warning: This method rewrites the file.
116+
117+ ` ` ` js
118+ comb.processFile(' print.less' );
119+ ` ` `
120+
121+ # ## processString(text, syntax, filename)
122+
123+ Comb a stylesheet.
124+ If style' s syntax is different from `css`, you should pass `syntax` parameter,
125+ too.
126+ `filename` is optional, it' s used to print possible errors.
127+
128+ ` ` ` js
129+ // Comb a css string:
130+ var css = ' a {top: 0; left: 0}' ;
131+ var combedCSS = comb.processString(css);
132+
133+ // Comb a less string:
134+ var less = ' @color: tomato; a {color: @color}' ;
135+ var combedLESS = comb.processString(less, ' less' );
136+ ` ` `
137+
36138# # Configuration
37139
38140` csscomb` is configured using [.csscomb.json](https://github.com/csscomb/csscomb.js/blob/master/.csscomb.json) file, located in the project root.
@@ -76,7 +178,8 @@ Available value: `{Boolean}` `true`
76178
77179Config mode: ` { " verbose" : true }`
78180` ` ` bash
79- $ ./bin/csscomb ./test
181+ ./bin/csscomb ./test
182+
80183✓ test/integral.origin.css
81184 test/integral.expect.css
82185
@@ -87,8 +190,8 @@ $ ./bin/csscomb ./test
87190
88191CLI mode:
89192` ` ` bash
90- $ ./bin/csscomb ./test --verbose
91- $ ./bin/csscomb ./test -v
193+ ./bin/csscomb ./test --verbose
194+ ./bin/csscomb ./test -v
92195` ` `
93196
94197# ## always-semicolon
0 commit comments