-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
executable file
·66 lines (54 loc) · 1.78 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
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
#!/usr/bin/env node
const {generateDocumentation} = require('../dist/index.cjs.js');
const {readdirSync, statSync} = require('fs');
const {join, dirname} = require('path');
const help = process.argv.find((arg) => arg.indexOf('--help') > -1);
if (help !== undefined) {
console.log('Mandatory parameters:');
console.log('--src=<list of files> (comma separated if multiple or wild card)');
console.log('\nOptions:');
console.log('--dest=<destination file> (default README.md)');
console.log('--repo=<GitHub repo URL>');
console.log('--types');
console.log('--noemoji');
return;
}
const listFolderInputs = (dir) =>
readdirSync(dir)
.filter((file) => file.includes('ts') && statSync(join(dir, file)).isFile())
.map((file) => `${dir}/${file}`);
const listInputs = () =>
process.argv
.find((arg) => arg.indexOf('--src=') > -1)
?.replace('--src=', '')
?.split(',')
.reduce(
(acc, file) => [...acc, ...(file.endsWith('*') ? listFolderInputs(dirname(file)) : [file])],
[]
);
const inputFiles = listInputs();
const outputFile =
process.argv.find((arg) => arg.indexOf('--dest=') > -1)?.replace('--dest=', '') ?? 'README.md';
const repoUrl = process.argv.find((arg) => arg.indexOf('--repo=') > -1)?.replace('--repo=', '');
const types = process.argv.find((arg) => arg.indexOf('--types') > -1) !== undefined;
const noEmoji = process.argv.find((arg) => arg.indexOf('--noemoji') > -1) !== undefined;
if (!inputFiles || inputFiles.length === 0) {
throw new Error('No source file(s) provided.');
}
generateDocumentation({
inputFiles,
outputFile,
buildOptions: {
...(repoUrl !== undefined && {
repo: {
url: repoUrl
}
}),
...(types && {types})
},
markdownOptions: {
...(noEmoji && {
emoji: null
})
}
});