kill-me-now 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +24 -20
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{ name: string, pid: number, command: string }} OpenFileType
|
|
5
|
+
*/
|
|
6
|
+
|
|
3
7
|
import debug from 'debug'
|
|
4
8
|
|
|
5
9
|
import {
|
|
@@ -22,13 +26,13 @@ log('`kill-me-now` is awake')
|
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
28
|
* @param {string} alpha
|
|
25
|
-
* @returns {(openFile:
|
|
29
|
+
* @returns {(openFile: OpenFileType) => boolean}
|
|
26
30
|
*/
|
|
27
31
|
function getHasName (alpha) {
|
|
28
32
|
info('getHasName')
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
|
-
* @param {
|
|
35
|
+
* @param {OpenFileType} openFile
|
|
32
36
|
* @returns {boolean}
|
|
33
37
|
*/
|
|
34
38
|
return function hasName ({ name: omega }) {
|
|
@@ -42,14 +46,14 @@ function getHasName (alpha) {
|
|
|
42
46
|
|
|
43
47
|
/**
|
|
44
48
|
* @param {number} alpha
|
|
45
|
-
* @returns {(openFile:
|
|
49
|
+
* @returns {(openFile: OpenFileType) => boolean}
|
|
46
50
|
*/
|
|
47
|
-
function
|
|
48
|
-
info('
|
|
51
|
+
function getHasProcessId (alpha) {
|
|
52
|
+
info('getHasProcessId')
|
|
49
53
|
|
|
50
54
|
if (alpha) {
|
|
51
|
-
return function
|
|
52
|
-
info('
|
|
55
|
+
return function hasProcessId ({ pid: omega }) {
|
|
56
|
+
info('hasProcessId')
|
|
53
57
|
|
|
54
58
|
return (
|
|
55
59
|
omega !== alpha
|
|
@@ -64,14 +68,14 @@ function getHasPid (alpha) {
|
|
|
64
68
|
|
|
65
69
|
/**
|
|
66
70
|
* @param {string} alpha
|
|
67
|
-
* @returns {(openFile:
|
|
71
|
+
* @returns {(openFile: OpenFileType) => boolean}
|
|
68
72
|
*/
|
|
69
|
-
function
|
|
70
|
-
info('
|
|
73
|
+
function getHasCommand (alpha) {
|
|
74
|
+
info('getHasCommand')
|
|
71
75
|
|
|
72
76
|
if (alpha) {
|
|
73
|
-
return function
|
|
74
|
-
info('
|
|
77
|
+
return function hasCommand ({ command: omega }) {
|
|
78
|
+
info('hasCommand')
|
|
75
79
|
|
|
76
80
|
return (
|
|
77
81
|
omega === alpha
|
|
@@ -85,11 +89,11 @@ function getHasCmd (alpha) {
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
/**
|
|
88
|
-
* @param {
|
|
92
|
+
* @param {{ pid: number }} openFile
|
|
89
93
|
* @returns {void}
|
|
90
94
|
*/
|
|
91
|
-
function
|
|
92
|
-
info('
|
|
95
|
+
function killProcessById ({ pid }) {
|
|
96
|
+
info('killProcessById')
|
|
93
97
|
|
|
94
98
|
try {
|
|
95
99
|
log(`Killing process ${pid} ...`)
|
|
@@ -111,18 +115,18 @@ function killProcess ({ pid }) {
|
|
|
111
115
|
/**
|
|
112
116
|
* @param {string} name Name or File Path
|
|
113
117
|
* @param {number} [pid] Process ID
|
|
114
|
-
* @param {string} [
|
|
118
|
+
* @param {string} [command] Command
|
|
115
119
|
* @returns {Promise<void>}
|
|
116
120
|
*/
|
|
117
|
-
export default async function killMeNow (name, pid,
|
|
121
|
+
export default async function killMeNow (name, pid, command) {
|
|
118
122
|
const lsof = await getLsofArray()
|
|
119
123
|
const hasName = getHasName(name)
|
|
120
124
|
|
|
121
125
|
if (lsof.some(hasName)) {
|
|
122
126
|
lsof
|
|
123
127
|
.filter(hasName)
|
|
124
|
-
.filter(
|
|
125
|
-
.filter(
|
|
126
|
-
.forEach(
|
|
128
|
+
.filter(getHasProcessId(pid))
|
|
129
|
+
.filter(getHasCommand(command))
|
|
130
|
+
.forEach(killProcessById)
|
|
127
131
|
}
|
|
128
132
|
}
|