-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
29 lines (25 loc) · 853 Bytes
/
main.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
// Prevents us from using variables before declaring them.
"use strict";
var packageConfig = require(__dirname + "/package.config.json");
var fileName = packageConfig.defaultConfigFile;
var args = require("optimist").argv;
var fs = require("fs");
var path = require("path");
if(args[packageConfig.commandLineSwitchName]) {
fileName = args[packageConfig.commandLineSwitchName];
}
var rootDir = process.cwd();
var configData = "";
var filePath = path.normalize(rootDir) + "/" + fileName;
try {
configData = fs.readFileSync(filePath, "utf-8");
module.exports = JSON.parse(configData);
}
catch(e) {
var msg = 'Unable to read or parse file "' + filePath + '". Exception caught: ' + e;
if(packageConfig.throwOnError) {
throw new Error(msg);
}
console.error(msg);
module.exports = null;
}