-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
executable file
·34 lines (30 loc) · 930 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env node
const cssRazor = require('./index.js').default
const defaultOptions = require('./defaultOptions.js')
const argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.argv
if (process.argv && process.argv.length > 2) {
defaultOptions.outputFile = '' // Default to no output file over cli because of stdout.
const options = Object.assign({}, defaultOptions, argv)
options._.forEach((arg, i) => {
if (arg.indexOf('.html') === arg.length - 5) {
options.html.push(arg)
} else if (arg.indexOf('.css') === arg.length - 4) {
options.css.push(arg)
}
// TODO: Set more CLI options here.
})
cssRazor(options, (err, data) => {
if (err) {
process.stderr.write(err)
process.exit(1)
}
if (options.stdout) {
process.stdout.write(data.css)
process.exit(0)
}
})
} else {
throw new Error('You need to pass arguments to css-razor')
}