-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·87 lines (64 loc) · 1.9 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import config from '../../config';
// DOMUSTO
import DomustoPlugin from '../../domusto/DomustoPlugin';
// INTERFACES
import { Domusto } from '../../domusto/DomustoTypes';
// PLUGIN SPECIFIC
import * as childProcess from 'child_process';
/**
* Shell plugin for DOMUSTO
* @author Bas van Dijk
* @version 0.0.1
*
* @class DomustoShell
* @extends {DomustoPlugin}
*/
class DomustoShell extends DomustoPlugin {
/**
* Creates an instance of DomustoShell.
* @param {any} Plugin configuration as defined in the config.js file
* @memberof DomustoShell
*/
constructor(pluginConfiguration: Domusto.PluginConfiguration) {
super({
plugin: 'Shell executer',
author: 'Bas van Dijk',
category: Domusto.PluginCategories.system,
version: '0.0.1',
website: 'http://domusto.com'
});
this.console.header(`${pluginConfiguration.id} plugin ready`);
}
/**
* Executed when a signal is received for this plugin
*
* @param {Domusto.Signal} signal
* @memberof DomustoShell
*/
onSignalReceivedForPlugin(signal: Domusto.Signal) {
if (!this._busy) {
let shellCommand = signal.data['shellCommand'];
this._busy = true;
if (shellCommand) {
this.executeCommand(shellCommand);
} else {
this.console.error('No action defined in ', signal);
}
}
}
/**
* Run given shell command
*
* @param {any} shellCommand
* @memberof DomustoShell
*/
executeCommand(shellCommand) {
childProcess.exec(shellCommand, (error, stdout, stderr) => {
this.console.debug('error', error);
this.console.debug('stdout', stdout);
this.console.debug('stderr', stderr);
this._busy = false;
});
}
}
export default DomustoShell;