mirror of
https://github.com/EvolutionAPI/evolution-manager.git
synced 2025-12-20 20:02:19 -06:00
feat: cli v0.2.0
This commit is contained in:
21
lib/pm2/delete.js
Normal file
21
lib/pm2/delete.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { exec } = require('child_process');
|
||||
const detectPm2ProcessId = require('../utils/detectPm2ProcessId.js');
|
||||
|
||||
module.exports = async (argv, id) => {
|
||||
const pm2ProcessId = id || await detectPm2ProcessId();
|
||||
if(pm2ProcessId === false) {
|
||||
console.log('⚙️ Manager process not setup')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('⚙️ Deleting PM2 process')
|
||||
exec(`pm2 del ${pm2ProcessId}`, (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
console.log(stdout)
|
||||
})
|
||||
|
||||
console.log('🗑️ PM2 process deleted')
|
||||
}
|
||||
25
lib/pm2/index.js
Normal file
25
lib/pm2/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
const functions = {
|
||||
setup: require('./setup.js'),
|
||||
reset: require('./reset.js'),
|
||||
start: require('./start.js'),
|
||||
stop: require('./stop.js'),
|
||||
delete: require('./delete.js'),
|
||||
}
|
||||
|
||||
module.exports = async (argv) => {
|
||||
|
||||
try {
|
||||
|
||||
if (argv._.length === 1) throw new Error('No operation specified')
|
||||
|
||||
const operation = argv._[1]
|
||||
if (!functions[operation]) throw new Error(`Unknown operation: ${operation}`)
|
||||
|
||||
await functions[operation](argv)
|
||||
} catch (e) {
|
||||
console.error(e.message || e)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
21
lib/pm2/reset.js
Normal file
21
lib/pm2/reset.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { exec } = require('child_process');
|
||||
const detectPm2ProcessId = require('../utils/detectPm2ProcessId.js');
|
||||
|
||||
module.exports = async (argv, id) => {
|
||||
const pm2ProcessId = id || await detectPm2ProcessId();
|
||||
if (pm2ProcessId === false) {
|
||||
console.log('⚙️ Manager process not setup')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('⚙️ Restarting PM2 process')
|
||||
exec(`pm2 restart ${pm2ProcessId}`, (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
console.log(stdout)
|
||||
})
|
||||
|
||||
console.log('🚀 PM2 process restarted')
|
||||
}
|
||||
34
lib/pm2/setup.js
Normal file
34
lib/pm2/setup.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const build = require('../utils/build.js');
|
||||
const verifyPm2Installation = require('../utils/verifyPm2Installation.js');
|
||||
const detectPm2ProcessId = require('../utils/detectPm2ProcessId.js');
|
||||
const { exec } = require('child_process')
|
||||
|
||||
module.exports = async (argv) => {
|
||||
const port = argv.port || 9615;
|
||||
|
||||
await verifyPm2Installation(true);
|
||||
await build();
|
||||
|
||||
const pm2ProcessId = await detectPm2ProcessId();
|
||||
|
||||
if (pm2ProcessId !== false) {
|
||||
console.log('📦 Manager process already setup')
|
||||
await require('./reset.js')(argv, pm2ProcessId);
|
||||
return
|
||||
}
|
||||
|
||||
console.log('⚙️ Starting PM2 process')
|
||||
console.time('⚙️ Starting PM2 process')
|
||||
exec(`pm2 serve dist/ ${port} --name evolution-manager --spa`, (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
console.log(stdout)
|
||||
console.timeEnd('⚙️ Starting PM2 process')
|
||||
|
||||
console.log('🚀 PM2 process started')
|
||||
console.log('🚀 Manager ready in port :' + port)
|
||||
})
|
||||
}
|
||||
|
||||
21
lib/pm2/start.js
Normal file
21
lib/pm2/start.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { exec } = require('child_process');
|
||||
const detectPm2ProcessId = require('../utils/detectPm2ProcessId.js');
|
||||
|
||||
module.exports = async (argv, id) => {
|
||||
const pm2ProcessId = id || await detectPm2ProcessId();
|
||||
if (pm2ProcessId === false) {
|
||||
console.log('⚙️ Manager process not setup')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('⚙️ Start PM2 process')
|
||||
exec(`pm2 start ${pm2ProcessId}`, (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
console.log(stdout)
|
||||
})
|
||||
|
||||
console.log('🚀 PM2 process started')
|
||||
}
|
||||
21
lib/pm2/stop.js
Normal file
21
lib/pm2/stop.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { exec } = require('child_process');
|
||||
const detectPm2ProcessId = require('../utils/detectPm2ProcessId.js');
|
||||
|
||||
module.exports = async (argv, id) => {
|
||||
const pm2ProcessId = id || await detectPm2ProcessId();
|
||||
if(pm2ProcessId === false) {
|
||||
console.log('⚙️ Manager process not setup')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('⚙️ Stopping PM2 process')
|
||||
exec(`pm2 stop ${pm2ProcessId}`, (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
console.log(stdout)
|
||||
})
|
||||
|
||||
console.log('🛑 PM2 process stopped')
|
||||
}
|
||||
Reference in New Issue
Block a user