forked from cncf/landscapeapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepareLandscape.js
58 lines (50 loc) · 2.57 KB
/
prepareLandscape.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
const path = require('path');
const fs = require('fs/promises');
const qs = require('query-string');
const { execSync } = require('child_process');
const { loadGuide } = require('./loadGuide');
const { projectPath, settings, distPath } = require('./settings');
const items = require(path.resolve(projectPath, 'data.json'))
const { website } = settings.global;
//render
async function main() {
await fs.rm(distPath, { recursive: true, force: true });
await fs.mkdir(path.resolve(distPath, 'logos'), { recursive: true });
execSync(`cp -r "${projectPath}/images" "${distPath}"`);
execSync(`cp ${projectPath}/cached_logos/* "${distPath}/logos"`);
await fs.writeFile(path.resolve(distPath, 'settings.json'), JSON.stringify(settings));
await fs.mkdir(path.resolve(distPath, 'data', 'exports'), { recursive: true });
await fs.mkdir(path.resolve(distPath, 'data', 'items'), { recursive: true });
await fs.writeFile(path.resolve(distPath, 'data', 'items.json'), JSON.stringify(items))
await fs.writeFile(path.resolve(distPath, '_headers'),
await fs.readFile('_headers', 'utf-8'));
await fs.copyFile( path.resolve(projectPath, 'images', 'favicon.png'), path.resolve(distPath, 'favicon.png'));
for (let item of items) {
await fs.writeFile(path.resolve(distPath, 'data', 'items', `${item.id}.json`), JSON.stringify(item))
}
const guide = loadGuide();
if (guide) {
await fs.writeFile(path.resolve(distPath, 'guide.json'), JSON.stringify(guide))
}
const { prepareItemsForExport } = require('./prepareItemsForExport');
const { flattenItems } = require('../src/utils/itemsCalculator');
const { getGroupedItems } = require('../src/utils/itemsCalculator');
const { parseParams } = require('../src/utils/routing');
const itemsForExport = prepareItemsForExport(items)
await fs.writeFile(path.resolve(distPath, 'data', 'items-export.json'), JSON.stringify(itemsForExport))
for ( let element of Object.entries(settings.export || {})) {
let [exportPath, query] = element;
const params = parseParams({ mainContentMode: 'card-mode', ...qs.parse(query) })
const groupedItems = getGroupedItems({data: items, ...params})
.map(group => {
const items = group.items.map(({ id, name, href }) => ({ id, name, logo: `${website}/${href}` }))
return { ...group, items }
})
const exportItems = params.grouping === 'no' ? flattenItems(groupedItems) : groupedItems
await fs.writeFile(path.resolve(distPath, 'data', 'exports', `${exportPath}.json`), JSON.stringify(exportItems));
}
}
main().catch(function(ex) {
console.info(ex);
process.exit(1);
});