From 3e003725d95ab81e0f64ec0c2a83cf10b6caf08a Mon Sep 17 00:00:00 2001 From: Gabriel Pastori <58153955+gabrielpastori1@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:40:52 -0300 Subject: [PATCH] add verbose to cli --- lib/cli.js | 22 +++++++++++++++++++--- lib/pm2/index.js | 1 - lib/pm2/setup.js | 3 +++ lib/utils/build.js | 4 ++++ lib/utils/verbose.js | 15 +++++++++++++++ lib/utils/verifyPm2Installation.js | 2 ++ package.json | 1 + 7 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 lib/utils/verbose.js diff --git a/lib/cli.js b/lib/cli.js index 5a784ef..d527f8a 100644 --- a/lib/cli.js +++ b/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() diff --git a/lib/pm2/index.js b/lib/pm2/index.js index 506e44f..e8587d6 100644 --- a/lib/pm2/index.js +++ b/lib/pm2/index.js @@ -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] diff --git a/lib/pm2/setup.js b/lib/pm2/setup.js index 2622b0a..4fc3e8e 100644 --- a/lib/pm2/setup.js +++ b/lib/pm2/setup.js @@ -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) diff --git a/lib/utils/build.js b/lib/utils/build.js index 1c82ba3..4aaa308 100644 --- a/lib/utils/build.js +++ b/lib/utils/build.js @@ -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() diff --git a/lib/utils/verbose.js b/lib/utils/verbose.js new file mode 100644 index 0000000..aa39a66 --- /dev/null +++ b/lib/utils/verbose.js @@ -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) + } +} \ No newline at end of file diff --git a/lib/utils/verifyPm2Installation.js b/lib/utils/verifyPm2Installation.js index a373369..1e4dc74 100644 --- a/lib/utils/verifyPm2Installation.js +++ b/lib/utils/verifyPm2Installation.js @@ -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) { diff --git a/package.json b/package.json index b76b624..f81e02c 100644 --- a/package.json +++ b/package.json @@ -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": {