diff --git a/cmds/index.js b/cmds/index.js index 68b183b..10b535d 100755 --- a/cmds/index.js +++ b/cmds/index.js @@ -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'); @@ -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'); @@ -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('-')}`); diff --git a/example/documentation/code/config.js b/example/documentation/code/config.js index 8f1d2da..2e0578e 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":"components","children":[{"name":"sub","children":[{"name":"sub-test","path":"/sub-test","fullPath":"components/sub/sub-test"},{"name":"sub-vue-md","path":"/sub-vue-md","fullPath":"components/sub/sub-vue-md"}]},{"name":"test","path":"/test","fullPath":"components/test"},{"name":"vue-md","path":"/vue-md","fullPath":"components/vue-md"}]},{"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":"components","collapsable":false,"children":["components/sub/sub-test","components/sub/sub-vue-md","components/test","components/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 +exports.fileTree=[{"name":"Icon","path":"/Icon","fullPath":"./documentation/code/Icon"},{"name":"class-constructor","path":"/class-constructor","fullPath":"./documentation/code/class-constructor"},{"name":"components","children":[{"name":"sub","children":[{"name":"sub-test","path":"/sub-test","fullPath":"components/sub/sub-test"},{"name":"sub-vue-md","path":"/sub-vue-md","fullPath":"components/sub/sub-vue-md"}]},{"name":"test","path":"/test","fullPath":"components/test"},{"name":"vue-md","path":"/vue-md","fullPath":"components/vue-md"}]},{"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":"first.test","path":"/first.test","fullPath":"tests/first.test"}]},{"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":"components","collapsable":false,"children":["components/sub/sub-test","components/sub/sub-vue-md","components/test","components/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","tests/first.test"]}]}); \ No newline at end of file diff --git a/example/documentation/code/tests/first.test.md b/example/documentation/code/tests/first.test.md new file mode 100644 index 0000000..4f9ca0c --- /dev/null +++ b/example/documentation/code/tests/first.test.md @@ -0,0 +1,15 @@ +--- +title: first.test +--- + +# first.test + + + +## FirstTest +**Kind**: global class + + +### new FirstTest() +This is the FirstTest class + diff --git a/package-lock.json b/package-lock.json index 131428b..8a4a0f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,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" }, "bin": { @@ -10351,6 +10352,11 @@ "node": ">=8" } }, + "node_modules/shell-quote": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.2.tgz", + "integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==" + }, "node_modules/shelljs": { "version": "0.8.4", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz", @@ -20419,6 +20425,11 @@ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, + "shell-quote": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.2.tgz", + "integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==" + }, "shelljs": { "version": "0.8.4", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz", diff --git a/package.json b/package.json index 3524089..e1fa79f 100644 --- a/package.json +++ b/package.json @@ -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": {