-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (36 loc) · 1.15 KB
/
index.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
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var async = require('async');
module.exports = function(config, batch, reports, logger, done) {
function log(file, cb) {
return function (err) {
if (err) logger.error('error writing %s', file);
else logger.silly('wrote %s', file);
cb(err);
};
}
var tmpDir = path.join(__dirname, 'dist', 'data');
var outDir = path.join(config.input.rcDir, config.outDir);
logger.verbose('making tmp dir %s', tmpDir);
mkdirp(tmpDir, function(err){
if (err) return done(err);
var batchFn = function(cb) {
var file = path.join(tmpDir, 'batch.json');
fs.writeFile(file, JSON.stringify(batch), 'utf8', log(file, cb));
};
var writeFns = reports.map(function(report) {
return function(cb) {
var file = path.join(tmpDir, report._id + '.json');
fs.writeFile(file, JSON.stringify(report), 'utf8', log(file, cb));
};
});
async.parallel([batchFn].concat(writeFns),function(err, results) {
if (err) {
logger.error(err);
return done(err);
}
done();
});
});
};