Introduce config module

This commit is contained in:
Akihiko Odaki
2018-04-02 13:15:53 +09:00
parent 5b9f3701f5
commit 3fb6834f7d
50 changed files with 213 additions and 208 deletions

View File

@@ -4,7 +4,6 @@
Error.stackTraceLimit = Infinity;
import * as fs from 'fs';
import * as os from 'os';
import * as cluster from 'cluster';
import * as debug from 'debug';
@@ -21,8 +20,8 @@ import MachineInfo from './utils/machineInfo';
import DependencyInfo from './utils/dependencyInfo';
import stats from './utils/stats';
import { Config, path as configPath } from './config';
import loadConfig from './config';
import loadConfig from './config/load';
import { Config } from './config/types';
import parseOpt from './parse-opt';
@@ -116,11 +115,17 @@ async function init(): Promise<Config> {
new DependencyInfo().showAll();
const configLogger = new Logger('Config');
if (!fs.existsSync(configPath)) {
throw 'Configuration not found - Please run "npm run config" command.';
}
let config;
const config = loadConfig();
try {
config = loadConfig();
} catch (exception) {
if (exception.code === 'ENOENT') {
throw 'Configuration not found - Please run "npm run config" command.';
}
throw exception;
}
configLogger.info('Successfully loaded');
configLogger.info(`maintainer: ${config.maintainer}`);