// 为了向下兼容preuninstall 此模块暂时保留
const { logger } = require('@gem-mine/cli-share-lib')
const pm2 = require('pm2')
const util = require('util')

pm2.connectP = util.promisify(pm2.connect)
pm2.listP = util.promisify(pm2.list)
pm2.deleteP = util.promisify(pm2.delete)
pm2.disconnectP = util.promisify(pm2.disconnect)

module.exports = async function deleteCliService() {
  await pm2.connectP()
  const appList = await pm2.listP()
  if(appList.some((app) => app.name === 'cli-service')) {
    await pm2.deleteP('cli-service')
  }
  await pm2.disconnectP()
}