-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathgenerate-readme-packages-overview.js
120 lines (103 loc) · 3.26 KB
/
generate-readme-packages-overview.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
118
119
120
'use strict';
/*
* Generate the `Packages Overview` section of the monorepo README.
* Uses the `description` from the `package.json` of the packages in the monorepo.
*
* Prints to standard out, with the intention of copy pasting into the readme file.
*/
const path = require('path');
const { runInDir } = require('@mongodb-js/monorepo-tools');
const rootDir = path.resolve(__dirname, '..');
// From packages/compass/src/app/plugins/default.js
const pluginNames = [
'@mongodb-js/compass-app-stores',
'@mongodb-js/compass-aggregations',
'@mongodb-js/compass-export-to-language',
'@mongodb-js/compass-collection',
'@mongodb-js/compass-crud',
'@mongodb-js/compass-databases-collections',
'@mongodb-js/compass-field-store',
'@mongodb-js/compass-find-in-page',
'@mongodb-js/compass-import-export',
'@mongodb-js/compass-query-bar',
'@mongodb-js/compass-schema',
'@mongodb-js/compass-schema-validation',
'@mongodb-js/compass-serverstats',
'@mongodb-js/compass-shell',
'@mongodb-js/compass-sidebar',
'@mongodb-js/compass-indexes',
'@mongodb-js/compass-explain-plan',
'@mongodb-js/compass-saved-aggregations-queries',
];
const LERNA_BIN = path.resolve(
__dirname,
'..',
'node_modules',
'.bin',
'lerna'
);
function printPackageDescriptionLine(
packageName,
packageRelativePath,
packageDescription
) {
console.log(
`- [**${packageName}**](${packageRelativePath}): ${packageDescription}`
);
}
async function main() {
console.log('\n## Packages Overview\n');
const packages = JSON.parse(
(await runInDir(`${LERNA_BIN} list --all --json --toposort`)).stdout
);
const packageInfos = [];
for (const { location } of packages) {
const packageJson = require(path.join(location, 'package.json'));
const packageRelativePath = location.substring(rootDir.length + 1);
// Main Compass package
if (packageRelativePath === 'packages/compass') {
printPackageDescriptionLine(
packageJson.name,
packageRelativePath,
packageJson.description
);
continue;
}
packageInfos.push({
name: packageJson.name,
relativePath: packageRelativePath,
description: packageJson.description,
});
}
// Alphabetize
packageInfos.sort((a, b) => a.name.localeCompare(b.name));
console.log('\n### Compass Plugins\n');
for (const { name, relativePath, description } of packageInfos) {
if (
relativePath.startsWith('packages/') &&
pluginNames.includes(name) &&
relativePath !== 'packages/compass'
) {
printPackageDescriptionLine(name, relativePath, description);
}
}
console.log('\n### Shared Libraries and Build Tools\n');
for (const { name, relativePath, description } of packageInfos) {
if (relativePath.startsWith('packages/') && !pluginNames.includes(name)) {
printPackageDescriptionLine(name, relativePath, description);
}
}
console.log('\n### Shared Configuration Files\n');
for (const { name, relativePath, description } of packageInfos) {
if (relativePath.startsWith('configs/')) {
printPackageDescriptionLine(name, relativePath, description);
}
}
console.log('');
}
process.on('unhandledRejection', (err) => {
console.error();
console.error(err.stack || err.message || err);
process.exitCode = 1;
});
main();