2020-06-30 23:42:59 +08:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-23 00:29:05 +08:00
|
|
|
const metro = require('./metro');
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
2020-06-30 23:42:59 +08:00
|
|
|
|
2020-07-23 00:29:05 +08:00
|
|
|
const { CONFIG_PATH = path.resolve(__dirname, './config.json') } = process.env;
|
|
|
|
const existsConfigFile = fs.existsSync(CONFIG_PATH);
|
2020-07-01 01:41:36 +08:00
|
|
|
|
2020-07-23 00:29:05 +08:00
|
|
|
if (!existsConfigFile) {
|
|
|
|
exit(4)(new Error(`Wrong path for CONFIG_PATH env variable: ${CONFIG_PATH} no such file`));
|
|
|
|
}
|
2020-07-01 01:41:36 +08:00
|
|
|
|
2020-07-23 00:29:05 +08:00
|
|
|
let config;
|
2020-07-01 01:41:36 +08:00
|
|
|
|
2020-07-23 00:29:05 +08:00
|
|
|
if (existsConfigFile) {
|
|
|
|
config = fs.readFileSync(CONFIG_PATH);
|
|
|
|
try {
|
|
|
|
config = JSON.parse(config);
|
|
|
|
} catch (e) {
|
|
|
|
exit(5)(new Error('Wrong config format: invalid JSON'));
|
2020-07-01 01:41:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 00:29:05 +08:00
|
|
|
metro({ metrics: config && config.metrics })
|
|
|
|
.then(exit(0))
|
|
|
|
.catch(exit(1));
|
|
|
|
|
|
|
|
process.on('uncaughtException', exit(2));
|
|
|
|
process.on('unhandledRejection', exit(3));
|
|
|
|
|
|
|
|
function exit (code = 1) {
|
|
|
|
return function (err) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
|
2020-07-01 01:41:36 +08:00
|
|
|
process.exit(code);
|
|
|
|
};
|
|
|
|
}
|