Skip to content

Commit

Permalink
feat: add support to read .cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed May 29, 2022
1 parent b30989c commit b505754
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/ts-doc/bin/tsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const fs = require("fs");
const {buildApi} = require("../src/tasks/build-api");

const file = `${process.cwd()}/tsdoc.config.js`;
let config = {
rootDir: process.cwd(),
packagesDir: "packages/",
Expand All @@ -13,8 +12,14 @@ let config = {
modules: {}
};

if (fs.existsSync(file)) {
config = require(file);
const fileJS = `${process.cwd()}/tsdoc.config.js`;
if (fs.existsSync(fileJS)) {
config = require(fileJS);
}

const fileCJS = `${process.cwd()}/tsdoc.config.cjs`;
if (fs.existsSync(fileCJS)) {
config = require(fileCJS);
}

buildApi(config);
57 changes: 57 additions & 0 deletions packages/ts-doc/src/parsers/DocParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,63 @@ describe("DocParser", () => {
]);
});
});
describe("Decorator with params", () => {
it("should parse content and return all symbols", () => {
// GIVEN
const contents = readFileSync(__dirname + "/data/scenario-params.txt", {encoding: "utf8"});

// WHEN
const doc = new DocParser(contents).parse();

// THEN
expect(Array.from(doc.symbols.keys())).to.deep.eq(["MaxLength"]);

const symbol1 = doc.symbols.get("MaxLength");

expect(!!symbol1).to.eq(true);
expect(symbol1.symbolType).to.equal("decorator");
expect(symbol1.overview).to.equal("function MaxLength(maxLength: number): (...args: any[]) => any;");
expect(symbol1.labels).to.deep.equal([
{
key: "param",
value: "{number} maxLength The maximum length allowed"
},
{
key: "decorator",
value: "decorator"
},
{
key: "ajv",
value: "ajv"
},
{
key: "jsonMapper",
value: "jsonMapper"
},
{
key: "swagger",
value: "swagger"
},
{
key: "schema",
value: "schema"
},
{
key: "propertyDecorator",
value: "propertyDecorator"
},
{
key: "paramDecorator",
value: "paramDecorator"
},
{
key: "model",
value: "model"
}
]);
expect(symbol1.getMembers()).to.deep.equal([]);
});
});
describe("Decorator with multiple signature definition", () => {
it("should parse content and return all symbols", () => {
// GIVEN
Expand Down
76 changes: 76 additions & 0 deletions packages/ts-doc/src/parsers/data/scenario-params.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
*
* A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
*
* 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).
*
* ::: warning
* The value of maxLength MUST be a non-negative integer.
* :::
*
* ::: tip
* Omitting this keyword has the same behavior as a value of 0.
* :::
*
* ## Example
* ### With primitive type
*
* ```typescript
* class Model {
* @MaxLength(10)
* property: number;
* }
* ```
*
* Will produce:
*
* ```json
* {
* "type": "object",
* "properties": {
* "property": {
* "type": "string",
* "maxLength": 10
* }
* }
* }
* ```
*
* ### With array type
*
* ```typescript
* class Model {
* @MaxLength(10)
* @CollectionOf(String)
* property: string[];
* }
* ```
*
* Will produce:
*
* ```json
* {
* "type": "object",
* "properties": {
* "property": {
* "type": "array",
* "items": {
* "type": "string",
* "maxLength": 10
* }
* }
* }
* }
* ```
*
* @param {number} maxLength The maximum length allowed
* @decorator
* @ajv
* @jsonMapper
* @swagger
* @schema
* @propertyDecorator
* @paramDecorator
* @model
*/
export declare function MaxLength(maxLength: number): (...args: any[]) => any;

0 comments on commit b505754

Please sign in to comment.