-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
35 lines (31 loc) · 1 KB
/
index.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 fs = require('fs');
const path = require('path');
const defaults = {
dir: './packages',
verbose: false,
bullet: '*',
};
module.exports = function SUBPACKAGELIST(content, _options, config) {
const options = Object.assign({}, defaults, _options);
const packagesDir = path.resolve(
path.dirname(config.originalPath),
options.dir
);
return fs
.readdirSync(packagesDir)
.map((filename) => path.join(packagesDir, filename))
.filter((filePath) => fs.statSync(filePath).isDirectory())
.filter((dirPath) => fs.existsSync(path.join(dirPath, 'package.json')))
.map((dirPath) => [
path.relative(path.dirname(config.originalPath), dirPath),
require(path.join(dirPath, 'package.json')),
])
.map(([link, package]) => {
let entry = `${options.bullet} [${package.name}](${link})`;
if (options.verbose === 'true' && package.description.trim().length) {
entry += ` - ${package.description.trim()}`;
}
return entry;
})
.join('\n');
};