Skip to content

Commit

Permalink
fix(stats): add condition to check stats length
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Feb 18, 2021
1 parent 6e73ef8 commit afa705b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
14 changes: 10 additions & 4 deletions cmds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const del = require('del');
const mm = require('micromatch');
const chalk = require('chalk');
const child_process = require('child_process');
const quote = require('shell-quote').quote;

const vueSidebar = require('../helpers/vue-sidebar');
const parseVuepressComment = require('../helpers/comment-parser');
Expand Down Expand Up @@ -138,9 +139,14 @@ async function generate(argv) {

if (/\.vue$/.test(file)) {
const nodeModulesPath = path.join(path.dirname(fs.realpathSync(__filename)), '../node_modules');
const rootProjectFolder = process.cwd()
const rootProjectFolder = process.cwd();
process.chdir(folder); // Change current working directory to the folder of the current source file
child_process.execSync(`${nodeModulesPath}/.bin/vue-docgen ${file} ${path.join(rootProjectFolder, folderPath)}`);
const shellCommand = quote([
`${nodeModulesPath}/.bin/vue-docgen`,
file,
path.join(rootProjectFolder, folderPath)
]);
child_process.execSync(shellCommand);
process.chdir(rootProjectFolder); // Reset current working directory to root project folder

mdFileData = fs.readFileSync(`${folderPath}/${fileName}.md`, 'utf-8');
Expand Down Expand Up @@ -284,10 +290,10 @@ async function generate(argv) {
const resultTime = (Math.abs(startTime - +new Date()) / 1000).toFixed(2);

// get longest type string
const maxExtLength = Math.max.apply(
const maxExtLength = Object.keys(statistics).length ? Math.max.apply(
null,
Object.keys(statistics).map(w => w.length)
);
) : 0;

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

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.

15 changes: 15 additions & 0 deletions example/documentation/code/tests/first.test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: first.test
---

# first.test

<a name="FirstTest"></a>

## FirstTest
**Kind**: global class
<a name="new_FirstTest_new"></a>

### new FirstTest()
This is the FirstTest class

11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"jsdoc-to-markdown": "^6.0.1",
"micromatch": "^4.0.2",
"mkdirp": "^1.0.4",
"shell-quote": "^1.7.2",
"vue-docgen-cli": "^4.35.0"
},
"devDependencies": {
Expand Down

0 comments on commit afa705b

Please sign in to comment.