-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·45 lines (38 loc) · 988 Bytes
/
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
#!/usr/bin/env node
'use strict';
const util = require('./lib/util'),
api = require('./lib/api'),
args = require('./lib/args'),
runningAsScript = !module.parent;
require('dotenv').config();
function initCmd() {
return getOperationStream()
.errors(streamErrors)
.tap(util.logResult())
.done(process.exit);
}
function streamErrors(error, push) {
const resultObj = {error, status: 'error'};
if (error.pageUri) resultObj.pageUri = error.pageUri;
push(null, resultObj);
}
function getOperationStream() {
switch (args._[0]) {
case 'pages':
return util.readStdin()
.otherwise(() => {
return util.streamAllPageUris();
})
.through(uriStream =>
api.reindexPages(uriStream, args.elasticIndex, args)
);
default:
return util.readStdin()
.through(uriStream => api.reindex(uriStream, args.elasticIndex, args));
}
}
if (runningAsScript) {
initCmd();
} else {
module.exports = api;
}