-
Notifications
You must be signed in to change notification settings - Fork 3
/
worker.js
66 lines (52 loc) · 2.03 KB
/
worker.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
var debug = require('debug')('strider-bower:worker');
var findDirectory = require('./lib/find-directory');
var fs = require('fs');
var installPackages = require('./lib/install-packages');
var path = require('path');
var updateCache = require('./lib/update-cache');
module.exports = {
// Initialize the plugin for a job
// config: taken from DB config extended by flat file config
// job & repo: see strider-runner-core
// cb(err, initialized plugin)
init: function (config, job, context, cb) {
config = config || {};
var subDir = config.subDir || '';
var projectDir = path.join(context.dataDir, subDir);
var binBase = config.globalBower ? __dirname : projectDir;
var paths = [path.join(binBase, 'node_modules', '.bin')];
var result = {
path: paths,
env: {
MOCHA_COLORS: 1
},
prepare: function (context, done) {
debug('Preparing bower...');
// We don't support any caching in a docker container, as the container is reconstructed on every run anyway.
if (context.runnerId === 'docker') {
return installPackages(config, context, projectDir);
}
var bowerExists = fs.existsSync(path.join(projectDir, 'bower.json'));
if (!bowerExists) {
debug('No "bower.json" found in project. Nothing to do.');
context.comment('No "bower.json" found in project. Nothing to do.');
return done(null, false);
}
var skipCache = config.caching !== 'strict' && config.caching !== 'loose';
findDirectory(projectDir, function (err, bowerDirectory) {
installPackages(config, context, projectDir, bowerDirectory, function (err, exact) {
if (err || exact === true || skipCache) {
if (skipCache) {
context.comment('skipping cache update');
}
return done(err);
}
updateCache(context, projectDir, bowerDirectory, done);
});
});
}
};
cb(null, result);
}
};