From 5b8954757cafc4057a27439d25abfef3cc919680 Mon Sep 17 00:00:00 2001 From: ph1p Date: Mon, 15 Feb 2021 00:56:51 +0100 Subject: [PATCH] feat(exclude): update pattern check and fix some bugs --- README.md | 28 +++++----- cmds/index.js | 21 +++++--- example/documentation/code/config.js | 2 +- .../documentation/code/{ => tests}/class.md | 0 example/package.json | 2 +- example/src/tests/class.js | 52 +++++++++++++++++++ 6 files changed, 81 insertions(+), 24 deletions(-) rename example/documentation/code/{ => tests}/class.md (100%) create mode 100644 example/src/tests/class.js diff --git a/README.md b/README.md index 1ef0696..dbdbb3d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/cmds/index.js b/cmds/index.js index 6f33c9e..21a41c2 100755 --- a/cmds/index.js +++ b/cmds/index.js @@ -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}`); @@ -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}`); @@ -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'); @@ -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 { @@ -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 @@ -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); }); diff --git a/example/documentation/code/config.js b/example/documentation/code/config.js index 7c6dfa7..bdab386 100644 --- a/example/documentation/code/config.js +++ b/example/documentation/code/config.js @@ -1 +1 @@ -exports.fileTree=[{"name":"Icon","path":"/Icon","fullPath":"./documentation/code/Icon"},{"name":"class-constructor","path":"/class-constructor","fullPath":"./documentation/code/class-constructor"},{"name":"class","path":"/class","fullPath":"./documentation/code/class"},{"name":"documentation","children":[]},{"name":"lib","children":[{"name":"dmd-options","path":"/dmd-options","fullPath":"lib/dmd-options"},{"name":"jsdoc-to-markdown","path":"/jsdoc-to-markdown","fullPath":"lib/jsdoc-to-markdown"}]},{"name":"methods","path":"/methods","fullPath":"./documentation/code/methods"},{"name":"objects","path":"/objects","fullPath":"./documentation/code/objects"},{"name":"subfolder","children":[{"name":"subfolder.1","children":[{"name":"variables","path":"/variables","fullPath":"subfolder/subfolder.1/variables"}]},{"name":"variables","path":"/variables","fullPath":"subfolder/variables"}]},{"name":"test","path":"/test","fullPath":"./documentation/code/test"},{"name":"tests","children":[]},{"name":"vue-md","path":"/vue-md","fullPath":"./documentation/code/vue-md"}];exports.sidebarTree = (title = 'Mainpage') => ({"/code/":[{"title":"API","collapsable":false,"children":[["",""+title+""],"Icon","class-constructor","class","methods","objects","test","vue-md"]},{"title":"lib","collapsable":false,"children":["lib/dmd-options","lib/jsdoc-to-markdown"]},{"title":"subfolder","collapsable":false,"children":["subfolder/subfolder.1/variables","subfolder/variables"]}]}); \ No newline at end of file +exports.fileTree=[{"name":"Icon","path":"/Icon","fullPath":"./documentation/code/Icon"},{"name":"class-constructor","path":"/class-constructor","fullPath":"./documentation/code/class-constructor"},{"name":"lib","children":[{"name":"dmd-options","path":"/dmd-options","fullPath":"lib/dmd-options"},{"name":"jsdoc-to-markdown","path":"/jsdoc-to-markdown","fullPath":"lib/jsdoc-to-markdown"}]},{"name":"methods","path":"/methods","fullPath":"./documentation/code/methods"},{"name":"objects","path":"/objects","fullPath":"./documentation/code/objects"},{"name":"subfolder","children":[{"name":"subfolder.1","children":[{"name":"variables","path":"/variables","fullPath":"subfolder/subfolder.1/variables"}]},{"name":"variables","path":"/variables","fullPath":"subfolder/variables"}]},{"name":"test","path":"/test","fullPath":"./documentation/code/test"},{"name":"tests","children":[{"name":"class","path":"/class","fullPath":"tests/class"}]},{"name":"vue-md","path":"/vue-md","fullPath":"./documentation/code/vue-md"}];exports.sidebarTree = (title = 'Mainpage') => ({"/code/":[{"title":"API","collapsable":false,"children":[["",""+title+""],"Icon","class-constructor","methods","objects","test","vue-md"]},{"title":"lib","collapsable":false,"children":["lib/dmd-options","lib/jsdoc-to-markdown"]},{"title":"subfolder","collapsable":false,"children":["subfolder/subfolder.1/variables","subfolder/variables"]},{"title":"tests","collapsable":false,"children":["tests/class"]}]}); \ No newline at end of file diff --git a/example/documentation/code/class.md b/example/documentation/code/tests/class.md similarity index 100% rename from example/documentation/code/class.md rename to example/documentation/code/tests/class.md diff --git a/example/package.json b/example/package.json index 99ea269..4d01641 100644 --- a/example/package.json +++ b/example/package.json @@ -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" }, diff --git a/example/src/tests/class.js b/example/src/tests/class.js new file mode 100644 index 0000000..c71cf48 --- /dev/null +++ b/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;