Skip to content

Commit

Permalink
feat(exclude): add pattern to exclude files
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Jan 29, 2019
1 parent 6d239da commit e13117b
Show file tree
Hide file tree
Showing 11 changed files with 6,958 additions and 17 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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
vuepress-jsdoc --source ./src --dist ./documentation --folder code --title API --exclude=*.test.js,exclude.js
```

### Commands
Expand All @@ -28,15 +28,16 @@ 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 |
| 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 |

### config.js

Expand All @@ -50,7 +51,7 @@ You can add all generated documentation files to your existing vuepress project

```bash
# First install vuepress
npm i vuepress -g
yarn global add vuepress

# Run the CLI
vuepress-jsdoc
Expand Down Expand Up @@ -141,4 +142,4 @@ yarn dev

# Generate dist folder
yarn build
```
```
20 changes: 17 additions & 3 deletions cmds/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mkdirp = require('mkdirp');
const jsdoc2md = require('jsdoc-to-markdown');
const vuedoc = require('@vuedoc/md');
const rimraf = require('rimraf');
const mm = require('micromatch');

const vueSidebar = require('../helpers/vueSidebar');
const parseVuepressComment = require('../helpers/commentParser');
Expand All @@ -18,6 +19,7 @@ const extensions = ['.ts', '.js', '.vue'];
* @param {Object} argv Arguments passed by yargs
*/
function generate(argv) {
const exclude = argv.exclude && (argv.exclude.split(',') || [argv.exclude]);
const srcFolder = argv.source;
const codeFolder = argv.folder;
const docsFolder = `${argv.dist}/${codeFolder}`;
Expand Down Expand Up @@ -100,6 +102,11 @@ function generate(argv) {

// iterate through all files in folder
await asyncForEach(files, async file => {
if (mm.contains(`${folder}/${file}`, exclude)) {
console.log('exclude', `${folder}/${file}`);
return;
}

const stat = await fs.lstat(`${folder}/${file}`);

let fileName = getFilename(file);
Expand All @@ -112,8 +119,15 @@ function generate(argv) {
if (stat.isDirectory(folder)) {
// check file length and skip empty folders
try {
await fs.mkdir(`${folderPath}/${file}`);
let files = await fs.readdir(`${folder}/${file}`);

files = files.filter(f => !mm.contains(f, exclude));

if (files.length > 0) {
await fs.mkdir(`${folderPath}/${file}`);
}
} catch (err) {
console.log(err);
console.log(`can't create folder, because it already exists`, `${folderPath}/${file}`);
}

Expand All @@ -137,7 +151,7 @@ function generate(argv) {
mdFileData = await vuedoc.md({
filename: `${folder}/${file}`
});
} else if (/\.(js|ts)$/.test(file)) {
} else if (/\.(js|ts)$/.test(file) && fileData) {
// render file
mdFileData = await jsdoc2md.render({
source: fileData,
Expand All @@ -148,7 +162,7 @@ function generate(argv) {
});
}

if (mdFileData !== '') {
if (mdFileData) {
const { frontmatter } = parseVuepressComment(fileData);

console.log('write file', `${folderPath}/${fileName}.md`);
Expand Down
3 changes: 2 additions & 1 deletion example/documentation/code/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ exports.fileTree = [
{ name: 'variables', path: '/variables', fullPath: 'subfolder/variables' }
]
},
{ name: 'test', path: '/test', fullPath: './documentation/code/test' }
{ name: 'test', path: '/test', fullPath: './documentation/code/test' },
{ name: 'tests', children: [] }
];
exports.sidebarTree = (title = 'Mainpage') => ({
'/code/': [
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"docs": "../bin/vuepress-jsdoc.js --source=./src --dist=./documentation --title=API",
"docs": "../bin/vuepress-jsdoc.js --source=./src --dist=./documentation --title=API --exclude=*.test.js",
"dev": "vuepress dev documentation",
"build": "vuepress build documentation"
},
Expand Down
6 changes: 6 additions & 0 deletions example/src/tests/first.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* This is the FirstTest class
*
* @class FirstTest
*/
class FirstTest {}
2 changes: 2 additions & 0 deletions helpers/commentParser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const fm = require('front-matter');

module.exports = fileContent => {
Expand Down
2 changes: 2 additions & 0 deletions helpers/vueSidebar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// create vuepress sidebar
module.exports = ({ fileTree, codeFolder, title }) => {
let rootFiles = [['', '::vuepress-jsdoc-title::']];
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ function main() {
default: '',
desc: 'Path to your custom readme',
type: 'string'
},
exclude: {
alias: 'e',
default: '',
desc: 'Pattern to exclude files/folders (Comma seperated) - *.test.js,exclude.js',
type: 'string'
}
});
}
Expand Down
Loading

0 comments on commit e13117b

Please sign in to comment.