-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsaveDocs.js
More file actions
41 lines (37 loc) · 1.17 KB
/
saveDocs.js
File metadata and controls
41 lines (37 loc) · 1.17 KB
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
import formatPkg from './formatPkg.js';
import log from './log.js';
import { getDownloads, getDependents } from './npm.js';
import { getChangelogs } from './changelog.js';
export default function saveDocs({ docs, index }) {
const rawPkgs = docs
.filter(result => result.doc.name !== undefined) // must be a document
.map(result => formatPkg(result.doc))
.filter(pkg => pkg !== undefined);
if (rawPkgs.length === 0) {
log.info('🔍 No pkgs found in response.');
return Promise.resolve();
}
return addMetaData(rawPkgs)
.then(pkgs => index.saveObjects(pkgs))
.then(() => log.info('🔍 Found and saved %d packages', rawPkgs.length));
}
function addMetaData(pkgs) {
return Promise.all([
getDownloads(pkgs),
getDependents(pkgs),
getChangelogs(pkgs),
]).then(([downloads, dependents, changelogs]) =>
pkgs.map((pkg, index) => ({
...pkg,
...downloads[index],
...dependents[index],
...changelogs[index],
_searchInternal: {
...pkg._searchInternal,
...downloads[index]._searchInternal,
...dependents[index]._searchInternal,
...changelogs[index]._searchInternal,
},
}))
);
}