forked from datenanfragen/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-deploy.js
35 lines (29 loc) · 1.33 KB
/
prepare-deploy.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
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const schema = require('./static/schema');
// Find countries that have data.
const countries_not_to_stub = glob
.sync('static/db/suggested-companies/@(??|all).json')
.map((country_file) => path.basename(country_file, '.json'));
// Determine countries that need stubs by filtering out the countries that have data.
const all_countries = schema.properties['relevant-countries'].items.enum;
const countries_to_stub = all_countries.filter((country) => !countries_not_to_stub.includes(country));
// Create the stubs for the countries with no data.
countries_to_stub.forEach((country) => {
fs.writeFileSync('static/db/suggested-companies/' + country + '.json', '[]');
});
// Create wizard files for all countries.
all_countries.forEach((country) => {
const json = fs.readFileSync('static/db/suggested-companies/' + country + '.json', 'utf-8');
const companies = JSON.parse(json);
const companies_wizard = companies.reduce((acc, slug) => {
const details = JSON.parse(fs.readFileSync('static/db/' + slug + '.json', 'utf-8'));
acc[slug] = details['name'];
return acc;
}, {});
fs.writeFileSync(
'static/db/suggested-companies/' + country + '_wizard.json',
JSON.stringify(companies_wizard, null, 4)
);
});