Repository navigation
Expand file tree
/
Copy pathsidebars-adaptors.js
More file actions
89 lines (80 loc) · 2.61 KB
/
Copy pathsidebars-adaptors.js
File metadata and controls
89 lines (80 loc) · 2.61 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
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')) {
const adaptorsFile = fs.readFileSync('./adaptors/packages/publicPaths.json');
const adaptors = JSON.parse(adaptorsFile);
// Every adaptor repeats the same item labels ('Functions', 'Overview', ...).
// Docusaurus derives a sidebar item's translation key from `key ?? label`,
// so without an explicit `key` those labels collide and the build throws
// `Multiple docs sidebar items produce the same translation key` for any
// non-default locale. Namespacing each key by adaptor keeps them unique.
const items = adaptors.sort().map(a => {
const base = {
type: 'category',
label: a.name,
key: a.name,
className: a.icon ? `adaptor-icon adaptor-icon-${a.name}` : undefined,
items: [
{
type: 'doc',
label: 'Functions & Examples',
key: `${a.name}-functions`,
id: a.docsId,
},
{
type: 'doc',
label: 'Configuration',
key: `${a.name}-configuration`,
id: a.configurationSchemaId,
},
{
type: 'doc',
label: 'Changelog',
key: `${a.name}-changelog`,
id: a.changelogId,
},
{
type: 'doc',
label: 'README.md',
key: `${a.name}-readme`,
id: a.readmeId,
},
],
};
const path = `./adaptors/${a.name}.md`;
if (fs.existsSync(path)) {
base.items.unshift({
type: 'doc',
label: 'Overview',
key: `${a.name}-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 !== 'packages');
const extras = overviews
.filter(id => !adaptors.map(a => `${a.name}`).includes(id))
.map(id => ({ type: 'doc', id, label: id, key: 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.)'
);
list = [];
}
module.exports = {
adaptors: [{ type: 'doc', id: 'adaptors-intro' }, ...list],
};