Skip to content

Commit c356bcc

Browse files
committed
docs: fix watch-mode and add more informations
1 parent 453019f commit c356bcc

File tree

8 files changed

+50
-72
lines changed

8 files changed

+50
-72
lines changed

documentation/.vuepress/config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ module.exports = {
1111
require('../../dist/index.js').default,
1212
{
1313
folder: 'code',
14-
jsDocConfigPath: './jsdoc.json',
15-
source: './src',
14+
source: './dist',
1615
dist: './documentation',
17-
title: 'API'
16+
title: 'API',
17+
partials: ['./example/partials/*.hbs'],
18+
readme: './README.md',
19+
exclude: '**/*.d.ts,**/interfaces.*,**/constants.*,**/cmds.*'
1820
}
1921
]
2022
],

src/__tests__/utils.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { checkExtension, getExtension, getFilename, asyncForEach } from '../lib/utils';
1+
import { checkExtension, getExtension, getFilename } from '../lib/utils';
22

33
describe('test utils', () => {
44
test('getExtension should return true', () => {
@@ -19,16 +19,4 @@ describe('test utils', () => {
1919
// @ts-expect-error check empty method
2020
expect(getFilename()).toBe('');
2121
});
22-
test('asyncForEach should run array async', async () => {
23-
const promise1 = Promise.resolve(1);
24-
const promise2 = Promise.resolve(2);
25-
26-
const results: number[] = [];
27-
28-
await asyncForEach([promise1, promise2], async result => {
29-
results.push(await result);
30-
});
31-
32-
expect(results).toEqual([1, 2]);
33-
});
3422
});

src/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { generateVueSidebar } from './lib/vue-sidebar';
2121

2222
/**
2323
* Create the sidebar
24-
* @param options
24+
* @param options {object}
2525
* @returns {Promise}
2626
*/
2727
const createVuepressSidebar = options =>
@@ -37,8 +37,8 @@ const createVuepressSidebar = options =>
3737

3838
/**
3939
* Parse file
40-
* @param file
41-
* @param argv
40+
* @param file {DirectoryFile}
41+
* @param argv {CLIArguments}
4242
* @returns {Promise}
4343
*/
4444
const parseDirectoryFile = async (file: DirectoryFile, argv: CLIArguments) => {
@@ -83,7 +83,7 @@ const createReadmeFile = async (argv: CLIArguments, deletedPaths?: string[]) =>
8383

8484
/**
8585
* Parse all CLI arguments
86-
* @param argv
86+
* @param argv {CLIArguments}
8787
* @returns {object} all arguments
8888
*/
8989
const parseArguments = (argv: CLIArguments) => {
@@ -187,6 +187,10 @@ export const generate = async (argv: CLIArguments) => {
187187
watchFiles(argv);
188188
};
189189

190+
/**
191+
* Watch files in source folder
192+
* @param argv {CLIArguments}
193+
*/
190194
const watchFiles = (argv: CLIArguments) => {
191195
const { exclude, srcFolder, codeFolder, docsFolder, title } = parseArguments(argv);
192196

@@ -230,8 +234,8 @@ const watchFiles = (argv: CLIArguments) => {
230234

231235
/**
232236
* The vuepress plugins
233-
* @param argv
234-
* @param ctx
237+
* @param argv {CLIArguments}
238+
* @param ctx {object}
235239
* @returns {object}
236240
*/
237241
const plugin = (argv: CLIArguments, ctx) => ({

src/lib/comment-parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { DirectoryFile } from '../interfaces';
1010

1111
/**
1212
* Search in file for @vuepress comment
13-
* @param fileContent
13+
* @param fileContent {string} content of given file
1414
* @returns {object} object of found frontmatter data
1515
*/
1616
export const parseComment = (fileContent: string) => {
@@ -45,9 +45,9 @@ export const parseComment = (fileContent: string) => {
4545
};
4646

4747
/**
48-
* Helper function to get header as strctured markdown
49-
* @param content : ;
50-
* @param file
48+
* Helper function to get header as structured markdown
49+
* @param content {string} file content
50+
* @param file {object} file object
5151
* @returns {string} markdown header
5252
*/
5353
export const parseVuepressFileHeader = (content: string, file: DirectoryFile) => {

src/lib/list-folder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { DirectoryFile, FileTree } from '../interfaces';
1212

1313
/**
1414
* Recursively traverse folders and return exluded files, a file list and a file tree.
15-
* @param srcPath
16-
* @param exclude
17-
* @param mainPath
18-
* @param tree
15+
* @param srcPath {string} path to source dir
16+
* @param exclude {array} exluded file patter list
17+
* @param mainPath {string} path to hold source dir
18+
* @param tree {object} tree array
1919
* @returns {object} paths array, tree, excluded array
2020
*/
2121
export const listFolder = async (srcPath: string, exclude: string[] = [], mainPath?: string, tree: FileTree[] = []) => {

src/lib/parser.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { parseVuepressFileHeader } from './comment-parser';
1818

1919
/**
2020
* Parse a typescript or javascript file
21-
* @param file
22-
* @param srcFolder
23-
* @param destFolder
24-
* @param configPath
25-
* @param partials
21+
* @param file {DirectoryFile}
22+
* @param srcFolder {string}
23+
* @param destFolder {string}
24+
* @param configPath {string}
25+
* @param partials {string | string[]}
2626
* @returns {object} file data
2727
*/
2828
export const parseFile = async (
@@ -91,9 +91,9 @@ export const parseFile = async (
9191

9292
/**
9393
* Parse a vue file
94-
* @param file
95-
* @param srcFolder
96-
* @param destFolder
94+
* @param file {DirectoryFile}
95+
* @param srcFolder {string}
96+
* @param destFolder {string}
9797
* @returns {object} file data
9898
*/
9999
export const parseVueFile = async (
@@ -153,9 +153,9 @@ export const parseVueFile = async (
153153

154154
/**
155155
* Write content on disk
156-
* @param parseData
157-
* @param dest
158-
* @returns {object | null} null or type with some data of the saved file
156+
* @param parseData {ParseReturn | null}
157+
* @param dest {string}
158+
* @returns {Promise | null} null or type with some data of the saved file
159159
*/
160160
export const writeContentToFile = async (parseData: ParseReturn | null, dest: string) => {
161161
const root = process.cwd();

src/lib/utils.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,26 @@
66
*/
77
/**
88
* Get extension of file
9-
* @param path
9+
* @param path {string}
1010
* @returns {string} extension of file
1111
*/
1212
export const getExtension = (path: string) => path.substring(path.length, path.lastIndexOf('.'));
1313

1414
/**
1515
* Check if extension ist correct
16-
* @param path
17-
* @param extensions
16+
* @param path {string}
17+
* @param extensions {string[]}
1818
* @returns {boolean}
1919
*/
2020
export const checkExtension = (path: string, extensions: string[]) => extensions.indexOf(getExtension(path)) >= 0;
2121

2222
/**
2323
* Get filename without extension
24-
* @param path
24+
* @param path {string}
2525
* @returns {string} filename
2626
*/
2727
export const getFilename = (path: string) =>
2828
path
2929
?.split('/')
3030
?.pop()
3131
?.substring(0, path.lastIndexOf('.')) || '';
32-
33-
/**
34-
* Async foreach loop
35-
* @param array
36-
* @callback callback
37-
*/
38-
export const asyncForEach = async (
39-
array: any[],
40-
callback: (result: any, index: number, array: any[]) => Promise<void>
41-
) => {
42-
for (let index = 0; index < array.length; index++) {
43-
await callback(array[index], index, array);
44-
}
45-
};

src/lib/vue-sidebar.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66
*/
77
import fs from 'fs';
88
import { join } from 'path';
9-
interface Node {
10-
name: string;
11-
children: any[];
12-
}
9+
10+
import { FileTree } from '../interfaces';
1311

1412
/**
1513
* Runs through the given tree structure and creates a vuepress config
1614
* @param data Informations to build config
17-
* @param data.fileTree tree strcture
18-
* @param data.codeFolder ./code/ folder
19-
* @param data.srcFolder ./src/ folder
20-
* @param data.docsFolder ./documentation/ folder
21-
* @param data.title title string
15+
* @param data.fileTree {array} tree strcture
16+
* @param data.codeFolder {string}./code/ folder
17+
* @param data.srcFolder {string} ./src/ folder
18+
* @param data.docsFolder {string} ./documentation/ folder
19+
* @param data.title {string} title string
2220
* @returns {object} returns the vuepress menu strcture
2321
*/
2422
export const generateVueSidebar = ({
@@ -35,9 +33,9 @@ export const generateVueSidebar = ({
3533
title: string;
3634
}) => {
3735
let rootFiles = [['', '::vuepress-jsdoc-title::']];
38-
rootFiles = rootFiles.concat(fileTree.filter((file: Node) => !file.children).map((file: Node) => file.name));
36+
rootFiles = rootFiles.concat(fileTree.filter((file: FileTree) => !file.children).map((file: FileTree) => file.name));
3937

40-
const rootFolder = fileTree.filter((file: Node) => file.children && file.children.length > 0);
38+
const rootFolder = fileTree.filter((file: FileTree) => file.children && file.children.length > 0);
4139

4240
const buildChildren = (children: any[], name: string, depth: number) => {
4341
let newChildren: any[] = [];
@@ -55,10 +53,10 @@ export const generateVueSidebar = ({
5553
return newChildren;
5654
};
5755

58-
const tree = rootFolder.map((folder: Node) => ({
56+
const tree = rootFolder.map((folder: FileTree) => ({
5957
title: folder.name,
6058
collapsable: false,
61-
children: buildChildren(folder.children, folder.name, 0)
59+
children: buildChildren(folder.children!, folder.name, 0)
6260
}));
6361

6462
return {

0 commit comments

Comments
 (0)