-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
55 lines (46 loc) · 1.54 KB
/
index.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
// expose methods for managing symlinks and adding new addons and stuff
var extend = require('xtend');
var partial = require('ap').partial;
var fs = require('fs');
var path = require('path');
var assertOk = require('assert-ok');
module.exports = Manager;
// list of methods that all take in a state first param
var api = require('./lib');
function Manager (options, exitOnError) {
var state = extend({
exitOnError: exitOnError
}, options);
// setup instance
var instance = {};
Object.keys(api).forEach(function (fnName) {
instance[fnName] = partial(api[fnName], state);
});
var dirStat;
var gameStat;
var contentStat;
state.dir = path.normalize(state.dir);
try {
state.dir = fs.realpathSync(state.dir);
} catch (e) {
if (e.code === 'ENOENT') {
instance.exitWithError('Base directory ' + state.dir + ' does not exist!');
}
throw e;
}
try {
dirStat = fs.statSync(state.dir);
gameStat = fs.statSync(path.join(state.dir, './game'));
contentStat = fs.statSync(path.join(state.dir, './content'));
} catch (e) {
if (e.code === 'ENOENT') {
instance.exitWithError('base directory is missing "' + e.path.split('\\').pop() + '" and therefore probably isn\'t the dota 2 beta folder');
}
console.log(state, e, Object.keys(e));
throw e;
}
assertOk(dirStat.isDirectory(), 'base directory is not a directory');
assertOk(gameStat.isDirectory(), 'game directory is not a directory');
assertOk(contentStat.isDirectory(), 'content directory is not a directory');
return instance;
}