-
Notifications
You must be signed in to change notification settings - Fork 13
/
worker.js
103 lines (84 loc) · 2.96 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict';
var path = require('path');
var async = require('async');
var installPackages = require('./lib/install-packages');
var updateCache = require('./lib/update-cache');
var updateGlobalCache = require('./lib/update-global-cache');
var installGlobals = require('./lib/install-globals');
var npmCommand = require('./lib/npm-command');
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 globalsDir = path.join(context.dataDir, '.globals');
var ret = {
env: {
MOCHA_COLORS: 1,
},
path: [
path.join(__dirname, 'node_modules/.bin'),
path.join(globalsDir, 'node_modules/.bin'),
],
prepare: function (context, done) {
// Did the user specify any packages to be globally insalled?
var installGlobalPackages = config.globals && config.globals.length;
if (config.test && config.test !== '<none>') {
context.data({ doTest: true }, 'extend');
}
var tasks = [];
var nocache = config.caching !== 'strict' && config.caching !== 'loose';
if (installGlobalPackages) {
tasks.push(function (next) {
installGlobals(config, context, globalsDir, function (err, cached) {
if (err || nocache || cached) {
return next(err);
}
updateGlobalCache(config.globals, context, globalsDir, next);
});
});
}
tasks.push(function (next) {
installPackages(config, context, function (err, exact) {
if (err || exact === true || nocache) {
return next(err);
}
updateCache(context, projectDir, next);
});
});
async.series(tasks, done);
},
};
if (config.test && config.test !== '<none>') {
ret.test = typeof config.test !== 'string' ? 'npm test' : config.test;
ret.test = {
cmd: ret.test === 'npm test' ? npmCommand('test') : ret.test,
cwd: projectDir,
};
}
if (config.runtime && config.runtime !== 'whatever') {
ret.env.N_PREFIX = path.join(context.baseDir, '.n');
// string or list - to be prefixed to the PATH
ret.path = ret.path.concat([
path.join(__dirname, 'node_modules/n/bin'),
ret.env.N_PREFIX + '/bin',
]);
var version =
config.runtime === 'custom' ? config.customVersion : config.runtime;
ret.environment = 'n ' + version;
}
cb(null, ret);
},
// if provided, autodetect is run if the project has *no* plugin
// configuration at all.
autodetect: {
filename: 'package.json',
exists: true,
language: 'node.js',
framework: null,
},
};