Skip to content

Commit fb2b12c

Browse files
author
Maximilian Hoffmann
committed
add basic cli
1 parent c88dcc2 commit fb2b12c

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

.bin/ocss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
3+
var fs = require('fs')
4+
var path = require('path')
5+
var mkdirp = require('mkdirp')
6+
var rimraf = require('rimraf')
7+
8+
var program = require('commander')
9+
var parser = require('ocss-parser')
10+
11+
program
12+
.version(require('../package.json').version)
13+
.usage('<input> <output>')
14+
.parse(process.argv)
15+
16+
var input = program.args[0]
17+
var destination = program.args[1]
18+
19+
var filename = path.basename(input, '.ocss')
20+
var contents = fs.readFileSync(input, 'utf-8')
21+
22+
var ast = parser.parse(filename, contents)
23+
var css = parser.stringify(ast)
24+
25+
rimraf(destination, function() {
26+
27+
mkdirp(path.dirname(destination), function(error) {
28+
if (error) throw error
29+
fs.writeFileSync(destination, css)
30+
console.log('created', destination)
31+
})
32+
33+
})

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
npm-debug.log

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "ocss",
3-
"version": "1.0.0",
3+
"version": "0.0.1",
44
"description": "a CSS preprocessor that restricts you to use best practices",
55
"main": "index.js",
66
"scripts": {
7-
"test": "tape test/index.js | tap-dot"
7+
"test": ".bin/ocss test/src/test.ocss test/dist/test.css"
88
},
99
"repository": {
1010
"type": "git",
@@ -30,6 +30,9 @@
3030
"tape": "^2.14.0"
3131
},
3232
"dependencies": {
33-
"ocss-parser": "^1.3.2"
33+
"commander": "^2.3.0",
34+
"mkdirp": "^0.5.0",
35+
"ocss-parser": "^1.3.2",
36+
"rimraf": "^2.2.8"
3437
}
3538
}

test/dist/test.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.test {
2+
display: block;
3+
color: red;
4+
}
5+
.test-child {
6+
color: blue;
7+
background: transparent;
8+
}
9+
.test-child-subchild {
10+
font-size: 12px;
11+
}
12+
.test-child:hover {
13+
color: red;
14+
}
15+
.test--big {
16+
font-size: 200%;
17+
}
18+
.test--big .test-child {
19+
color: red;
20+
}

test/src/test.ocss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
display: block
2+
color: red
3+
4+
child // comment
5+
color: blue
6+
background: transparent
7+
8+
:hover
9+
color: red
10+
11+
subchild
12+
font-size: 12px
13+
// another comment
14+
=big
15+
font-size: 200%
16+
17+
child
18+
color: red

0 commit comments

Comments
 (0)