mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: Ability to hide/show financial statement header.
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
const commander = require('commander');
|
||||
const { knexSnakeCaseMappers } = require('objection');
|
||||
const Knex = require('knex');
|
||||
const color = require('colorette');
|
||||
const argv = require('getopts')(process.argv.slice(2));
|
||||
const systemConfig = require('../config/systemKnexfile');
|
||||
const config = require('../config/config');
|
||||
const {
|
||||
initSystemKnex,
|
||||
getAllSystemTenants,
|
||||
initTenantKnex,
|
||||
exit,
|
||||
success,
|
||||
log,
|
||||
} = require('./utils');
|
||||
const lincenseCommander = require('./license');
|
||||
|
||||
// - bigcapital system:migrate:latest
|
||||
// - bigcapital system:migrate:rollback
|
||||
@@ -16,57 +22,8 @@ const config = require('../config/config');
|
||||
// - bigcapital system:migrate:make
|
||||
// - bigcapital tenants:list
|
||||
|
||||
function initSystemKnex() {
|
||||
return Knex({
|
||||
...systemConfig['production'],
|
||||
...knexSnakeCaseMappers({ upperCase: true }),
|
||||
});
|
||||
}
|
||||
|
||||
function getAllSystemTenants(knex) {
|
||||
return knex('tenants');
|
||||
}
|
||||
|
||||
function initTenantKnex(organizationId) {
|
||||
return Knex({
|
||||
client: config.tenant.db_client,
|
||||
connection: {
|
||||
host: config.tenant.db_host,
|
||||
user: config.tenant.db_user,
|
||||
password: config.tenant.db_password,
|
||||
database: `${config.tenant.db_name_prefix}${organizationId}`,
|
||||
charset: config.tenant.charset,
|
||||
},
|
||||
migrations: {
|
||||
directory: config.tenant.migrations_dir,
|
||||
},
|
||||
seeds: {
|
||||
directory: config.tenant.seeds_dir,
|
||||
},
|
||||
pool: { min: 0, max: 5 },
|
||||
...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);
|
||||
}
|
||||
// - bigcapital license:generate
|
||||
// - bigcapital licenses:list
|
||||
|
||||
commander
|
||||
.command('system:migrate:rollback')
|
||||
|
||||
57
server/bin/license.js
Normal file
57
server/bin/license.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const commander = require('commander');
|
||||
const color = require('colorette');
|
||||
const argv = require('getopts')(process.argv.slice(2));
|
||||
const cryptoRandomString = require('crypto-random-string');
|
||||
const {
|
||||
initSystemKnex,
|
||||
getAllSystemTenants,
|
||||
initTenantKnex,
|
||||
exit,
|
||||
success,
|
||||
log,
|
||||
} = require('./utils');
|
||||
|
||||
// License generate key.
|
||||
commander
|
||||
.command('license:generate <license_period>')
|
||||
.description('Generates a new license key.')
|
||||
.action(async (interval) => {
|
||||
try {
|
||||
const sysDb = initSystemKnex();
|
||||
let repeat = true;
|
||||
|
||||
while(repeat) {
|
||||
key = cryptoRandomString(16).toUpperCase();
|
||||
const license = await sysDb('subscription_licenses').where('key', key);
|
||||
|
||||
if (license.length === 0) {
|
||||
repeat = false;
|
||||
}
|
||||
}
|
||||
const licenseIds = await sysDb('subscription_licenses').insert({
|
||||
key,
|
||||
license_period: interval ? parseInt(interval, 10) : 1,
|
||||
license_interval: 'month',
|
||||
});
|
||||
const license = await sysDb('subscription_licenses').where('id', licenseIds[0]).first();
|
||||
success(`ID: ${license.id} | License: ${license.key} | Interval: ${license.licenseInterval} | Period: ${license.licensePeriod}`);
|
||||
} catch(error) {
|
||||
exit(error);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve licenses list.
|
||||
commander
|
||||
.command('licenses:list')
|
||||
.description('Retrieve a list of subscription licenses.')
|
||||
.action(async () => {
|
||||
const sysDb = initSystemKnex();
|
||||
const licenses = await sysDb('subscription_licenses');
|
||||
|
||||
licenses.forEach((license) => {
|
||||
log(`ID: ${license.id} | Key: ${license.key} | Interval: ${license.licenseInterval} | Period: ${license.licensePeriod}`);
|
||||
});
|
||||
exit();
|
||||
});
|
||||
|
||||
commander.parse(process.argv);
|
||||
67
server/bin/utils.js
Normal file
67
server/bin/utils.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const Knex = require('knex');
|
||||
const { knexSnakeCaseMappers } = require('objection');
|
||||
const color = require('colorette');
|
||||
const config = require('../config/config');
|
||||
const systemConfig = require('../config/systemKnexfile');
|
||||
|
||||
|
||||
function initSystemKnex() {
|
||||
return Knex({
|
||||
...systemConfig['production'],
|
||||
...knexSnakeCaseMappers({ upperCase: true }),
|
||||
});
|
||||
}
|
||||
|
||||
function getAllSystemTenants(knex) {
|
||||
return knex('tenants');
|
||||
}
|
||||
|
||||
function initTenantKnex(organizationId) {
|
||||
return Knex({
|
||||
client: config.tenant.db_client,
|
||||
connection: {
|
||||
host: config.tenant.db_host,
|
||||
user: config.tenant.db_user,
|
||||
password: config.tenant.db_password,
|
||||
database: `${config.tenant.db_name_prefix}${organizationId}`,
|
||||
charset: config.tenant.charset,
|
||||
},
|
||||
migrations: {
|
||||
directory: config.tenant.migrations_dir,
|
||||
},
|
||||
seeds: {
|
||||
directory: config.tenant.seeds_dir,
|
||||
},
|
||||
pool: { min: 0, max: 5 },
|
||||
...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 = {
|
||||
initTenantKnex,
|
||||
initSystemKnex,
|
||||
getAllSystemTenants,
|
||||
exit,
|
||||
success,
|
||||
log,
|
||||
}
|
||||
Reference in New Issue
Block a user