forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadSponsorData.js
More file actions
111 lines (94 loc) · 2.92 KB
/
loadSponsorData.js
File metadata and controls
111 lines (94 loc) · 2.92 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
let config;
try {
config = require('../.config.js');
} finally {
if (!config || !config.uri) {
console.error('No Config or config.URI given, please create a .config.js file with those values in the root of the repository');
process.exit(-1);
}
}
const fs = require('fs');
const mongoose = require('../');
run().catch(err => {
console.error(err);
process.exit(-1);
});
// only "." because fs resolves relative to the CWD instead of relative to __dirname
const docsDir = './docs';
async function run() {
await mongoose.connect(config.uri);
const Subscriber = mongoose.model('Subscriber', mongoose.Schema({
companyName: String,
description: String,
url: String,
logo: String
}), 'Subscriber');
const Job = mongoose.model('Job', mongoose.Schema({
logo: String,
company: String,
title: String,
location: {
type: String,
required: true
},
description: {
type: String,
required: true
},
url: {
type: String,
required: true
}
}), 'Job');
const OpenCollectiveSponsor = mongoose.model('OpenCollectiveSponsor', mongoose.Schema({
openCollectiveId: {
type: Number
},
website: {
type: String,
required: true
},
image: {
type: String,
required: true
},
alt: {
type: String
}
}), 'OpenCollectiveSponsor');
try {
fs.mkdirSync(`${docsDir}/data`);
} catch {}
const subscribers = await Subscriber.
find({ companyName: { $exists: true }, description: { $exists: true }, logo: { $exists: true } }).
sort({ createdAt: 1 }).
select({ companyName: 1, description: 1, url: 1, logo: 1 });
fs.writeFileSync(`${docsDir}/data/sponsors.json`, JSON.stringify(subscribers, null, ' '));
const jobs = await Job.find().select({ logo: 1, company: 1, title: 1, location: 1, description: 1, url: 1 });
fs.writeFileSync(`${docsDir}/data/jobs.json`, JSON.stringify(jobs, null, ' '));
const opencollectiveSponsors = await fetch('https://opencollective.com/mongoose/members.json')
.then(res => res.json())
.then(res => res.filter(result => result.tier === 'sponsor' && result.isActive));
for (const sponsor of opencollectiveSponsors) {
const override = await OpenCollectiveSponsor.findOne({ openCollectiveId: sponsor['MemberId'] });
if (override == null) {
continue;
}
sponsor.website = override.website;
sponsor.image = override.image;
if (override.alt != null) {
sponsor.alt = override.alt;
}
}
const additionalSponsors = await OpenCollectiveSponsor.find({}).
then(docs => docs.filter(doc => doc.openCollectiveId == null));
for (const sponsor of additionalSponsors) {
opencollectiveSponsors.push(sponsor);
}
if (opencollectiveSponsors != null) {
fs.writeFileSync(`${docsDir}/data/opencollective.json`, JSON.stringify(opencollectiveSponsors, null, ' '));
}
console.log('Done');
process.exit(0);
}