-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-catch.js
58 lines (47 loc) · 1.35 KB
/
node-catch.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
52
53
54
55
56
57
58
"use strict"
var program = require('commander'),
Q = require('q'),
fs = require('fs'),
Datastore = require('nedb');
var configDb = new Datastore({
filename: 'data/node-catch.config',
autoload: true });
var configFind = Q.denodeify(configDb.find.bind(configDb));
var commandList = ['list','remove','refresh','add'];
configFind({})
.then(function (configs) {
var defaultConfig = {
db: 'data/node-catch.data',
maxCurrency: 4,
storageDirectory: 'podcasts'
};
var config = configs[0] || defaultConfig;
if (configs.length == 0) {
configDb.insert(defaultConfig);
}
var db = new Datastore({
filename: config.db,
autoload: true
});
for (var i = 0; i < commandList.length; i++) {
require('./commands/' + commandList[i] + '.js').configureCommand(program, db, config);
}
fs.readdir(config.storageDirectory, function (err, files) {
if (err) {
fs.mkdir(config.storageDirectory, function (err) {
if (err) {
console.log(err)
process.exit(1);
}
program.parse(process.argv);
});
}
else {
program.parse(process.argv);
}
});
program.version('0.0.1');
})
.catch(function (err) {
console.log(err);
})