-
Notifications
You must be signed in to change notification settings - Fork 3
/
snowdrop.js
executable file
·51 lines (47 loc) · 1.46 KB
/
snowdrop.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
var path = require('path')
, fs = require('fs')
, clc = require('cli-color')
, async = require('async')
;
var markerFileName = '.snowdrop.json'
var configFile = null;
module.exports = {
'getPaths':function(dir) {
var cwd = process.cwd();
if(typeof(dir) != 'undefined' && fs.existsSync(dir)) {
cwd = dir;
}
var configFilePaths = [cwd + path.sep + markerFileName];
while(cwd != path.sep) {
configFilePaths.push(path.dirname(cwd) + path.sep + markerFileName);
cwd = path.dirname(cwd);
}
return configFilePaths;
},
'configInPath':function(configFilePaths, callback) {
async.filter(configFilePaths, fs.exists, function(results){
if(results.length > 0) {
callback(true, results.pop());
} else {
callback(false);
}
});
}
}
// Don'r run if we're running the test suite.
if(process.argv[1].match(/mocha/) == null) {
module.exports.configInPath(module.exports.getPaths(), function(result, configFile){
if(result) {
if(process.argv.length > 2 && process.argv[2] == '-u') {
require('./lib/update').update(configFile);
} else {
require('./lib/observe').observe(markerFileName, configFile);
}
} else {
console.log(clc.red('No config file exists.'));
console.log(clc.yellow("Initializing config at " + process.cwd() + path.sep + markerFileName));
require('./lib/create').create(markerFileName);
}
});
}