mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat(server): bigcapital cli commands
This commit is contained in:
51
packages/server/bin/utils.js
Normal file
51
packages/server/bin/utils.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const Knex = require('knex');
|
||||
const { knexSnakeCaseMappers } = require('objection');
|
||||
const color = require('colorette');
|
||||
const config = require('./config');
|
||||
|
||||
function initSystemKnex() {
|
||||
return Knex({
|
||||
client: config.system.db_client,
|
||||
connection: {
|
||||
host: config.system.db_host,
|
||||
user: config.system.db_user,
|
||||
password: config.system.db_password,
|
||||
database: config.system.db_name,
|
||||
charset: 'utf8',
|
||||
},
|
||||
migrations: {
|
||||
directory: config.system.migrations_dir,
|
||||
},
|
||||
seeds: {
|
||||
directory: config.system.seeds_dir,
|
||||
},
|
||||
pool: { min: 0, max: 7 },
|
||||
...knexSnakeCaseMappers({ upperCase: true }),
|
||||
});
|
||||
}
|
||||
|
||||
function exit(text) {
|
||||
if (text instanceof Error) {
|
||||
console.error(
|
||||
color.red(`${text.detail ? `${text.detail}\n` : ''}${text.stack}`)
|
||||
);
|
||||
} else {
|
||||
console.error(color.red(text));
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function success(text) {
|
||||
console.log(text);
|
||||
process.exit(0);
|
||||
}
|
||||
function log(text) {
|
||||
console.log(text);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
log,
|
||||
success,
|
||||
exit,
|
||||
initSystemKnex,
|
||||
};
|
||||
Reference in New Issue
Block a user