Skip to content

Commit 797b958

Browse files
authored
Merge pull request #198 from docsbydoxdox/feature/custom-parser
[feat] Added new custom jsdoc template.
2 parents 845933d + a209459 commit 797b958

35 files changed

+1794
-0
lines changed

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "module",
44
"workspaces": [
55
"./packages/doxdox-core",
6+
"./packages/doxdox-parser-custom",
67
"./packages/doxdox-parser-dox",
78
"./packages/doxdox-parser-jsdoc",
89
"./packages/doxdox-parser-template",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/fixtures/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"parser": "@typescript-eslint/parser",
6+
"plugins": ["@typescript-eslint"],
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/eslint-recommended",
10+
"plugin:@typescript-eslint/recommended"
11+
],
12+
"rules": {
13+
"@typescript-eslint/no-explicit-any": "error",
14+
"@typescript-eslint/no-unused-vars": "error",
15+
"no-warning-comments": ["warn", { "terms": ["todo"], "location": "start" }],
16+
"no-magic-numbers": [
17+
"error",
18+
{
19+
"ignore": [-1, 0, 1]
20+
}
21+
]
22+
}
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
3+
coverage/
4+
5+
dist/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
coverage/
2+
3+
src/
4+
5+
tests/
6+
7+
.eslintrc
8+
9+
.prettierignore
10+
.prettierrc
11+
12+
tsconfig.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"arrowParens": "avoid",
3+
"singleQuote": true,
4+
"tabWidth": 4,
5+
"trailingComma": "none",
6+
"overrides": [
7+
{
8+
"files": ["*.json", ".*rc", "*.md"],
9+
"options": {
10+
"tabWidth": 2
11+
}
12+
}
13+
]
14+
}

packages/doxdox-parser-custom/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Scott Doxey
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# doxdox-parser-custom
2+
3+
> Custom parser for doxdox.
4+
5+
[![NPM version](https://img.shields.io/npm/v/doxdox-parser-custom?style=flat-square)](https://www.npmjs.org/package/doxdox-parser-custom)
6+
[![NPM downloads per month](https://img.shields.io/npm/dm/doxdox-parser-custom?style=flat-square)](https://www.npmjs.org/package/doxdox-parser-custom)
7+
[![doxdox documentation](https://img.shields.io/badge/doxdox-documentation-%23E85E95?style=flat-square)](https://doxdox.org)
8+
9+
## Install
10+
11+
```bash
12+
$ npm install doxdox-cli@v4.0.0-preview.15 doxdox-parser-custom@v4.0.0-preview.15 --save-dev
13+
```
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "doxdox-parser-custom",
3+
"description": "Custom parser for doxdox",
4+
"version": "4.0.0-preview.15",
5+
"exports": "./dist/index.js",
6+
"types": "./dist/index.d.ts",
7+
"type": "module",
8+
"engines": {
9+
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
10+
},
11+
"dependencies": {
12+
"comment-parser": "1.3.1"
13+
},
14+
"peerDependencies": {
15+
"doxdox-core": "4.0.0-preview.15"
16+
},
17+
"peerDependenciesMeta": {
18+
"doxdox-core": {
19+
"optional": false
20+
}
21+
},
22+
"devDependencies": {
23+
"@types/jest": "29.0.3",
24+
"@types/node": "18.7.18",
25+
"@typescript-eslint/eslint-plugin": "5.38.0",
26+
"@typescript-eslint/parser": "5.38.0",
27+
"eslint": "8.23.1",
28+
"jest": "29.0.3",
29+
"rimraf": "3.0.2",
30+
"ts-jest": "29.0.1",
31+
"ts-jest-resolver": "2.0.0",
32+
"typescript": "4.8.3"
33+
},
34+
"scripts": {
35+
"test": "npx cross-env@7 NODE_OPTIONS=--experimental-vm-modules jest --runInBand --passWithNoTests",
36+
"test-update": "npx cross-env@7 NODE_OPTIONS=--experimental-vm-modules jest --runInBand --passWithNoTests --updateSnapshot",
37+
"build": "rimraf dist/ && tsc",
38+
"lint": "eslint 'src/**/*.ts'"
39+
},
40+
"jest": {
41+
"collectCoverage": true,
42+
"extensionsToTreatAsEsm": [
43+
".ts"
44+
],
45+
"transform": {
46+
"^.+\\.ts$": [
47+
"ts-jest",
48+
{
49+
"useESM": true
50+
}
51+
]
52+
},
53+
"resolver": "ts-jest-resolver",
54+
"testRegex": ".*.test.ts$"
55+
},
56+
"keywords": [
57+
"doxdox",
58+
"documentation",
59+
"custom"
60+
],
61+
"authors": [
62+
{
63+
"name": "Scott Doxey",
64+
"email": "hello@scottdoxey.com",
65+
"homepage": "http://scottdoxey.com/"
66+
}
67+
],
68+
"license": "MIT",
69+
"homepage": "https://github.com/docsbydoxdox/doxdox",
70+
"repository": {
71+
"type": "git",
72+
"url": "git://github.com/docsbydoxdox/doxdox.git"
73+
}
74+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { parseString } from './index';
2+
3+
describe('custom parser', () => {
4+
it('parse example jsdoc headers', async () => {
5+
await expect(
6+
parseString(
7+
'lib/utils/index.js',
8+
`/**
9+
* Finds file in path.
10+
*
11+
* console.log(await findFileInPath('./', 'package.json'));
12+
* console.log(await findFileInPath('../', 'package.json'));
13+
* console.log(await findFileInPath('~/git/github/doxdox/', '.package.json'));
14+
*
15+
* @param {string} [input] Directory to check for file.
16+
* @param {string?} [fileName = 'package.json'] File name to check for.
17+
* @return {Promise<string | null>} Path to package.json file.
18+
* @public
19+
*/
20+
21+
const findFileInPath = async (input, fileName = 'package.json') => {};
22+
23+
/**
24+
* Get the root directory of the package, supplied path or URL.
25+
*
26+
* @param {string?} [url] Optional path or URL.
27+
* @return {string} Directory path.
28+
* @public
29+
*/
30+
31+
const getRootDirPath = (url) => {};`
32+
)
33+
).resolves.toEqual(
34+
expect.objectContaining({
35+
path: 'lib/utils/index.js',
36+
methods: expect.arrayContaining([
37+
expect.objectContaining({
38+
fullName: 'findFileInPath(input, fileName)',
39+
name: 'findFileInPath',
40+
params: expect.arrayContaining([
41+
expect.objectContaining({
42+
name: 'input',
43+
types: ['string']
44+
}),
45+
expect.objectContaining({
46+
name: 'fileName',
47+
types: ['string']
48+
})
49+
]),
50+
private: false,
51+
returns: expect.arrayContaining([
52+
expect.objectContaining({
53+
name: null,
54+
description: 'Path to package.json file.',
55+
types: ['Promise<string | null>']
56+
})
57+
]),
58+
slug: 'lib-utils-index-js-findfileinpath'
59+
}),
60+
expect.objectContaining({
61+
fullName: 'getRootDirPath(url)',
62+
name: 'getRootDirPath',
63+
params: expect.arrayContaining([
64+
expect.objectContaining({
65+
name: 'url',
66+
types: ['string']
67+
})
68+
]),
69+
private: false,
70+
returns: expect.arrayContaining([
71+
expect.objectContaining({
72+
name: null,
73+
description: 'Directory path.',
74+
types: ['string']
75+
})
76+
]),
77+
slug: 'lib-utils-index-js-getrootdirpath'
78+
})
79+
])
80+
})
81+
);
82+
});
83+
it('parse empty string', async () => {
84+
await expect(parseString('test.js', '')).resolves.toEqual(
85+
expect.objectContaining({
86+
path: 'test.js',
87+
methods: []
88+
})
89+
);
90+
});
91+
});

0 commit comments

Comments
 (0)