Skip to content

Commit

Permalink
feat(exclude): update pattern check and fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Feb 14, 2021
1 parent a770921 commit 5b89547
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 24 deletions.
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -19,7 +19,7 @@ npm i vuepress-jsdoc -g

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

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

### Options

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

### config.js

Expand Down
21 changes: 13 additions & 8 deletions cmds/index.js
Expand Up @@ -78,11 +78,13 @@ async function generate(argv) {

// iterate through all files in folder
await asyncForEach(files, async file => {
if (exclude && mm.contains(`${chalk.dim(folder)}/${file}`, exclude)) {
let isExcluded = false;

if (exclude && mm.isMatch(path.join(folder.replace(srcFolder, ''), file), exclude)) {
console.log(chalk.reset.inverse.bold.blueBright(' EXCLUDE '), `${chalk.dim(folder)}/${chalk.bold(file)}`);

addToStatistics(file, 'exclude');
return;
isExcluded = true;
}

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

dirFiles = dirFiles.filter(f => !mm.contains(f, exclude));
dirFiles = dirFiles.filter(f => {
return !mm.isMatch(path.join(folder.replace(srcFolder, ''), file, f), exclude);
});

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

return Promise.resolve(files);
} catch (error) {
console.log(error);
if (error.code === 'ENOENT') {
console.log('cannot find source folder');
} else {
Expand Down Expand Up @@ -283,7 +288,7 @@ async function generate(argv) {
Object.keys(statistics).map(w => w.length)
);

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

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

console.log(
`${extension}${Array(maxExtLength - extension.length + maxExtLength / 2).join(
`${extension}${Array(Math.round(maxExtLength - extension.length + maxExtLength / 2)).join(
' '
)}| ${content} - ${total} total`
);
});

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

process.exit(errorCount ? 1 : 0);
});
Expand Down
2 changes: 1 addition & 1 deletion example/documentation/code/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
2 changes: 1 addition & 1 deletion example/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"docs": "../bin/vuepress-jsdoc.js -c ./jsdoc.json --source=./src --dist=./documentation --title=API --exclude=*.test.js --partials=./partials/*.hbs",
"docs": "../bin/vuepress-jsdoc.js -c ./jsdoc.json --source=./src --dist=./documentation --title=API --exclude=**/*/*.test.js,class.js --partials=./partials/*.hbs",
"dev": "vuepress dev documentation",
"build": "vuepress build documentation"
},
Expand Down
52 changes: 52 additions & 0 deletions example/src/tests/class.js
@@ -0,0 +1,52 @@
/*
* @vuepress
* ---
* test: test class
* ---
*/
/**
* This is a test class
*
* @class Test
*/
class Test {
/**
* Creates an instance of Test.
* @param {string} [name='Peter']
* @memberof Test
*/
constructor(name = 'Peter') {
this.name = name;
this.isActive = isActive;
}

/**
* Set current name
*
* @memberof Test
*/
set name(name) {
this.name = name;
}

/**
* Get current name
*
* @memberof Test
*/
get name() {
return this.name;
}

/**
* Generate a fullname
*
* @returns an string
* @memberof Test
*/
generateFullName() {
return `${this.name} Mustermann`;
}
}

export default Test;

0 comments on commit 5b89547

Please sign in to comment.