@nu-art/commando 0.204.33 → 0.204.35
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/core/cli.d.ts +17 -0
- package/core/cli.js +64 -9
- package/package.json +1 -1
package/core/cli.d.ts
CHANGED
|
@@ -122,4 +122,21 @@ export declare class CommandoInteractive {
|
|
|
122
122
|
kill: (signal?: NodeJS.Signals | number) => boolean;
|
|
123
123
|
gracefullyKill: (pid?: number) => Promise<void>;
|
|
124
124
|
}
|
|
125
|
+
type CommandoCLIListener_Callback = (stdout: string) => void;
|
|
126
|
+
export declare class CommandoCLIListener {
|
|
127
|
+
private cb;
|
|
128
|
+
protected filter?: RegExp;
|
|
129
|
+
constructor(callback: CommandoCLIListener_Callback, filter?: string | RegExp);
|
|
130
|
+
private _process;
|
|
131
|
+
private stdoutPassesFilter;
|
|
132
|
+
listen: <T extends Commando | CommandoInteractive>(commando: T) => T;
|
|
133
|
+
protected process(stdout: string): void;
|
|
134
|
+
}
|
|
135
|
+
export declare class CommandoCLIKeyValueListener extends CommandoCLIListener {
|
|
136
|
+
private value;
|
|
137
|
+
constructor(pattern: string | RegExp);
|
|
138
|
+
private setValue;
|
|
139
|
+
protected process(stdout: string): void;
|
|
140
|
+
getValue: () => string | undefined;
|
|
141
|
+
}
|
|
125
142
|
export {};
|
package/core/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandoInteractive = exports.Commando = exports.CliWrapper = exports.Cli = exports.CliInteractive = exports.BaseCLI = void 0;
|
|
3
|
+
exports.CommandoCLIKeyValueListener = exports.CommandoCLIListener = exports.CommandoInteractive = exports.Commando = exports.CliWrapper = exports.Cli = exports.CliInteractive = exports.BaseCLI = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const class_merger_1 = require("./class-merger");
|
|
6
6
|
const CliError_1 = require("./CliError");
|
|
@@ -92,17 +92,13 @@ class CliInteractive extends BaseCLI {
|
|
|
92
92
|
};
|
|
93
93
|
this.gracefullyKill = async (pid) => {
|
|
94
94
|
return new Promise((resolve, reject) => {
|
|
95
|
-
console.log('Killing process');
|
|
96
95
|
this.shell.on('exit', async (code, signal) => {
|
|
97
|
-
console.log(`Process Killed ${signal}`);
|
|
98
96
|
resolve();
|
|
99
97
|
});
|
|
100
98
|
if (pid) {
|
|
101
|
-
console.log(`KILLING PID: ${pid}`);
|
|
102
99
|
process.kill(pid, 'SIGINT');
|
|
103
100
|
}
|
|
104
101
|
else {
|
|
105
|
-
console.log(`KILLING SHELL WITH SIGINT`);
|
|
106
102
|
this.shell.kill('SIGINT');
|
|
107
103
|
}
|
|
108
104
|
});
|
|
@@ -116,9 +112,14 @@ class CliInteractive extends BaseCLI {
|
|
|
116
112
|
const message = data.toString().trim();
|
|
117
113
|
if (!message.length)
|
|
118
114
|
return;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
try {
|
|
116
|
+
this.stdoutProcessors.forEach(processor => processor(message));
|
|
117
|
+
this.stderrProcessors.forEach(processor => processor(message));
|
|
118
|
+
this.logInfo(`${message}`);
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
this.logError(e);
|
|
122
|
+
}
|
|
122
123
|
};
|
|
123
124
|
(_a = this.shell.stdout) === null || _a === void 0 ? void 0 : _a.on('data', printer);
|
|
124
125
|
(_b = this.shell.stderr) === null || _b === void 0 ? void 0 : _b.on('data', printer);
|
|
@@ -295,7 +296,6 @@ class CommandoInteractive {
|
|
|
295
296
|
return commando.cli.kill(signal);
|
|
296
297
|
};
|
|
297
298
|
commando.gracefullyKill = async (pid) => {
|
|
298
|
-
console.log('Commando Inter calling gracefullyKill');
|
|
299
299
|
await commando.cli.gracefullyKill(pid);
|
|
300
300
|
};
|
|
301
301
|
commando.addStdoutProcessor = (processor) => {
|
|
@@ -318,3 +318,58 @@ class CommandoInteractive {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
exports.CommandoInteractive = CommandoInteractive;
|
|
321
|
+
class CommandoCLIListener {
|
|
322
|
+
constructor(callback, filter) {
|
|
323
|
+
this.stdoutPassesFilter = (stdout) => {
|
|
324
|
+
if (!this.filter)
|
|
325
|
+
return true;
|
|
326
|
+
return this.filter.test(stdout);
|
|
327
|
+
};
|
|
328
|
+
//######################### Functions #########################
|
|
329
|
+
this.listen = (commando) => {
|
|
330
|
+
const process = this._process.bind(this);
|
|
331
|
+
commando.addStdoutProcessor(process);
|
|
332
|
+
commando.addStderrProcessor(process);
|
|
333
|
+
return commando;
|
|
334
|
+
};
|
|
335
|
+
this.cb = callback;
|
|
336
|
+
if (!filter)
|
|
337
|
+
return;
|
|
338
|
+
if (typeof filter === 'string')
|
|
339
|
+
this.filter = new RegExp(filter);
|
|
340
|
+
else
|
|
341
|
+
this.filter = filter;
|
|
342
|
+
}
|
|
343
|
+
//######################### Inner Logic #########################
|
|
344
|
+
_process(stdout) {
|
|
345
|
+
if (!this.stdoutPassesFilter(stdout))
|
|
346
|
+
return;
|
|
347
|
+
this.process(stdout);
|
|
348
|
+
}
|
|
349
|
+
process(stdout) {
|
|
350
|
+
this.cb(stdout);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
exports.CommandoCLIListener = CommandoCLIListener;
|
|
354
|
+
class CommandoCLIKeyValueListener extends CommandoCLIListener {
|
|
355
|
+
constructor(pattern) {
|
|
356
|
+
const filter = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
|
|
357
|
+
super(ts_common_1.voidFunction, filter);
|
|
358
|
+
//######################### Inner Logic #########################
|
|
359
|
+
this.setValue = (value) => {
|
|
360
|
+
this.value = value;
|
|
361
|
+
};
|
|
362
|
+
this.getValue = () => this.value;
|
|
363
|
+
}
|
|
364
|
+
//######################### Functions #########################
|
|
365
|
+
process(stdout) {
|
|
366
|
+
var _a;
|
|
367
|
+
const pattern = this.filter;
|
|
368
|
+
if (!pattern)
|
|
369
|
+
throw new ts_common_1.ThisShouldNotHappenException('Class does not have a pattern, but it should have been initialized with one');
|
|
370
|
+
const value = (_a = stdout.match(pattern)) === null || _a === void 0 ? void 0 : _a[1];
|
|
371
|
+
if (value)
|
|
372
|
+
this.setValue(value);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.CommandoCLIKeyValueListener = CommandoCLIKeyValueListener;
|