Skip to content

Commit 5b89547

Browse files
committed
feat(exclude): update pattern check and fix some bugs
1 parent a770921 commit 5b89547

File tree

6 files changed

+81
-24
lines changed

6 files changed

+81
-24
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ npm i vuepress-jsdoc -g
1919

2020
```bash
2121
# search code in src and move it to code (./documentation/code) in your vuepress folder (./documentation)
22-
vuepress-jsdoc --source ./src --dist ./documentation --folder code --title API --exclude *.test.js,exclude.js
22+
vuepress-jsdoc --source ./src --dist ./documentation --folder code --title API --exclude=**/*/*.test.js
2323
```
2424

2525
### Commands
@@ -32,19 +32,19 @@ If no command passed it will run `generate` as default
3232

3333
### Options
3434

35-
| Name | Alias | Default | Description |
36-
| ----------------- | ----- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
37-
| --source | -s | ./src | Source folder with .js or .ts files |
38-
| --dist | -d | ./documentation | Destination folder |
39-
| --folder | -f | ./code | Folder inside destination folder. Gets overwritten everytime |
40-
| --title | -t | API | Title of your documentation |
41-
| --help | -h | | Show help |
42-
| --version | -v | | Show current version |
43-
| --readme | -r | | Path to custom readme file |
44-
| --exclude | -e | | Pattern to exclude files/folders (Comma seperated) - \*.test.js,exclude.js |
45-
| --rmPattern | -rm | | Pattern when removing files. You can ex- and include files. (glob pattern) |
46-
| --partials | -p | | jsdoc2markdown partial templates (overwrites default ones) |
47-
| --jsDocConfigPath | -c | | Path to [JsDoc Config](http://usejsdoc.org/about-configuring-jsdoc.html) (experimental) |
35+
| Name | Alias | Default | Description |
36+
| ----------------- | ----- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
37+
| --source | -s | ./src | Source folder with .js or .ts files |
38+
| --dist | -d | ./documentation | Destination folder |
39+
| --folder | -f | ./code | Folder inside destination folder. Gets overwritten everytime |
40+
| --title | -t | API | Title of your documentation |
41+
| --help | -h | | Show help |
42+
| --version | -v | | Show current version |
43+
| --readme | -r | | Path to custom readme file |
44+
| --exclude | -e | | Pattern to exclude files/folders (Comma seperated) - \*.test.js,exclude.js [more information](https://github.com/micromatch/micromatch#ismatch) |
45+
| --rmPattern | -rm | | Pattern when removing files. You can ex- and include files. (glob pattern) |
46+
| --partials | -p | | jsdoc2markdown partial templates (overwrites default ones) |
47+
| --jsDocConfigPath | -c | | Path to [JsDoc Config](http://usejsdoc.org/about-configuring-jsdoc.html) (experimental) |
4848

4949
### config.js
5050

cmds/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ async function generate(argv) {
7878

7979
// iterate through all files in folder
8080
await asyncForEach(files, async file => {
81-
if (exclude && mm.contains(`${chalk.dim(folder)}/${file}`, exclude)) {
81+
let isExcluded = false;
82+
83+
if (exclude && mm.isMatch(path.join(folder.replace(srcFolder, ''), file), exclude)) {
8284
console.log(chalk.reset.inverse.bold.blueBright(' EXCLUDE '), `${chalk.dim(folder)}/${chalk.bold(file)}`);
8385

8486
addToStatistics(file, 'exclude');
85-
return;
87+
isExcluded = true;
8688
}
8789

8890
const stat = await fs.lstat(`${folder}/${file}`);
@@ -97,9 +99,11 @@ async function generate(argv) {
9799
if (stat.isDirectory(folder)) {
98100
// check file length and skip empty folders
99101
try {
100-
let dirFiles = await fs.readdir(`${folder}/${file}`);
102+
let dirFiles = await fs.readdir(path.join(folder, file));
101103

102-
dirFiles = dirFiles.filter(f => !mm.contains(f, exclude));
104+
dirFiles = dirFiles.filter(f => {
105+
return !mm.isMatch(path.join(folder.replace(srcFolder, ''), file, f), exclude);
106+
});
103107

104108
if (dirFiles.length > 0) {
105109
await fs.mkdir(`${folderPath}/${file}`);
@@ -126,7 +130,7 @@ async function generate(argv) {
126130
await readFiles(`${folder}/${file}`, depth + 1, tree.filter(treeItem => file === treeItem.name)[0].children);
127131
}
128132
// Else branch accessed when file is not a folder
129-
else {
133+
else if (!isExcluded) {
130134
// check if extension is correct
131135
if (checkExtension(file, extensions)) {
132136
const fileData = await fs.readFile(`${folder}/${file}`, 'utf8');
@@ -229,6 +233,7 @@ async function generate(argv) {
229233

230234
return Promise.resolve(files);
231235
} catch (error) {
236+
console.log(error);
232237
if (error.code === 'ENOENT') {
233238
console.log('cannot find source folder');
234239
} else {
@@ -283,7 +288,7 @@ async function generate(argv) {
283288
Object.keys(statistics).map(w => w.length)
284289
);
285290

286-
console.log(`\n${Array(maxExtLength + maxExtLength / 2).join('-')}`);
291+
console.log(`\n${Array(maxExtLength).join('-')}`);
287292

288293
const errorCount = Object.keys(statistics).reduce((b, c) => b + statistics[c].error, 0);
289294
// iterate trough stats
@@ -298,13 +303,13 @@ async function generate(argv) {
298303
const total = Object.keys(statusTypes).reduce((before, curr) => before + types[curr], 0);
299304

300305
console.log(
301-
`${extension}${Array(maxExtLength - extension.length + maxExtLength / 2).join(
306+
`${extension}${Array(Math.round(maxExtLength - extension.length + maxExtLength / 2)).join(
302307
' '
303308
)}| ${content} - ${total} total`
304309
);
305310
});
306311

307-
console.log(`${Array(maxExtLength + maxExtLength / 2).join('-')}\nTime: ${resultTime}s\n`);
312+
console.log(`${Array(maxExtLength).join('-')}\nTime: ${resultTime}s\n`);
308313

309314
process.exit(errorCount ? 1 : 0);
310315
});

example/documentation/code/config.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"docs": "../bin/vuepress-jsdoc.js -c ./jsdoc.json --source=./src --dist=./documentation --title=API --exclude=*.test.js --partials=./partials/*.hbs",
7+
"docs": "../bin/vuepress-jsdoc.js -c ./jsdoc.json --source=./src --dist=./documentation --title=API --exclude=**/*/*.test.js,class.js --partials=./partials/*.hbs",
88
"dev": "vuepress dev documentation",
99
"build": "vuepress build documentation"
1010
},

example/src/tests/class.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* @vuepress
3+
* ---
4+
* test: test class
5+
* ---
6+
*/
7+
/**
8+
* This is a test class
9+
*
10+
* @class Test
11+
*/
12+
class Test {
13+
/**
14+
* Creates an instance of Test.
15+
* @param {string} [name='Peter']
16+
* @memberof Test
17+
*/
18+
constructor(name = 'Peter') {
19+
this.name = name;
20+
this.isActive = isActive;
21+
}
22+
23+
/**
24+
* Set current name
25+
*
26+
* @memberof Test
27+
*/
28+
set name(name) {
29+
this.name = name;
30+
}
31+
32+
/**
33+
* Get current name
34+
*
35+
* @memberof Test
36+
*/
37+
get name() {
38+
return this.name;
39+
}
40+
41+
/**
42+
* Generate a fullname
43+
*
44+
* @returns an string
45+
* @memberof Test
46+
*/
47+
generateFullName() {
48+
return `${this.name} Mustermann`;
49+
}
50+
}
51+
52+
export default Test;

0 commit comments

Comments
 (0)