forked from CoderDojo/cp-local-development
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestdata.js
44 lines (36 loc) · 1.26 KB
/
testdata.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
var debug = require('debug')('localdev:testdata');
var async = require('async');
var command = require('./command.js');
var _ = require('lodash');
var util = require('util');
module.exports = function (argv, systems, cb) {
debug(system);
var usage = 'Usage: testdata <system-name> [service-name]\n e.g. testdata phase3';
var sysName = argv._[1];
if (!sysName) return cb(usage);
var system = systems[sysName];
if (!system) return cb('System not found: ' + sysName);
var workspace = 'workspace-' + sysName;
console.log('System:', sysName, util.inspect(system.stringify(), true, null), 'workspace: ' + workspace);
var serviceName = argv._[2];
var services = system.services;
if (serviceName) {
var service = _.findWhere(system.services, {name: serviceName});
if (!service) return cb('Service not found: ' + serviceName);
services = [service];
}
// load the test data
async.series([
loadAllTestData
], cb);
function loadAllTestData (cb) {
async.mapSeries(services, loadTestData, cb);
}
function loadTestData (service, cb) {
if (!service.testdata) return cb();
var dir = workspace + '/' + service.name;
var cmd = service.testdata;
debug('loadTestData', dir, cmd);
command(cmd, dir, service.env, cb);
}
};