forked from twitter-archive/recess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recess
executable file
·82 lines (68 loc) · 1.84 KB
/
recess
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env node
var recess = require('../lib')
, watch = require('watch')
, nopt = require('nopt')
, path = require('path')
, fs = require('fs')
, config = '.recessrc'
, writeFile
, options
, output
, paths
// exit with docs
if (process.argv.length == 2) return recess.docs()
// define expected options
options = {
compile: Boolean
, compress: Boolean
, config: path
, noIDs: Boolean
, noJSPrefix: Boolean
, noOverqualifying: Boolean
, noUnderscores: Boolean
, noUniversalSelectors: Boolean
, prefixWhitespace: Boolean
, strictPropertyOrder: Boolean
, version: Boolean
, watch: path
, zeroUnits: Boolean
}
// parse options
shorthand = { 'v': ['--version'] };
options = nopt(options, shorthand, process.argv)
// if help exit
if (options.help) return recess.docs()
// set version
recess.version = require(path.join(__dirname, '..', 'package.json')).version
if (options.version) return console.log(recess.version)
// set path from remaining arguments
paths = options.argv.remain
// clean options object
delete options.argv
// check for config or default .recessrc
if (options.config || (fs.existsSync || path.existsSync)(config)) {
config = JSON.parse(fs.readFileSync(options.config || config))
for (i in options) config[i] = options[i]
options = config
}
// set CLI to true
options.cli = true
// if not watch - run Recess
if (!options.watch) return recess(paths, options)
// set CLI to false
options.cli = false
paths = paths[0].split(':')
output = paths[1]
paths = paths[0]
// generate output and write to file
writeFile = function () {
recess(paths, options, function (err, obj) {
fs.writeFile(output, obj.output)
})
}
// create monitor to watch filetree
watch.createMonitor(options.watch, function (monitor) {
monitor.on("created", writeFile)
monitor.on("changed", writeFile)
monitor.on("removed", writeFile)
})