-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
68 lines (56 loc) · 1.46 KB
/
index.ts
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
64
65
66
67
68
import { initLogger, logger, Logger } from './utils/log-helper'
import sync from './lib/dir-sync/dir-sync'
import executeMount from './lib/service'
import { logHelpMessage } from './utils/help-log'
import EnvConfig from './utils/config/env-config/env-config'
import mountApi from './server'
import LibSync from './utils/config/runtime-config/state'
let mainLogger: Logger
async function runOnce(): Promise<any> {
if (LibSync.options.runBackUp) {
mainLogger.info('Running Backup Sync')
await sync(true)
}
return await sync(false)
}
async function init() {
await EnvConfig.init()
LibSync.state // TODO this is a fucked up way to init lol
initLogger()
if (LibSync.options.runHelp) {
logHelpMessage()
}
mainLogger = logger.child({ func: 'main' })
mainLogger.info('LibSync Initialised.')
}
const main = async () => {
await init()
mainLogger.log(
'info',
'Running with opts src: %s dest: %s debug: %s service: %s',
LibSync.dirs.src,
LibSync.dirs.dest,
LibSync.options.isDebug,
LibSync.options.runOnce,
{
opts: {
src: LibSync.dirs.src,
dest: LibSync.dirs.dest,
opts: { ...LibSync.options },
},
}
)
if (!LibSync.options.runOnce) {
mainLogger.info('Mounting LibSync Service')
executeMount()
if (!LibSync.options.isHeadless) {
mountApi()
}
} else {
mainLogger.info('Running Singular Sync')
runOnce()
}
LibSync.unlock()
}
main()
module.exports = main