Skip to content

Commit b505754

Browse files
committed
feat: add support to read .cjs
1 parent b30989c commit b505754

File tree

3 files changed

+141
-3
lines changed

3 files changed

+141
-3
lines changed

packages/ts-doc/bin/tsdoc.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const fs = require("fs");
33
const {buildApi} = require("../src/tasks/build-api");
44

5-
const file = `${process.cwd()}/tsdoc.config.js`;
65
let config = {
76
rootDir: process.cwd(),
87
packagesDir: "packages/",
@@ -13,8 +12,14 @@ let config = {
1312
modules: {}
1413
};
1514

16-
if (fs.existsSync(file)) {
17-
config = require(file);
15+
const fileJS = `${process.cwd()}/tsdoc.config.js`;
16+
if (fs.existsSync(fileJS)) {
17+
config = require(fileJS);
18+
}
19+
20+
const fileCJS = `${process.cwd()}/tsdoc.config.cjs`;
21+
if (fs.existsSync(fileCJS)) {
22+
config = require(fileCJS);
1823
}
1924

2025
buildApi(config);

packages/ts-doc/src/parsers/DocParser.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,63 @@ describe("DocParser", () => {
8888
]);
8989
});
9090
});
91+
describe("Decorator with params", () => {
92+
it("should parse content and return all symbols", () => {
93+
// GIVEN
94+
const contents = readFileSync(__dirname + "/data/scenario-params.txt", {encoding: "utf8"});
95+
96+
// WHEN
97+
const doc = new DocParser(contents).parse();
98+
99+
// THEN
100+
expect(Array.from(doc.symbols.keys())).to.deep.eq(["MaxLength"]);
101+
102+
const symbol1 = doc.symbols.get("MaxLength");
103+
104+
expect(!!symbol1).to.eq(true);
105+
expect(symbol1.symbolType).to.equal("decorator");
106+
expect(symbol1.overview).to.equal("function MaxLength(maxLength: number): (...args: any[]) => any;");
107+
expect(symbol1.labels).to.deep.equal([
108+
{
109+
key: "param",
110+
value: "{number} maxLength The maximum length allowed"
111+
},
112+
{
113+
key: "decorator",
114+
value: "decorator"
115+
},
116+
{
117+
key: "ajv",
118+
value: "ajv"
119+
},
120+
{
121+
key: "jsonMapper",
122+
value: "jsonMapper"
123+
},
124+
{
125+
key: "swagger",
126+
value: "swagger"
127+
},
128+
{
129+
key: "schema",
130+
value: "schema"
131+
},
132+
{
133+
key: "propertyDecorator",
134+
value: "propertyDecorator"
135+
},
136+
{
137+
key: "paramDecorator",
138+
value: "paramDecorator"
139+
},
140+
{
141+
key: "model",
142+
value: "model"
143+
}
144+
]);
145+
expect(symbol1.getMembers()).to.deep.equal([]);
146+
});
147+
});
91148
describe("Decorator with multiple signature definition", () => {
92149
it("should parse content and return all symbols", () => {
93150
// GIVEN
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
*
3+
* A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
4+
*
5+
* The length of a string instance is defined as the number of its characters as defined by [RFC 7159](http://json-schema.org/latest/json-schema-validation.html#RFC7159).
6+
*
7+
* ::: warning
8+
* The value of maxLength MUST be a non-negative integer.
9+
* :::
10+
*
11+
* ::: tip
12+
* Omitting this keyword has the same behavior as a value of 0.
13+
* :::
14+
*
15+
* ## Example
16+
* ### With primitive type
17+
*
18+
* ```typescript
19+
* class Model {
20+
* @MaxLength(10)
21+
* property: number;
22+
* }
23+
* ```
24+
*
25+
* Will produce:
26+
*
27+
* ```json
28+
* {
29+
* "type": "object",
30+
* "properties": {
31+
* "property": {
32+
* "type": "string",
33+
* "maxLength": 10
34+
* }
35+
* }
36+
* }
37+
* ```
38+
*
39+
* ### With array type
40+
*
41+
* ```typescript
42+
* class Model {
43+
* @MaxLength(10)
44+
* @CollectionOf(String)
45+
* property: string[];
46+
* }
47+
* ```
48+
*
49+
* Will produce:
50+
*
51+
* ```json
52+
* {
53+
* "type": "object",
54+
* "properties": {
55+
* "property": {
56+
* "type": "array",
57+
* "items": {
58+
* "type": "string",
59+
* "maxLength": 10
60+
* }
61+
* }
62+
* }
63+
* }
64+
* ```
65+
*
66+
* @param {number} maxLength The maximum length allowed
67+
* @decorator
68+
* @ajv
69+
* @jsonMapper
70+
* @swagger
71+
* @schema
72+
* @propertyDecorator
73+
* @paramDecorator
74+
* @model
75+
*/
76+
export declare function MaxLength(maxLength: number): (...args: any[]) => any;

0 commit comments

Comments
 (0)