mirror of
https://github.com/EvolutionAPI/evolution-manager.git
synced 2025-07-13 07:04:50 -06:00
add verbose to cli
This commit is contained in:
parent
fc85a4bce8
commit
3e003725d9
22
lib/cli.js
22
lib/cli.js
@ -1,5 +1,6 @@
|
||||
var argv = require('optimist').argv
|
||||
|
||||
const { verbose, isVerbose } = require('./utils/verbose.js')
|
||||
|
||||
const operations = {
|
||||
// 'create': require('./create'),
|
||||
@ -9,22 +10,37 @@ const operations = {
|
||||
'api': require('./api'),
|
||||
}
|
||||
|
||||
const { version } = require('../package.json')
|
||||
|
||||
function main() {
|
||||
try{
|
||||
try {
|
||||
|
||||
console.log('🖥️ evolution-manager CLI: ' + version)
|
||||
console.log('🖥️ Node: ' + process.version)
|
||||
|
||||
verbose('🗣️ Verbose: ' + isVerbose)
|
||||
verbose('🖥️ Platform: ' + process.platform)
|
||||
verbose('🖥️ Architecture: ' + process.arch)
|
||||
verbose('🖥️ PID: ' + process.pid)
|
||||
verbose('🖥️ CWD: ' + process.cwd())
|
||||
verbose('🖥️ argv: ' + JSON.stringify(argv))
|
||||
|
||||
|
||||
var operation = argv._[0]
|
||||
|
||||
if (!operation) operation = 'help'
|
||||
if (!operations[operation]) {
|
||||
console.error('Unknown operation: ' + operation)
|
||||
|
||||
console.error(' ⁉️ Unknown operation: ' + operation)
|
||||
operation = 'help'
|
||||
}
|
||||
verbose('🗣️ Running operation: ' + operation)
|
||||
operations[operation](argv)
|
||||
} catch (e) {
|
||||
console.error(e.message || e)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main()
|
||||
|
||||
|
@ -11,7 +11,6 @@ const functions = {
|
||||
module.exports = async (argv) => {
|
||||
|
||||
try {
|
||||
|
||||
if (argv._.length === 1) throw new Error('No operation specified')
|
||||
|
||||
const operation = argv._[1]
|
||||
|
@ -1,12 +1,14 @@
|
||||
const build = require('../utils/build.js');
|
||||
const verifyPm2Installation = require('../utils/verifyPm2Installation.js');
|
||||
const detectPm2ProcessId = require('../utils/detectPm2ProcessId.js');
|
||||
const { verbose } = require('../utils/verbose')
|
||||
const { exec } = require('child_process')
|
||||
const path = require('path')
|
||||
|
||||
module.exports = async (argv) => {
|
||||
const port = argv.port || 9615;
|
||||
|
||||
|
||||
await verifyPm2Installation(true);
|
||||
await build();
|
||||
|
||||
@ -20,6 +22,7 @@ module.exports = async (argv) => {
|
||||
|
||||
console.log('⚙️ Starting PM2 process')
|
||||
console.time('⚙️ Starting PM2 process')
|
||||
verbose('🗣️ Port: ', port)
|
||||
exec(`pm2 serve dist/ ${port} --name evolution-manager --spa`, { cwd: path.join(__dirname, '..', '..') }, (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
@ -1,6 +1,7 @@
|
||||
const { exec } = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { verbose } = require('./verbose.js')
|
||||
|
||||
module.exports = (envs = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -15,6 +16,8 @@ module.exports = (envs = {}) => {
|
||||
}
|
||||
|
||||
// pass envs to build
|
||||
verbose('🗣️ Build Env: ', envs)
|
||||
|
||||
exec(`npm run build`, { env: envs, cwd: path.join(__dirname, '..', '..') }, (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
@ -34,6 +37,7 @@ module.exports = (envs = {}) => {
|
||||
|
||||
const verifyViteInstallation = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
verbose('🗣️ Verifying Vite installation')
|
||||
exec(`vite --v`, (err) => {
|
||||
if (!err) return resolve()
|
||||
|
||||
|
15
lib/utils/verbose.js
Normal file
15
lib/utils/verbose.js
Normal file
@ -0,0 +1,15 @@
|
||||
var argv = require('optimist').argv
|
||||
|
||||
const isVerbose = argv.verbose || false
|
||||
const verbose = isVerbose ? verboseConsole : () => { };
|
||||
|
||||
module.exports = {
|
||||
verbose,
|
||||
isVerbose
|
||||
}
|
||||
|
||||
function verboseConsole() {
|
||||
if (isVerbose) {
|
||||
console.log.apply(console, arguments)
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
const { exec } = require('child_process');
|
||||
const { verbose } = require('./verbose.js')
|
||||
|
||||
module.exports = async (install = false) => {
|
||||
verbose('🗣️ Verifying PM2 installation')
|
||||
return new Promise((resolve, reject) => {
|
||||
exec('pm2 -v', async (err) => {
|
||||
if (err) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "evolution-manager",
|
||||
"description": "Evolution Manager is an open-source interface for managing the Evolution API, simplifying the creation and administration of API instances with advanced features and diverse integrations.",
|
||||
"version": "0.3.12",
|
||||
"main": "dist",
|
||||
"engines": {
|
||||
|
Loading…
Reference in New Issue
Block a user