-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbootstraphelper.js
35 lines (35 loc) · 1.03 KB
/
bootstraphelper.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
const Storage = require('./lib/storage.js');
const fs = require('fs');
const Path = require('path');
module.exports = function (saveFolder) {
return {
safeLoad : function (func, label) {
if (!label) {
label = func.toSource().replace(/[\r\n]/g, " \\n ")
}
try {
func();
} catch (e) {
console.error("fail to load " + label + " due to " + e.toString());
}
},
createStorage : function (path) {
try {
var stat = fs.statSync(Path.resolve(__dirname, saveFolder))
if (!stat.isDirectory()) {
var error = new Error('not a directory')
error.type = "not_a_directory"
throw error;
}
} catch (e) {
if (e.type == "not_a_directory") {
throw new Error("fail to create folder, target is not a folder");
} else {
fs.mkdirSync(Path.resolve(__dirname, saveFolder));
}
}
var storage = new Storage(Path.resolve(__dirname, saveFolder, path));
return storage;
}
};
}