30 lines
786 B
JavaScript
30 lines
786 B
JavaScript
#!/usr/bin/env node
|
|
import { ServerTool } from './ServerTool'
|
|
import pino from 'pino'
|
|
import * as pinoExpress from 'pino-pretty-express'
|
|
import path from 'path'
|
|
import fs from 'fs'
|
|
import config from 'config'
|
|
|
|
const serviceName = 'dar-server'
|
|
const isProduction = (process.env.NODE_ENV == 'production')
|
|
let log = null
|
|
|
|
if (isProduction) {
|
|
log = pino( { name: serviceName },
|
|
fs.createWriteStream(path.join(config.get('logDir'), serviceName + '.log'))
|
|
)
|
|
} else {
|
|
const pretty = pinoExpress.pretty({})
|
|
pretty.pipe(process.stdout)
|
|
log = pino({ name: serviceName }, pretty)
|
|
}
|
|
|
|
const tool = new ServerTool(path.basename(process.argv[1], '.js'), log)
|
|
|
|
tool.run(process.argv.slice(2)).then((exitCode) => {
|
|
process.exitCode = exitCode
|
|
}).catch((err) => {
|
|
console.error(err)
|
|
})
|