gancio-upstream/server/cli.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
2019-11-06 11:31:56 +01:00
const pkg = require('../package.json')
2019-07-03 16:58:24 +02:00
const path = require('path')
2021-09-30 11:15:21 +02:00
process.env.cwd = path.resolve('./')
2019-07-03 16:58:24 +02:00
// needed by nuxt
2021-09-30 11:15:21 +02:00
if (process.env.NODE_ENV === 'production') {
process.chdir(path.resolve(__dirname, '..'))
}
2021-09-27 10:42:17 +02:00
async function start (options) {
2021-06-04 15:36:03 +02:00
try {
2021-09-30 11:15:21 +02:00
require('./config')
2021-06-04 15:36:03 +02:00
} catch (e) {
2021-09-27 10:42:17 +02:00
console.error(e)
2021-06-04 15:36:03 +02:00
process.exit(-1)
}
2021-04-28 12:44:26 +02:00
2019-07-03 16:58:24 +02:00
require('./index')
}
2021-09-30 11:15:21 +02:00
console.info(`📅 ${pkg.name} - v${pkg.version} - ${pkg.description} (nodejs: ${process.version}, ENV: ${process.env.NODE_ENV})`)
2019-07-03 16:58:24 +02:00
require('yargs')
2019-11-06 11:31:56 +01:00
.usage('Usage $0 <command> [options]')
.option('docker', {
alias: 'd',
describe: 'Inside docker',
default: false,
type: 'boolean'
})
.option('config', {
alias: 'c',
describe: 'Configuration file',
2021-09-30 11:15:21 +02:00
default: path.resolve(process.env.cwd, 'config.json')
2019-11-06 11:31:56 +01:00
})
.coerce('config', config_path => {
2021-09-30 11:15:21 +02:00
const absolute_config_path = path.resolve(process.env.cwd, config_path)
2019-11-06 11:31:56 +01:00
process.env.config_path = absolute_config_path
return absolute_config_path
})
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
.help('h')
.alias('h', 'help')
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
2019-11-06 14:47:44 +01:00
.argv