forked from OriginTrail/ot-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (53 loc) · 2.33 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* eslint-disable no-console */
import 'dotenv/config';
import fs from 'fs-extra';
import OTNode from './ot-node.js';
import { NODE_ENVIRONMENTS } from './src/constants/constants.js';
process.env.NODE_ENV =
process.env.NODE_ENV && Object.values(NODE_ENVIRONMENTS).includes(process.env.NODE_ENV)
? process.env.NODE_ENV
: NODE_ENVIRONMENTS.DEVELOPMENT;
(async () => {
let userConfig = null;
try {
if (process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT && process.argv.length === 3) {
const configurationFilename = process.argv[2];
userConfig = JSON.parse(await fs.promises.readFile(process.argv[2]));
userConfig.configFilename = configurationFilename;
}
} catch (error) {
console.log('Unable to read user configuration from file: ', process.argv[2]);
process.exit(1);
}
try {
const node = new OTNode(userConfig);
await node.start();
} catch (e) {
console.error(`Error occurred while start ot-node, error message: ${e}. ${e.stack}`);
// console.error(`Trying to recover from older version`);
// if (process.env.NODE_ENV !== NODE_ENVIRONMENTS.DEVELOPMENT) {
// const rootPath = path.join(appRootPath.path, '..');
// const oldVersionsDirs = (await fs.promises.readdir(rootPath, { withFileTypes: true }))
// .filter((dirent) => dirent.isDirectory())
// .map((dirent) => dirent.name)
// .filter((name) => semver.valid(name) && !appRootPath.path.includes(name));
//
// if (oldVersionsDirs.length === 0) {
// console.error(
// `Failed to start OT-Node, no backup code available. Error message: ${e.message}`,
// );
// process.exit(1);
// }
//
// const oldVersion = oldVersionsDirs.sort(semver.compare).pop();
// const oldversionPath = path.join(rootPath, oldVersion);
// execSync(`ln -sfn ${oldversionPath} ${rootPath}/current`);
// await fs.promises.rm(appRootPath.path, { force: true, recursive: true });
// }
process.exit(1);
}
})();
process.on('uncaughtException', (err) => {
console.error('Something went really wrong! OT-node shutting down...', err);
process.exit(1);
});