This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
63 lines (53 loc) · 1.74 KB
/
utils.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
57
58
59
60
61
62
63
const { Client } = require('pg');
var config = require(__dirname + '/config.json');
const defaultConfig = require(__dirname + '/default-config.json');
const client = new Client(config.DB);
const fs = require('fs');
const path = require('path');
const UtilMgr = require(`${__dirname}/utils/utils.js`)(client);
/* config update */
var _configRewriteNeeded = false;
for ( _rootKey in defaultConfig )
{
if ( !( _rootKey in config ) )
{
console.warn(`[WARNING] '${_rootKey}' is missing in config, but exists in default. Copying to stay up to date...`);
config[_rootKey] = defaultConfig[_rootKey];
_configRewriteNeeded = true;
}
if ( typeof(defaultConfig[_rootKey]) == "object" )
{
for ( _inKey in defaultConfig[_rootKey] )
{
if ( !( _inKey in config[_rootKey] ) )
{
console.warn(`[WARNING] '${_inKey}' in '${_rootKey}' is missing in config, but exists in default. Copying to stay up to date...`);
config[_rootKey][_inKey] = defaultConfig[_rootKey][_inKey];
_configRewriteNeeded = true;
}
}
}
}
if ( _configRewriteNeeded )
fs.writeFileSync(__dirname + "/config.json", JSON.stringify(config, null, 2));
/* config update end */
client.connect()
.catch((e)=>{ console.log(e); });
var Utils = {};
Utils.fs = fs;
Utils.serviceName = config['env']['service'];
Utils.ToMinify = [
// + Scripts
`${__dirname}/static/scripts/public.js`,
// + Styles
`${__dirname}/static/styles/public.css`
];
/* utils methods */
Utils.Minify = UtilMgr.Require('minify');
Utils.Misc = UtilMgr.Require('misc');
Utils.Games = UtilMgr.Require('games');
Utils.Commits = UtilMgr.Require('commits');
Utils.Employees = UtilMgr.Require('employees');
Utils.Blog = UtilMgr.Require('blog');
Utils.Processors = UtilMgr.Require('processors');
module.exports = Utils;