mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
resolve path in cli/log/config
This commit is contained in:
parent
5495880c0b
commit
3b7b2ec6bd
3 changed files with 13 additions and 63 deletions
|
@ -1,48 +1,17 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
process.env.NODE_ENV = 'production'
|
|
||||||
|
|
||||||
const pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const cwd = process.cwd()
|
process.env.cwd = path.resolve('./')
|
||||||
const data_path = process.env.GANCIO_DATA || path.resolve('./')
|
|
||||||
|
|
||||||
// needed by nuxt
|
// needed by nuxt
|
||||||
// process.chdir(path.resolve(__dirname, '..'))
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
process.chdir(path.resolve(__dirname, '..'))
|
||||||
// async function run_migrations (db_conf) {
|
}
|
||||||
// const Umzug = require('umzug')
|
|
||||||
// const Sequelize = require('sequelize')
|
|
||||||
// try {
|
|
||||||
// const db = new Sequelize(db_conf)
|
|
||||||
// const umzug = new Umzug({
|
|
||||||
// storage: 'sequelize',
|
|
||||||
// storageOptions: { sequelize: db },
|
|
||||||
// logging: consola.info,
|
|
||||||
// migrations: {
|
|
||||||
// wrap: fun => {
|
|
||||||
// return () =>
|
|
||||||
// fun(db.queryInterface, Sequelize).catch(e => {
|
|
||||||
// consola.error(e)
|
|
||||||
// return false
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
// path: path.resolve(__dirname, 'migrations')
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// await umzug.up()
|
|
||||||
// return db.close()
|
|
||||||
// } catch (e) {
|
|
||||||
// consola.warn(` ⚠️ Cannot connect to db, check your configuration => ${e}`)
|
|
||||||
// process.exit(-1)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
async function start (options) {
|
async function start (options) {
|
||||||
try {
|
try {
|
||||||
const config = require('./config')
|
require('./config')
|
||||||
config.load()
|
|
||||||
console.info(`Logging to ${path.resolve(`${config.log_path}/gancio.log`)} [level: ${config.log_level}]`)
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
|
@ -51,8 +20,7 @@ async function start (options) {
|
||||||
require('./index')
|
require('./index')
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function setup (options)
|
console.info(`📅 ${pkg.name} - v${pkg.version} - ${pkg.description} (nodejs: ${process.version}, ENV: ${process.env.NODE_ENV})`)
|
||||||
console.info(`📅 ${pkg.name} - v${pkg.version} - ${pkg.description} (nodejs: ${process.version})`)
|
|
||||||
|
|
||||||
require('yargs')
|
require('yargs')
|
||||||
.usage('Usage $0 <command> [options]')
|
.usage('Usage $0 <command> [options]')
|
||||||
|
@ -62,16 +30,13 @@ require('yargs')
|
||||||
default: false,
|
default: false,
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
})
|
})
|
||||||
.option('db', {
|
|
||||||
describe: 'Specify db type'
|
|
||||||
})
|
|
||||||
.option('config', {
|
.option('config', {
|
||||||
alias: 'c',
|
alias: 'c',
|
||||||
describe: 'Configuration file',
|
describe: 'Configuration file',
|
||||||
default: path.resolve(data_path, 'config.json')
|
default: path.resolve(process.env.cwd, 'config.json')
|
||||||
})
|
})
|
||||||
.coerce('config', config_path => {
|
.coerce('config', config_path => {
|
||||||
const absolute_config_path = path.resolve(cwd, config_path)
|
const absolute_config_path = path.resolve(process.env.cwd, config_path)
|
||||||
process.env.config_path = absolute_config_path
|
process.env.config_path = absolute_config_path
|
||||||
return absolute_config_path
|
return absolute_config_path
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,48 +1,32 @@
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const log = require('./log')
|
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
firstrun: true,
|
firstrun: true,
|
||||||
// title: "Gancio",
|
|
||||||
// description: "A shared agenda for local communities",
|
|
||||||
baseurl: "http://localhost:13120",
|
baseurl: "http://localhost:13120",
|
||||||
server: {
|
server: {
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: 13120
|
port: 13120
|
||||||
},
|
},
|
||||||
log_level: 'debug',
|
log_level: 'debug',
|
||||||
log_path: './logs',
|
log_path: path.resolve(process.env.cwd, 'logs'),
|
||||||
db: {},
|
db: {},
|
||||||
upload_path: './uploads',
|
upload_path: path.resolve(process.env.cwd, 'uploads'),
|
||||||
// smtp: {
|
|
||||||
// auth: {
|
|
||||||
// user: '',
|
|
||||||
// pass: ''
|
|
||||||
// },
|
|
||||||
// secure: true,
|
|
||||||
// host: ''
|
|
||||||
// },
|
|
||||||
// admin_email: '',
|
|
||||||
|
|
||||||
//
|
|
||||||
write (config_path= process.env.config_path || './config.json') {
|
write (config_path= process.env.config_path || './config.json') {
|
||||||
log.error(path.resolve(config_path))
|
|
||||||
return fs.writeFileSync(config_path, JSON.stringify(config, null, 2))
|
return fs.writeFileSync(config_path, JSON.stringify(config, null, 2))
|
||||||
},
|
},
|
||||||
|
|
||||||
load () {
|
load () {
|
||||||
// load configuration from file
|
// load configuration from file
|
||||||
console.error(process.env.NODE_ENV)
|
|
||||||
const config_path = process.env.config_path || './config.json'
|
const config_path = process.env.config_path || './config.json'
|
||||||
log.info(`Reading configuration from: ${config_path}`)
|
console.info(`> Reading configuration from: ${config_path}`)
|
||||||
if (fs.existsSync(config_path)) {
|
if (fs.existsSync(config_path)) {
|
||||||
const configContent = fs.readFileSync(config_path)
|
const configContent = fs.readFileSync(config_path)
|
||||||
config = Object.assign(config, JSON.parse(configContent))
|
config = Object.assign(config, JSON.parse(configContent))
|
||||||
config.firstrun = false
|
config.firstrun = false
|
||||||
} else {
|
} else {
|
||||||
config.firstrun = true
|
config.firstrun = true
|
||||||
log.error('configuration file does not exists! we cannot be here!')
|
console.info('> Configuration file does not exists, running setup..')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,5 @@ const logger = createLogger({
|
||||||
)]
|
)]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
logger.info(`Logging to ${config.log_path}/gancio.log (level: ${config.log_level})`)
|
||||||
module.exports = logger
|
module.exports = logger
|
||||||
|
|
Loading…
Reference in a new issue