Skip to content

Commit

Permalink
refactor: fix some code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 3, 2021
1 parent 5340d78 commit a910cff
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
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.

16 changes: 8 additions & 8 deletions example/documentation/code/lib/jsdoc-to-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const jsdoc2md = require('jsdoc-to-markdown')
**Kind**: Exported class
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+render"></a>

#### jsdoc2md.render([options]) -> <code>Promise</code>
#### jsdoc2md.render([options]) <code>Promise</code>
Returns markdown documentation from jsdoc-annoted source code.

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
Expand Down Expand Up @@ -64,7 +64,7 @@ Pass in filepaths (`**` glob matching supported) of javascript source files:
```
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getTemplateData"></a>

#### jsdoc2md.getTemplateData([options]) -> <code>Promise</code>
#### jsdoc2md.getTemplateData([options]) <code>Promise</code>
Returns the template data (jsdoc-parse output) which is fed into the output template (dmd).

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
Expand All @@ -77,7 +77,7 @@ Returns the template data (jsdoc-parse output) which is fed into the output temp

<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getJsdocData"></a>

#### jsdoc2md.getJsdocData([options]) -> <code>Promise</code>
#### jsdoc2md.getJsdocData([options]) <code>Promise</code>
Returns raw data direct from the underlying [jsdoc3](https://github.com/jsdoc3/jsdoc).

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
Expand All @@ -94,14 +94,14 @@ Returns raw data direct from the underlying [jsdoc3](https://github.com/jsdoc3/j

<a name="module_jsdoc-to-markdown--JsdocToMarkdown+clear"></a>

#### jsdoc2md.clear() -> <code>Promise</code>
#### jsdoc2md.clear() <code>Promise</code>
By default, the output of each invocation of the main generation methods (`render`, `getTemplateData` etc) is stored in the cache (your system's [temporary directory](https://nodejs.org/dist/latest-v6.x/docs/api/os.html#os_os_tmpdir)). Future jsdoc2md invocations with the same input options and source code will return the output immediately from cache, making the tool much faster/cheaper. If the input options or source code changes, fresh output will be generated. This method clears the cache, which you should never need to do unless the cache is failing for some reason. On Mac OSX, the system tmpdir clears itself every few days meaning your jsdoc2md cache will also be routinely cleared.

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
**Category**: async
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getNamepaths"></a>

#### jsdoc2md.getNamepaths(options) -> <code>object</code>
#### jsdoc2md.getNamepaths(options) <code>object</code>
Returns all [jsdoc namepaths](http://usejsdoc.org/about-namepaths.html) found in the supplied source code.

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
Expand All @@ -113,7 +113,7 @@ Returns all [jsdoc namepaths](http://usejsdoc.org/about-namepaths.html) found in

<a name="module_jsdoc-to-markdown--JsdocToMarkdown+renderSync"></a>

#### jsdoc2md.renderSync([options]) -> <code>string</code>
#### jsdoc2md.renderSync([options]) <code>string</code>
Sync version of [render](#module_jsdoc-to-markdown--JsdocToMarkdown+render).

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
Expand All @@ -130,7 +130,7 @@ const docs = jsdoc2md.renderSync({ files: 'lib/*.js' })
```
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getTemplateDataSync"></a>

#### jsdoc2md.getTemplateDataSync([options]) -> <code>Array.&lt;object&gt;</code>
#### jsdoc2md.getTemplateDataSync([options]) <code>Array.&lt;object&gt;</code>
Sync version of [getTemplateData](#module_jsdoc-to-markdown--JsdocToMarkdown+getTemplateData).

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
Expand All @@ -142,7 +142,7 @@ Sync version of [getTemplateData](#module_jsdoc-to-markdown--JsdocToMarkdown+get

<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getJsdocDataSync"></a>

#### jsdoc2md.getJsdocDataSync([options]) -> <code>Array.&lt;object&gt;</code>
#### jsdoc2md.getJsdocDataSync([options]) <code>Array.&lt;object&gt;</code>
Sync version of [getJsdocData](#module_jsdoc-to-markdown--JsdocToMarkdown+getJsdocData).

**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
Expand Down
8 changes: 4 additions & 4 deletions example/documentation/code/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ headline: Custom Title!
## Functions

<dl>
<dt><a href="#ES6Method">ES6Method(param)</a> -> <code>string</code></dt>
<dt><a href="#ES6Method">ES6Method(param)</a> <code>string</code></dt>
<dd><p>A normal ES6 Method</p>
</dd>
<dt><a href="#standardMethod">standardMethod()</a> -> <code>string</code></dt>
<dt><a href="#standardMethod">standardMethod()</a> <code>string</code></dt>
<dd><p>A normal standard Method</p>
</dd>
</dl>

<a name="ES6Method"></a>

## ES6Method(param) -> <code>string</code>
## ES6Method(param) <code>string</code>
A normal ES6 Method

**Kind**: global function
Expand All @@ -29,7 +29,7 @@ A normal ES6 Method

<a name="standardMethod"></a>

## standardMethod() -> <code>string</code>
## standardMethod() <code>string</code>
A normal standard Method

**Kind**: global function
2 changes: 1 addition & 1 deletion example/documentation/code/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ name
**Kind**: static property of [<code>obj</code>](#obj)
<a name="obj.objMethod"></a>

### obj.objMethod(parameter) ->
### obj.objMethod(parameter)
A function with a parameter and returns the name

**Kind**: static method of [<code>obj</code>](#obj)
Expand Down
2 changes: 1 addition & 1 deletion example/documentation/code/tests/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Get current name
**Kind**: instance property of [<code>Test</code>](#Test)
<a name="Test+generateFullName"></a>

### test.generateFullName() ->
### test.generateFullName()
Generate a fullname

**Kind**: instance method of [<code>Test</code>](#Test)
Expand Down
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

3 changes: 2 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ParseReturn {
export interface FileTree {
name: string;
path?: string;
ext?: string;
fullPath?: string;
children?: FileTree[];
}
}
21 changes: 14 additions & 7 deletions src/lib/list-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,26 @@ export const listFolder = async (srcPath: string, exclude: string[] = [], mainPa
// skip readmes as they are automatically resolved
if (name.toLowerCase() === 'readme') continue;

if (!mm.isMatch(path.join(srcPath.replace(mainPath || srcPath, ''), dirent.name), exclude)) {
const treeEntry: FileTree = {
name,
...(!isDir ? { path: `/${name}`, fullPath: path.join(srcPath, name), ext } : {})
};
const baseSrc = mainPath || srcPath;

tree.push(treeEntry);
if (!mm.isMatch(path.join(srcPath.replace(baseSrc, ''), dirent.name), exclude)) {
let treeEntry: FileTree = {
name
};

if (isDir) {
treeEntry.children = [];
paths.push(...(await listFolder(filePath, exclude, mainPath || srcPath, treeEntry.children)).paths);
paths.push(...(await listFolder(filePath, exclude, baseSrc, treeEntry.children)).paths);
} else {
treeEntry = {
...treeEntry,
path: `/${name}`,
fullPath: path.join(srcPath, name),
ext
};
}

tree.push(treeEntry);
paths.push(file);
} else {
excluded.push(file);
Expand Down

0 comments on commit a910cff

Please sign in to comment.