-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharvest.js
69 lines (64 loc) · 1.84 KB
/
harvest.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
/**
* @file
* Provides interface for running and caching harvests.
*/
const Content = require('./models/content');
const Harvest = require('./models/harvest').Harvest;
const fs = require('fs-extra');
const Async = require('async');
/**
* Prepares harvest.
*/
function prepare(siteName, config) {
const sitesDir = config.get('sitesDir');
const siteDir = `${sitesDir}/${siteName}`;
const content = new Content[config.get('storage')](siteName, config);
const sources = fs.readJsonSync(`${siteDir}/harvest/sources.json`);
const harvest = new Harvest(content, sources);
return harvest;
}
/**
* Caches harvest sources. Downloading sources makes it easier to deal with
* timeouts, revisions, and other issues.
*/
function cache(siteName, config) {
const harvest = prepare(siteName, config);
harvest.cache((err) => {
if (!err) console.log('Harvest cached.'); // eslint-disable-line
});
}
/**
* Runs harvest. Use after files have been cached.
*/
function run(siteName, config) {
const harvest = prepare(siteName, config);
Async.waterfall([
(done) => {
console.log('Loading files...'); // eslint-disable-line
harvest.load((err, result) => {
console.log('Files loaded...'); // eslint-disable-line
done(err, result);
});
},
(docsGroup, done) => {
console.log('Preparing files...'); // eslint-disable-line
harvest.prepare(docsGroup, (err, result) => {
console.log('Files prepared...'); // eslint-disable-line
done(null, result);
});
},
(docsGroup, done) => {
console.log('Storing files...'); // eslint-disable-line
harvest.store(docsGroup, (err, result) => {
console.log('Files stored...'); // eslint-disable-line
done(null, result);
});
},
], (err) => {
console.log(err, !err);
});
}
module.exports = {
cache,
run,
};