2025-01-16 05:22:33 +00:00
|
|
|
"use strict";
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.default = killChild;
|
|
|
|
const console_colors_1 = __importDefault(require("./console-colors"));
|
|
|
|
const kill_port_1 = __importDefault(require("kill-port"));
|
|
|
|
/**
|
|
|
|
* ## Kill Child Process Function
|
|
|
|
* @param {string | number | (string | number)[]} [port]
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
2025-01-16 08:28:46 +00:00
|
|
|
function killChild(childProcess, port) {
|
2025-01-16 05:22:33 +00:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
if (!childProcess)
|
|
|
|
return false;
|
|
|
|
try {
|
|
|
|
const childProcessPID = childProcess.pid;
|
|
|
|
childProcess.kill();
|
2025-02-03 12:41:13 +00:00
|
|
|
try {
|
|
|
|
if (typeof port == "object" && (port === null || port === void 0 ? void 0 : port[0])) {
|
|
|
|
for (let i = 0; i < port.length; i++) {
|
|
|
|
const singlePort = port[i];
|
|
|
|
yield (0, kill_port_1.default)(Number(singlePort));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (port) {
|
|
|
|
yield (0, kill_port_1.default)(Number(port));
|
2025-01-16 05:22:33 +00:00
|
|
|
}
|
|
|
|
}
|
2025-02-03 12:41:13 +00:00
|
|
|
catch (error) { }
|
2025-01-16 05:22:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Child Process couldn't be killed! ${error.message}`);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|