"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pm2exists = exports.pm2dump = exports.pm2startup = exports.pm2start = exports.pm2delete = exports.pm2restart = exports.pm2stop = exports.pm2list = exports.pm2disconnect = exports.pm2connect = void 0;
const pm2 = require("pm2");
async function pm2connect() {
    return new Promise((resolve, reject) => {
        pm2.connect((err) => {
            if (err)
                return reject(err);
            resolve();
        });
    });
}
exports.pm2connect = pm2connect;
function pm2disconnect() {
    pm2.disconnect();
}
exports.pm2disconnect = pm2disconnect;
async function pm2list() {
    return new Promise((resolve, reject) => {
        pm2.list((err, list) => {
            if (err)
                return reject(err);
            resolve(list);
        });
    });
}
exports.pm2list = pm2list;
async function pm2stop(name) {
    return new Promise((resolve, reject) => {
        pm2.stop(name, (err, proc) => {
            if (err)
                return reject(err);
            resolve(proc);
        });
    });
}
exports.pm2stop = pm2stop;
async function pm2restart(name) {
    return new Promise((resolve, reject) => {
        pm2.restart(name, (err, proc) => {
            if (err)
                return reject(err);
            resolve(proc);
        });
    });
}
exports.pm2restart = pm2restart;
async function pm2delete(name) {
    return new Promise((resolve, reject) => {
        pm2.delete(name, (err, proc) => {
            if (err)
                return reject(err);
            resolve(proc);
        });
    });
}
exports.pm2delete = pm2delete;
async function pm2start(options) {
    return new Promise((resolve, reject) => {
        pm2.start(options, (err, proc) => {
            if (err)
                return reject(err);
            resolve(proc);
        });
    });
}
exports.pm2start = pm2start;
async function pm2startup(platform) {
    return new Promise((resolve, reject) => {
        pm2.startup(platform, (err, result) => {
            if (err)
                return reject(err);
            resolve(result);
        });
    });
}
exports.pm2startup = pm2startup;
async function pm2dump() {
    return new Promise((resolve, reject) => {
        pm2.dump(true, (err, result) => {
            if (err)
                return reject(err);
            resolve(result);
        });
    });
}
exports.pm2dump = pm2dump;
async function pm2exists(name) {
    return new Promise(async (resolve, reject) => {
        try {
            var instances = await pm2list();
            if (instances.filter(x => x.name == name).length > 0) {
                resolve(true);
            }
            else {
                resolve(false);
            }
        }
        catch (error) {
            reject(error);
        }
    });
}
exports.pm2exists = pm2exists;
//# sourceMappingURL=pm2util.js.map