gancio-upstream/server/cli.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-10-21 16:18:58 +02:00
#!/usr/bin/env node
const pkg = require('../package.json')
const path = require('path')
2023-06-30 23:50:01 +02:00
const usersCLI = require('./cli/users')
2021-10-21 16:18:58 +02:00
2021-10-21 20:49:49 +02:00
process.env.cwd = process.env.GANCIO_DATA || path.resolve('./')
2021-10-21 16:18:58 +02:00
process.chdir(path.resolve(__dirname, '..'))
async function start () {
require('@nuxt/cli-edge').run(['start', '--modern'])
.catch((error) => {
console.error(error)
process.exit(2)
})
}
2024-06-11 11:28:27 +02:00
async function migrate () {
const config = require('./config')
if (config.status === 'SETUP') {
console.error('> Cannot run database migration before setup')
return
}
const db = require('./api/models/index')
db.connect()
await db.sequelize.authenticate()
await db.runMigrations()
}
2021-10-25 11:05:29 +02:00
console.info(`📅 ${pkg.name} - v${pkg.version} - ${pkg.description} (nodejs: ${process.version})`)
2021-10-21 16:18:58 +02:00
require('yargs')
.usage('Usage $0 <command> [options]')
.option('config', {
alias: 'c',
describe: 'Configuration file',
2022-05-05 16:01:39 +02:00
default: path.resolve(process.env.cwd, 'config.json'),
coerce: config_path => {
const absolute_config_path = path.resolve(process.env.cwd, config_path)
process.env.config_path = absolute_config_path
return absolute_config_path
}})
2024-06-11 11:28:27 +02:00
.command(['migrate'], 'Run database migration', migrate)
2021-10-21 16:18:58 +02:00
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
2023-06-30 23:50:01 +02:00
.command(['users'], 'Manage users', usersCLI)
2021-10-21 16:18:58 +02:00
.help('h')
.alias('h', 'help')
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
2022-05-05 16:01:39 +02:00
.recommendCommands()
.demandCommand(1, '')
2021-10-21 16:18:58 +02:00
.argv