Skip to content

Commit b90b2e1

Browse files
author
Jose Constela
committed
Store commands on files
1 parent bd4bbdc commit b90b2e1

File tree

4 files changed

+41
-24
lines changed

4 files changed

+41
-24
lines changed

helpers/report.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports.progress = progress
6969
*/
7070
const result = (socket, topic, originalMessage, res) => {
7171
console.log(' || Command executed. Reporting...'.yellow)
72-
72+
7373
const message = Object.assign(originalMessage, {
7474
stdout: parseStd(res.stdout),
7575
stderr: parseStd(res.stderr)

package-lock.json

Lines changed: 21 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tideflowio/tideflow-agent",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Tideflow.io's agent",
55
"main": "index.js",
66
"keywords": [
@@ -37,6 +37,7 @@
3737
"cross-spawn": "^6.0.5",
3838
"queue": "^6.0.0",
3939
"socket.io-client": "^2.2.0",
40+
"tmp": "^0.1.0",
4041
"update-notifier": "^2.5.0"
4142
},
4243
"devDependencies": {

runner.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const spawn = require('cross-spawn')
2+
const tmp = require('tmp')
3+
const fs = require('fs')
24
const report = require('./helpers/report')
35

46
/**
@@ -10,18 +12,22 @@ const report = require('./helpers/report')
1012
*/
1113
const cmd = (socket, topic, req) => {
1214
return new Promise((resolve, reject) => {
13-
15+
16+
// Store code in tmp file
17+
const previousfile = tmp.tmpNameSync()
18+
const commandFile = tmp.tmpNameSync()
19+
fs.writeFileSync(commandFile, req.command)
20+
1421
// Given the command to execute, get the program's name and its parameters
1522
// in order to pass them to child_process.spawn
16-
let parameters = req.command.split(' ')
17-
const command = parameters.shift()
23+
const command = process.platform === 'win32' ? 'sh' : 'bash'
24+
let parameters = [commandFile]
1825

1926
// Check if the command is attaching the output from the previous flow's step
2027
if (req.previous) {
21-
[
22-
'--tf_previous',
23-
req.previous
24-
].map(p => parameters.push(p))
28+
fs.writeFileSync(previousfile, req.previous)
29+
parameters.push('--tf_previous_file')
30+
parameters.push(previousfile)
2531
}
2632

2733
// Execute the command in a child process so that stds can be monitored
@@ -39,6 +45,8 @@ const cmd = (socket, topic, req) => {
3945

4046
// Report Exit code
4147
sp.on('exit', code => {
48+
fs.unlinkSync(previousfile)
49+
fs.unlinkSync(commandFile)
4250
report.result( socket, topic, req,
4351
{
4452
stderr: code ? `EXIT CODE ${code}` : null,
@@ -51,6 +59,8 @@ const cmd = (socket, topic, req) => {
5159

5260
// Report an exception
5361
sp.on('error', (error) => {
62+
fs.unlinkSync(previousfile)
63+
fs.unlinkSync(commandFile)
5464
report.exception( socket, topic, req, error.toString() )
5565
return reject(error)
5666
})

0 commit comments

Comments
 (0)