-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.04 KB
/
index.js
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
const { spawn } = require('child_process')
const schema = require('./schema')
const pkgData = require('./package.json')
module.exports = function (app) {
let child
return {
start: options => {
let arguments = ['SK_x728bat.py']
child = spawn('python3', arguments, { cwd: __dirname })
child.stdout.on('data', data => {
try {
console.log(`"${data}"`)
console.log(JSON.stringify(JSON.parse(data), null, 2))
// app.debug(data.toString())
app.handleMessage(undefined, JSON.parse(data.toString()))
} catch (e) {
console.error(e.message)
}
})
child.stderr.on('data', fromChild => {
console.error(fromChild.toString())
})
child.on('error', err => {
console.error(err)
})
child.stdin.write(JSON.stringify(options))
child.stdin.write('\n')
},
stop: () => {
if (child) {
process.kill(child.pid)
child = undefined
}
},
schema,
id: pkgData.name,
name: pkgData.description
}
}