-
Notifications
You must be signed in to change notification settings - Fork 14
/
sidebars-adaptors.js
117 lines (105 loc) · 3.06 KB
/
sidebars-adaptors.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
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
112
113
114
115
116
117
const fs = require('fs');
// Note that we'd like a way to start the docs site even if the
// generate-adaptors code has not yet been run. This if/else is not very elegent
// but does the trick.
let list = [];
if (
fs.existsSync('./adaptors/packages/publicPaths.json') &&
fs.existsSync('./adaptors/library/jobs/auto/publicPaths.json')
) {
const adaptorsFile = fs.readFileSync('./adaptors/packages/publicPaths.json');
const adaptors = JSON.parse(adaptorsFile);
const publicFile = fs.readFileSync(
'./adaptors/library/jobs/auto/publicPaths.json'
);
const publicJobs = JSON.parse(publicFile);
// Note: we can include out own examples here.
const jobs = [...publicJobs];
const groupedJobs = jobs.reduce((r, a) => {
r[a.adaptor] = r[a.adaptor] || [];
r[a.adaptor].push(a);
return r;
}, Object.create(null));
const items = adaptors.sort().map(a => {
const base = {
type: 'category',
label: a.name,
items: [
{
type: 'doc',
label: 'Functions',
id: a.docsId,
},
{
type: 'doc',
label: 'Configuration',
id: a.configurationSchemaId,
},
groupedJobs[a.name] && groupedJobs[a.name].length > 0
? {
type: 'category',
label: 'Examples',
items: groupedJobs[a.name].map(j => ({
type: 'doc',
label: j.name,
id: `library/${j.id}`,
})),
}
: {},
{
type: 'doc',
label: 'Changelog',
id: a.changelogId,
},
{
type: 'doc',
label: 'README.md',
id: a.readmeId,
},
],
};
const path = `./adaptors/${a.name}.md`;
if (fs.existsSync(path)) {
base.items.unshift({
type: 'doc',
label: 'Overview',
id: a.name,
});
}
return base;
});
const overviews = fs
.readdirSync(`./adaptors/`)
.map(file => file.replace(/\.[^/.]+$/, ''))
.filter(id => id !== 'intro')
.filter(id => id !== 'adaptors')
.filter(id => id !== 'library')
.filter(id => id !== 'library-intro')
.filter(id => id !== 'packages');
const extras = overviews
.filter(id => !adaptors.map(a => `${a.name}`).includes(id))
.map(id => ({ type: 'doc', id, label: id }));
list = [...items, ...extras].sort((a, b) => a.label.localeCompare(b.label));
} else {
console.log('Skipping adaptor sidebar because artifact generation failed:');
console.log(
" Adaptors 'publicPaths.json':",
fs.existsSync('./adaptors/packages/publicPaths.json')
? 'found'
: 'NOT FOUND! (Maybe `yarn generate-adaptors` failed.)'
);
console.log(
" Job Library 'publicPaths.json':",
fs.existsSync('./adaptors/library/jobs/auto/publicPaths.json')
? 'found'
: 'NOT FOUND! (Maybe `yarn generate-library` failed or has not been run.)'
);
list = [];
}
module.exports = {
adaptors: [
{ type: 'doc', id: 'adaptors-intro' },
{ type: 'doc', id: 'library-intro' },
...list,
],
};