| 31 | var args = <any>program; |
| 32 | |
| 33 | function parseOptions(path: string) { |
| 34 | if (!path) return; |
| 35 | if (!fs.existsSync(path)) return; |
| 36 | |
| 37 | var content = fs.readFileSync(path).toString(); |
| 38 | |
| 39 | try { |
| 40 | var configs = JSON.parse(content); |
| 41 | return { |
| 42 | port: configs.port, |
| 43 | password: configs.password, |
| 44 | cipherAlgorithm: configs.method, |
| 45 | fork: configs.fork, |
| 46 | cluster: configs.cluster, |
| 47 | timeout: configs.timeout, |
| 48 | management: configs.management, |
| 49 | } |
| 50 | } catch(ex) { |
| 51 | console.warn('Configuration file error'); |
| 52 | console.warn(ex.message); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | var fileOptions = parseOptions(args.config) || {}; |
| 57 | if (fileOptions) Object.getOwnPropertyNames(fileOptions).forEach(n => args[n] = args[n] === undefined ? fileOptions[n] : args[n]); |