Skip to content

Commit 38256c1

Browse files
author
Niall O'Higgins
committed
make prepare command support arbitrary shell
1 parent 5b467af commit 38256c1

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

worker.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,40 @@ var detect = require('strider-detection-rules')
22
var fs = require('fs')
33
var path = require('path')
44

5+
function shellCommand(command) {
6+
if (!command.replace(/#[^\n]*/g, '').trim().length) return
7+
return {
8+
command: 'sh',
9+
args: ['-x', '-c', command]
10+
}
11+
}
12+
513
module.exports = {
614
init: function (config, job, context, done) {
715
var venvDir = path.join(context.baseDir, '.venv')
816
var test = undefined
917
if (config && config.test !== 'none') {
1018
test = config.test
1119
}
12-
var defaultPrepare = "pip install -r requirements.txt"
20+
var defaultPrepare = function (context, done) {
21+
if (!fs.existsSync(path.join(context.dataDir, 'requirements.txt'))) {
22+
// skip if default and no requirements.txt exists
23+
// we assume that if you're configuring your own, you'll ensure the file exists
24+
return done(null, true)
25+
}
26+
context.cmd("pip install -r requirements.txt", function (err) {
27+
done(err, true)
28+
})
29+
}
1330
var prepare = defaultPrepare
1431
if (config && config.prepare) {
15-
prepare = config.prepare
32+
prepare = shellCommand(config.prepare)
1633
}
1734
done(null, {
1835
path: [path.join(__dirname, 'thirdparty'),
1936
path.join(venvDir, 'bin')],
2037
environment: 'virtualenv.py ' + venvDir,
21-
prepare: function (context, done) {
22-
if (prepare === defaultPrepare && !fs.existsSync(path.join(context.dataDir, 'requirements.txt'))) {
23-
// skip if default and no requirements.txt exists
24-
// we assume that if you're configuring your own, you'll ensure the file exists
25-
return done(null, true)
26-
}
27-
context.cmd(prepare, function (err) {
28-
done(err, true)
29-
})
30-
},
38+
prepare: prepare,
3139
test: test
3240
})
3341
},

0 commit comments

Comments
 (0)