deepwork-node-watchdog 1.0.1 → 1.0.2
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/README.md +46 -37
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -7
- package/dist/main.js +16 -15
- package/dist/watchdog.types.d.ts +1 -13
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -24,18 +24,45 @@ npm install deepwork-node-watchdog
|
|
|
24
24
|
|
|
25
25
|
## Uso como CLI
|
|
26
26
|
|
|
27
|
-
### Iniciar el watchdog
|
|
27
|
+
### Iniciar el watchdog con un archivo de lista negra
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
30
|
deepwork-watchdog --blacklist /ruta/absoluta/a/blacklist.txt
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
### Iniciar el watchdog con una lista de procesos separados por coma
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
deepwork-watchdog --blacklist discord,whatsapp,spotify
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Especificar intervalo de escaneo
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
deepwork-watchdog --blacklist discord,spotify --interval 5000
|
|
43
|
+
```
|
|
44
|
+
|
|
33
45
|
### Listar procesos en ejecución
|
|
34
46
|
|
|
35
47
|
```bash
|
|
36
48
|
deepwork-watchdog --list
|
|
37
49
|
```
|
|
38
50
|
|
|
51
|
+
### Ver la versión
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
deepwork-watchdog --version
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Argumentos disponibles
|
|
58
|
+
|
|
59
|
+
| Argumento | Tipo | Default | Descripción |
|
|
60
|
+
|----------------|-----------|---------|-----------------------------------------------------------------------------|
|
|
61
|
+
| `--blacklist` | `string` | — | Ruta absoluta a un archivo de lista negra, o nombres separados por coma |
|
|
62
|
+
| `--interval` | `number` | `3000` | Intervalo entre escaneos en milisegundos |
|
|
63
|
+
| `--list` | `boolean` | — | Lista los procesos activos del sistema y termina |
|
|
64
|
+
| `--version` | `boolean` | — | Muestra la versión del paquete y termina |
|
|
65
|
+
|
|
39
66
|
### Archivo de lista negra (`blacklist.txt`)
|
|
40
67
|
|
|
41
68
|
Cada línea es el nombre de un proceso a matar. Las líneas vacías y los comentarios (`#`) son ignorados. La extensión `.exe` es opcional.
|
|
@@ -52,13 +79,12 @@ spotify
|
|
|
52
79
|
## Uso como librería
|
|
53
80
|
|
|
54
81
|
```ts
|
|
55
|
-
import { start, stop, isRunning, listProcesses } from 'deepwork-node-watchdog';
|
|
82
|
+
import { start, stop, scan, isRunning, listProcesses } from 'deepwork-node-watchdog';
|
|
56
83
|
|
|
57
84
|
// Iniciar el watchdog con una lista de procesos
|
|
58
85
|
start({
|
|
59
86
|
blacklist: ['discord', 'whatsapp', 'spotify'],
|
|
60
|
-
intervalMs: 5000,
|
|
61
|
-
logFile: 'watchdog.log', // Opcional: archivo de log
|
|
87
|
+
intervalMs: 5000, // Intervalo de escaneo en ms (default: 3000)
|
|
62
88
|
});
|
|
63
89
|
|
|
64
90
|
// Detener el watchdog
|
|
@@ -67,41 +93,38 @@ stop();
|
|
|
67
93
|
// Verificar si está corriendo
|
|
68
94
|
console.log(isRunning()); // true | false
|
|
69
95
|
|
|
96
|
+
// Escaneo único (sin loop)
|
|
97
|
+
await scan(['discord', 'spotify']);
|
|
98
|
+
|
|
99
|
+
// También acepta ruta a archivo de lista negra
|
|
100
|
+
await scan('/ruta/absoluta/a/blacklist.txt');
|
|
101
|
+
|
|
70
102
|
// Listar procesos activos
|
|
71
103
|
const processes = await listProcesses();
|
|
72
104
|
processes.forEach(p => console.log(`${p.name} (PID: ${p.pid})`));
|
|
73
105
|
```
|
|
74
106
|
|
|
75
|
-
### También puedes usar un archivo de lista negra
|
|
76
|
-
|
|
77
|
-
```ts
|
|
78
|
-
start({
|
|
79
|
-
blacklistPath: '/ruta/absoluta/a/blacklist.txt',
|
|
80
|
-
intervalMs: 3000,
|
|
81
|
-
});
|
|
82
|
-
```
|
|
83
|
-
|
|
84
107
|
---
|
|
85
108
|
|
|
86
109
|
## API
|
|
87
110
|
|
|
88
111
|
### `start(options: WatchdogOptions): void`
|
|
89
112
|
|
|
90
|
-
Inicia el watchdog. Si ya está corriendo, no hace nada.
|
|
113
|
+
Inicia el watchdog en loop. Si ya está corriendo, no hace nada.
|
|
91
114
|
|
|
92
|
-
| Opción
|
|
93
|
-
|
|
94
|
-
| `blacklist`
|
|
95
|
-
| `
|
|
96
|
-
| `intervalMs` | `number` | `3000` | Intervalo entre escaneos en milisegundos |
|
|
97
|
-
| `logFile` | `string` | — | Ruta al archivo de log (opcional) |
|
|
98
|
-
|
|
99
|
-
> Se debe especificar `blacklist` o `blacklistPath`. Si no se especifica ninguno, el watchdog se inicia pero no hace nada.
|
|
115
|
+
| Opción | Tipo | Default | Descripción |
|
|
116
|
+
|--------------|-----------------------|---------|-------------------------------------------------------------------|
|
|
117
|
+
| `blacklist` | `string \| string[]` | — | Ruta a un archivo de lista negra, o array de nombres de procesos |
|
|
118
|
+
| `intervalMs` | `number` | `3000` | Intervalo entre escaneos en milisegundos |
|
|
100
119
|
|
|
101
120
|
### `stop(): void`
|
|
102
121
|
|
|
103
122
|
Detiene el watchdog y limpia el timer interno.
|
|
104
123
|
|
|
124
|
+
### `scan(blacklist: string | string[]): Promise<void>`
|
|
125
|
+
|
|
126
|
+
Ejecuta un escaneo único. Acepta un array de nombres de procesos o la ruta absoluta a un archivo de lista negra.
|
|
127
|
+
|
|
105
128
|
### `isRunning(): boolean`
|
|
106
129
|
|
|
107
130
|
Retorna `true` si el watchdog está activo.
|
|
@@ -112,20 +135,6 @@ Retorna la lista de procesos activos en el sistema.
|
|
|
112
135
|
|
|
113
136
|
---
|
|
114
137
|
|
|
115
|
-
## Configuración CLI (`watchdog.conf`)
|
|
116
|
-
|
|
117
|
-
Cuando se usa como CLI, el watchdog lee un archivo `watchdog.conf` en el directorio de instalación:
|
|
118
|
-
|
|
119
|
-
```ini
|
|
120
|
-
# Intervalo entre escaneos (milisegundos)
|
|
121
|
-
INTERVAL_MS=3000
|
|
122
|
-
|
|
123
|
-
# Archivo de log (dejar vacío para desactivar)
|
|
124
|
-
LOG_FILE=watchdog.log
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
138
|
## Compatibilidad
|
|
130
139
|
|
|
131
140
|
| Sistema operativo | Comando para listar | Comando para matar |
|
|
@@ -137,4 +146,4 @@ LOG_FILE=watchdog.log
|
|
|
137
146
|
|
|
138
147
|
## Licencia
|
|
139
148
|
|
|
140
|
-
ISC — Kevin Javier Reyes
|
|
149
|
+
ISC — Kevin Javier Reyes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WatchdogOptions } from "./watchdog.types";
|
|
2
|
+
export declare function scan(blacklist: string[] | string): Promise<void>;
|
|
2
3
|
export declare function start(options: WatchdogOptions): void;
|
|
3
4
|
export declare function stop(): void;
|
|
4
5
|
export declare function isRunning(): boolean;
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.listProcesses = void 0;
|
|
7
|
+
exports.scan = scan;
|
|
7
8
|
exports.start = start;
|
|
8
9
|
exports.stop = stop;
|
|
9
10
|
exports.isRunning = isRunning;
|
|
@@ -15,22 +16,20 @@ let activeOptions = null;
|
|
|
15
16
|
async function loop() {
|
|
16
17
|
if (!running || !activeOptions)
|
|
17
18
|
return;
|
|
18
|
-
const {
|
|
19
|
-
await watchdog_1.default.scan(
|
|
19
|
+
const { blacklist, intervalMs = 3000 } = activeOptions;
|
|
20
|
+
await watchdog_1.default.scan(blacklist);
|
|
20
21
|
if (running) {
|
|
21
22
|
timer = setTimeout(loop, intervalMs);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
async function scan(blacklist) {
|
|
26
|
+
return watchdog_1.default.scan(blacklist);
|
|
27
|
+
}
|
|
24
28
|
function start(options) {
|
|
25
29
|
if (running)
|
|
26
30
|
return;
|
|
27
31
|
running = true;
|
|
28
32
|
activeOptions = options;
|
|
29
|
-
if (!options.blacklistPath &&
|
|
30
|
-
(!options.blacklist || options.blacklist.length === 0)) {
|
|
31
|
-
(0, log_util_1.log)("No blacklist specified. Use options.blacklistPath or options.blacklist to set it.");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
33
|
loop();
|
|
35
34
|
}
|
|
36
35
|
function stop() {
|
package/dist/main.js
CHANGED
|
@@ -15,7 +15,7 @@ const args = (0, args_lib_1.parseArgs)([
|
|
|
15
15
|
{
|
|
16
16
|
flag: "--blacklist",
|
|
17
17
|
type: "string",
|
|
18
|
-
description: "Absolute path to blacklist file",
|
|
18
|
+
description: "Absolute path to blacklist file or a comma-separated list of process names",
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
flag: "--list",
|
|
@@ -37,10 +37,11 @@ const args = (0, args_lib_1.parseArgs)([
|
|
|
37
37
|
(0, log_util_1.log)("Process Watchdog started" +
|
|
38
38
|
(args.blacklist ? ` with blacklist file: ${args.blacklist}` : ""));
|
|
39
39
|
let running = true;
|
|
40
|
+
let blacklistPathOrNames = null;
|
|
40
41
|
let timer;
|
|
41
42
|
function validateArgsRequirementsToScan() {
|
|
42
43
|
if (!args.blacklist) {
|
|
43
|
-
(0, log_util_1.log)("No blacklist file specified. Use --blacklist <absolutePath> to set it.");
|
|
44
|
+
(0, log_util_1.log)("No blacklist file or process names specified. Use --blacklist <absolutePath> or a comma-separated list of process names to set it.");
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
46
47
|
if (args.interval <= 0) {
|
|
@@ -56,19 +57,13 @@ async function loop() {
|
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
console.log("Scanning processes...");
|
|
59
|
-
await watchdog_1.default.scan(
|
|
60
|
+
await watchdog_1.default.scan(blacklistPathOrNames);
|
|
60
61
|
if (running) {
|
|
61
62
|
timer = setTimeout(loop, args.interval);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
if (args.version) {
|
|
65
|
-
let pkg;
|
|
66
|
-
try {
|
|
67
|
-
pkg = require(path_1.default.resolve(__dirname, "../package.json"));
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
pkg = require(path_1.default.resolve(__dirname, "package.json"));
|
|
71
|
-
}
|
|
66
|
+
let pkg = require(path_1.default.resolve(__dirname, "../package.json"));
|
|
72
67
|
console.log(`Process Watchdog version: ${pkg.version}`);
|
|
73
68
|
process.exit(0);
|
|
74
69
|
}
|
|
@@ -81,11 +76,17 @@ else if (args.list) {
|
|
|
81
76
|
})();
|
|
82
77
|
}
|
|
83
78
|
else {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
const blacklist = args.blacklist?.trim();
|
|
80
|
+
if (!blacklist) {
|
|
81
|
+
(0, log_util_1.log)("No blacklist file or process names specified. Use --blacklist <absolutePath> or a comma-separated list of process names to set it.");
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
blacklistPathOrNames = args.blacklist.includes(",")
|
|
85
|
+
? args.blacklist.split(",").map((s) => s.trim())
|
|
86
|
+
: path_1.default.isAbsolute(args.blacklist || "")
|
|
87
|
+
? args.blacklist
|
|
88
|
+
: path_1.default.resolve(process.cwd(), args.blacklist || "");
|
|
89
|
+
console.log(`Using blacklist file or names: ${blacklistPathOrNames}`);
|
|
89
90
|
console.log(`Starting process scan loop with interval: ${args.interval}ms`);
|
|
90
91
|
console.log("Press Ctrl+C to stop the watchdog.");
|
|
91
92
|
loop();
|
package/dist/watchdog.types.d.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
export interface Config {
|
|
2
|
-
INTERVAL_MS: number;
|
|
3
|
-
LOG_FILE: string;
|
|
4
|
-
}
|
|
5
|
-
export interface Profile {
|
|
6
|
-
name: string;
|
|
7
|
-
path: string;
|
|
8
|
-
blacklistPath: string;
|
|
9
|
-
hasBlacklist: boolean;
|
|
10
|
-
processCount: number;
|
|
11
|
-
}
|
|
12
1
|
export interface WatchdogOptions {
|
|
13
|
-
|
|
14
|
-
blacklist?: string[];
|
|
2
|
+
blacklist: string[] | string;
|
|
15
3
|
intervalMs?: number;
|
|
16
4
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepwork-node-watchdog",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A Node.js watchdog for DeepWork.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Kevin Javier Reyes",
|
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
"deepwork-watchdog": "dist/main.js"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"start": "ts-node main.ts --blacklist
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"start": "ts-node src/main.ts --blacklist steam,epicgames,origin,ubisoft,riot,blizzard",
|
|
17
|
+
"list": "ts-node src/main.ts --list",
|
|
18
|
+
"version": "ts-node src/main.ts --version",
|
|
19
|
+
"start:dev": "ts-node-dev --respawn --transpile-only --ignore-watch node_modules src/main.ts --blacklist steam,epicgames,origin,ubisoft,riot,blizzard",
|
|
20
|
+
"list:dev": "ts-node-dev --respawn --transpile-only --ignore-watch node_modules src/main.ts --list",
|
|
21
|
+
"version:dev": "ts-node-dev --respawn --transpile-only --ignore-watch node_modules src/main.ts --version",
|
|
20
22
|
"build": "tsc"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|