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:
25
lib/utils/build.js
Normal file
25
lib/utils/build.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { exec } = require('child_process')
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('📦 Build start')
|
||||
console.time('📦 Build complete')
|
||||
const distFolder = process.cwd() + '/dist'
|
||||
if (fs.existsSync(distFolder)) {
|
||||
console.time('📦 Remove dist folder')
|
||||
fs.rmSync(distFolder, { recursive: true, force: true })
|
||||
console.timeEnd('📦 Remove dist folder')
|
||||
}
|
||||
exec('npm run build', (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
console.log(stdout)
|
||||
console.timeEnd('📦 Build complete')
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
18
lib/utils/detectPm2ProcessId.js
Normal file
18
lib/utils/detectPm2ProcessId.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const { exec } = require('child_process');
|
||||
|
||||
module.exports = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec('pm2 jlist', async (err, stdout) => {
|
||||
if (err) {
|
||||
console.log('⚙️ PM2 is not installed');
|
||||
return reject(false);
|
||||
}
|
||||
|
||||
const list = JSON.parse(stdout);
|
||||
|
||||
const process = list.find((process) => process.name === 'evolution-manager');
|
||||
resolve(process ? process.pm_id : false);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
35
lib/utils/verifyPm2Installation.js
Normal file
35
lib/utils/verifyPm2Installation.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const { exec } = require('child_process');
|
||||
|
||||
module.exports = async (install = false) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec('pm2 -v', async (err) => {
|
||||
if (err) {
|
||||
console.log('⚙️ PM2 is not installed')
|
||||
if (!install) return reject(false)
|
||||
const installSuccess = await installPM2()
|
||||
if (!installSuccess) return reject(false)
|
||||
resolve(true)
|
||||
}
|
||||
console.log('⚙️ PM2 is installed')
|
||||
resolve(true)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function installPM2() {
|
||||
return new Promise((resolve) => {
|
||||
console.log('⚙️ Installing PM2...')
|
||||
console.time('⚙️ PM2 installed successfully')
|
||||
exec('npm install -g pm2', (err, stdout) => {
|
||||
console.timeEnd('⚙️ PM2 installed successfully')
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return resolve(false)
|
||||
}
|
||||
console.log(stdout)
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user