diff --git a/common/config/rush/npm-shrinkwrap.json b/common/config/rush/npm-shrinkwrap.json index 04004c3b..e2e74379 100644 --- a/common/config/rush/npm-shrinkwrap.json +++ b/common/config/rush/npm-shrinkwrap.json @@ -5,87 +5,89 @@ "requires": true, "dependencies": { "@babel/code-frame": { - "version": "7.0.0-beta.36", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.36.tgz", - "integrity": "sha512-sW77BFwJ48YvQp3Gzz5xtAUiXuYOL2aMJKDwiaY3OcvdqBFurtYfOpSa4QrNyDxmOGRFSYzUpabU2m9QrlWE7w==", + "version": "7.0.0-beta.38", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.38.tgz", + "integrity": "sha512-JNHofQND7Iiuy3f6RXSillN1uBe87DAp+1ktsBfSxfL3xWeGFyJC9jH5zu2zs7eqVGp2qXWvJZFiJIwOYnaCQw==", "requires": { "chalk": "2.3.0", "esutils": "2.0.2", "js-tokens": "3.0.2" } }, - "@rush-temp/test-generator-cli": { - "version": "file:projects/test-generator-cli.tgz", - "integrity": "sha1-6X6rHJJU5+82zdF9bZ62CZYrxzk=", + "@rush-temp/ts-docs-gen": { + "version": "file:projects/ts-docs-gen.tgz", + "integrity": "sha1-ELxjGtKC3CkijkONj/wPj7siK9E=", "requires": { - "@types/fs-extra": "4.0.7", - "@types/handlebars": "4.0.36", - "@types/yargs": "10.0.0", - "fast-glob": "1.0.1", - "fs-extra": "4.0.3", - "handlebars": "4.0.11", + "@simplrjs/markdown": "1.1.0", + "@simplrjs/test-generator-cli": "0.1.3", + "@types/fs-extra": "5.0.0", + "@types/jest": "22.1.1", + "@types/sinon": "4.1.3", + "@types/yargs": "10.0.1", + "fs-extra": "5.0.0", + "jest": "22.1.4", "simplr-logger": "1.0.1", "simplr-tslint": "0.0.1", - "tslint": "5.8.0", + "sinon": "4.2.2", + "ts-extractor": "4.0.0-rc.1", + "ts-jest": "22.0.2", + "tslint": "5.9.1", "typescript": "2.6.2", - "yargs": "10.0.3" + "yargs": "11.0.0" } }, - "@rush-temp/ts-docs-gen": { - "version": "file:projects/ts-docs-gen.tgz", - "integrity": "sha1-VpmYmmPCGxgpL+NQ/+Q7RbokkUI=", + "@simplrjs/markdown": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@simplrjs/markdown/-/markdown-1.1.0.tgz", + "integrity": "sha512-YkSe0VmOzAEtVz5qTEPZAc1nu4h1WBmNmSo3JqnN0+PEkZ3QJDCykUZ0AsLd4mJddDSJN9QcphuhqtZPry/BOA==", + "requires": { + "@types/string": "0.0.29", + "string": "3.3.3" + } + }, + "@simplrjs/test-generator-cli": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@simplrjs/test-generator-cli/-/test-generator-cli-0.1.3.tgz", + "integrity": "sha512-eL4JCeWg3rKKp/wioaOwkE7WaZyM6/8Rs1bZL0Zv3IEj1UzgaYQeOzINSvAfKCIErOmhUkaFMaYXYseRedZTtg==", "requires": { - "@simplrjs/markdown": "1.0.7", "@types/fs-extra": "5.0.0", - "@types/jest": "22.0.0", - "@types/sinon": "4.1.2", + "@types/handlebars": "4.0.36", + "@types/yargs": "10.0.1", "fast-glob": "1.0.1", "fs-extra": "5.0.0", - "jest": "22.0.4", + "handlebars": "4.0.11", "simplr-logger": "1.0.1", - "simplr-tslint": "0.0.1", - "sinon": "4.1.3", - "ts-extractor": "3.1.1", - "ts-jest": "22.0.0", - "tslint": "5.8.0", - "typescript": "2.6.2" + "typescript": "2.6.2", + "yargs": "10.1.2" }, "dependencies": { - "@types/fs-extra": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.0.tgz", - "integrity": "sha512-qtxDULQKUenuaDLW003CgC+0T0eiAfH3BrH+vSt87GLzbz5EZ6Ox6mv9rMttvhDOatbb9nYh0E1m7ydoYwUrAg==", - "requires": { - "@types/node": "8.5.2" - } - }, - "fs-extra": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", - "integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==", + "yargs": { + "version": "10.1.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-10.1.2.tgz", + "integrity": "sha512-ivSoxqBGYOqQVruxD35+EyCFDYNEFL/Uo6FcOnz+9xZdZzK0Zzw4r4KhbrME1Oo2gOggwJod2MnsdamSG7H9ig==", "requires": { - "graceful-fs": "4.1.11", - "jsonfile": "4.0.0", - "universalify": "0.1.1" + "cliui": "4.0.0", + "decamelize": "1.2.0", + "find-up": "2.1.0", + "get-caller-file": "1.0.2", + "os-locale": "2.1.0", + "require-directory": "2.1.1", + "require-main-filename": "1.0.1", + "set-blocking": "2.0.0", + "string-width": "2.1.1", + "which-module": "2.0.0", + "y18n": "3.2.1", + "yargs-parser": "8.1.0" } } } }, - "@simplrjs/markdown": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@simplrjs/markdown/-/markdown-1.0.7.tgz", - "integrity": "sha512-QIIyLpb37GHpQD+7a5FCz/cxB2RVBp8mn2rSoFMkC0ZZAFIsw1UEmy7B9nPTPW923VNW5w9+4GnVqCUqkvCqfQ==", - "requires": { - "@types/string": "0.0.29", - "string": "3.3.3" - } - }, "@types/fs-extra": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-4.0.7.tgz", - "integrity": "sha512-BN48b/2F3kL0Ual7tjcHjj0Fl+nuYKtHa0G/xT3Q43HuCpN7rQD5vIx6Aqnl9x10oBI5xMJh8Ly+FQpP205JlA==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.0.tgz", + "integrity": "sha512-qtxDULQKUenuaDLW003CgC+0T0eiAfH3BrH+vSt87GLzbz5EZ6Ox6mv9rMttvhDOatbb9nYh0E1m7ydoYwUrAg==", "requires": { - "@types/node": "8.5.2" + "@types/node": "9.4.0" } }, "@types/handlebars": { @@ -94,19 +96,19 @@ "integrity": "sha512-LjNiTX7TY7wtuC6y3QwC93hKMuqYhgV9A1uXBKNvZtVC8ZvyWAjZkJ5BvT0K7RKqORRYRLMrqCxpw5RgS+MdrQ==" }, "@types/jest": { - "version": "22.0.0", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-22.0.0.tgz", - "integrity": "sha512-YnvduQPdRtIfvBLqfs6am0iz/07sqd/VYyPoqLzyZAYGyjokJDiE+LCgqX13ef8PNOWG5+Opbcy9gn5ymSIHCg==" + "version": "22.1.1", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-22.1.1.tgz", + "integrity": "sha512-JSh6yk+GkeSkucPa3DllFtpDXe0BMxDTFqCxoryzGKvZiusdb97Sb7X5gnMiKdFGkHbTMjSH+HbE9wrBIzrUTA==" }, "@types/node": { - "version": "8.5.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.5.2.tgz", - "integrity": "sha512-KA4GKOpgXnrqEH2eCVhiv2CsxgXGQJgV1X0vsGlh+WCnxbeAE1GT44ZsTU1IN5dEeV/gDupKa7gWo08V5IxWVQ==" + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.0.tgz", + "integrity": "sha512-zkYho6/4wZyX6o9UQ8rd0ReEaiEYNNCqYFIAACe2Tf9DrYlgzWW27OigYHnnztnnZQwVRpwWmZKegFmDpinIsA==" }, "@types/sinon": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-4.1.2.tgz", - "integrity": "sha512-fL6bJHYRzbw/7ofbKiJ65SOAasoe5mZhHNSYKxWsF3sGl/arhRwDPwXJqM1xofKNTQD14HNX9VruicM7pm++mQ==" + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-4.1.3.tgz", + "integrity": "sha512-Xxn32Q3mAJHOMU20bxcT6HiPksUJEkZA+nyZS4NhLo8kKb8hLhkBgp5OeW/BI3+9QmdrvDRk3caYNqtYb+TEbA==" }, "@types/string": { "version": "0.0.29", @@ -114,9 +116,9 @@ "integrity": "sha512-p8YTvb6vTWL38JxSe1rCduwP2l0jNRZpHlDUWqLt5A3F4SOc7yBPPd3jBiSk3b66urjs2tFM2QOhf4yEzz9wiQ==" }, "@types/yargs": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-10.0.0.tgz", - "integrity": "sha512-c1v82fFxticW/Iy49M8tbYy/4OTxuNAZHBVJTFlTYiW6JZrZxA0Yepj8c8qHgS3ZUxqW8M49awWaaF1DUJf/Ow==" + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-10.0.1.tgz", + "integrity": "sha512-EvK+v8864qaRCjtqcJa7iUKWYTIvbdSZ4MJd99QTcBpq2FbVllwW7ldRBesBYINgj2Mn0yMQ2yZZJPej1DcJFA==" }, "abab": { "version": "1.0.4", @@ -158,14 +160,17 @@ "integrity": "sha512-O/klc27mWNUigtv0F8NJWbLF00OcegQalkqKURWdosW08YZKi4m6CnSUSvIZG1otNJbTWhN01Hhz389DW7mvDQ==" }, "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" }, "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", + "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "requires": { + "color-convert": "1.9.1" + } }, "anymatch": { "version": "1.3.2", @@ -349,6 +354,11 @@ "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.1.tgz", "integrity": "sha1-GdOGodntxufByF04iu28xW0zYC0=" }, + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -379,6 +389,16 @@ "js-tokens": "3.0.2" }, "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + }, "chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", @@ -390,6 +410,19 @@ "strip-ansi": "3.0.1", "supports-color": "2.0.0" } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "2.1.1" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" } } }, @@ -444,12 +477,12 @@ } }, "babel-jest": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-22.0.4.tgz", - "integrity": "sha512-/Yt61fUpdFjetYlnpj280BPKEsPnK4mqzxDdo8DybPvrPNrLurbAF/WBjn2nnoi1Hc2Ippsf12/aOp8ys/Vl1A==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-22.1.0.tgz", + "integrity": "sha512-5pKRFTlDr+x1JESNRd5leqvxEJk3dRwVvIXikB6Lr4BWZbBppk1Wp+BLUzxWL8tM+EYGLCWgfqkD35Sft8r8Lw==", "requires": { "babel-plugin-istanbul": "4.1.5", - "babel-preset-jest": "22.0.3" + "babel-preset-jest": "22.1.0" } }, "babel-messages": { @@ -471,9 +504,9 @@ } }, "babel-plugin-jest-hoist": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-22.0.3.tgz", - "integrity": "sha512-Z0pOZFs0xDctwF0bPEKrnAzvbbgDi2vDFbQ0EdofnLI2bOa3P1H66gNLb2vMJJaa00VDjfiGhIocsHvBkqtyEQ==" + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-22.1.0.tgz", + "integrity": "sha512-Og5sjbOZc4XUI3njqwYhS6WLTlHQUJ/y5+dOqmst8eHrozYZgT4OMzAaYaxhk75c2fBVYwn7+mNEN97XDO7cOw==" }, "babel-plugin-syntax-object-rest-spread": { "version": "6.13.0", @@ -501,11 +534,11 @@ } }, "babel-preset-jest": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-22.0.3.tgz", - "integrity": "sha512-FbMMniSMXFvkKldCf+e4Tuol/v3XMaIpIp8xiT1WFlEW3ZapTKDW9YgVt3hqcpZXsIGFf6eUF3Owxom7yFlI8w==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-22.1.0.tgz", + "integrity": "sha512-ps2UYz7IQpP2IgZ41tJjUuUDTxJioprHXD8fi9DoycKDGNqB3nAX/ggy1S3plaQd43ktBvMS1FkkyGNoBujFpg==", "requires": { - "babel-plugin-jest-hoist": "22.0.3", + "babel-plugin-jest-hoist": "22.1.0", "babel-plugin-syntax-object-rest-spread": "6.13.0" } }, @@ -597,7 +630,7 @@ "integrity": "sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg==", "requires": { "cache-base": "1.0.1", - "class-utils": "0.3.5", + "class-utils": "0.3.6", "component-emitter": "1.2.1", "define-property": "1.0.0", "isobject": "3.0.1", @@ -679,13 +712,6 @@ "integrity": "sha1-j/CbCixCFxihBRwmCzLkj0QpOM4=", "requires": { "resolve": "1.1.7" - }, - "dependencies": { - "resolve": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", - "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=" - } } }, "bser": { @@ -745,24 +771,6 @@ "ansi-styles": "3.2.0", "escape-string-regexp": "1.0.5", "supports-color": "4.5.0" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", - "requires": { - "color-convert": "1.9.1" - } - }, - "supports-color": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", - "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", - "requires": { - "has-flag": "2.0.0" - } - } } }, "chokidar": { @@ -809,14 +817,13 @@ "integrity": "sha512-uTGIPNx/nSpBdsF6xnseRXLLtfr9VLqkz8ZqHXr3Y7b6SftyRxBGjwMtJj1OhNbmlc1wZzLNAlAcvyIiE8a6ZA==" }, "class-utils": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.5.tgz", - "integrity": "sha1-F+eTEDdQ+WJ7IXbqNM/RtWWQPIA=", + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", + "integrity": "sha512-qOhPa/Fj7s6TY8H8esGu5QNpMMQxz79h+urzrNYN6mn+9BnxlDGf5QZ+XeCDsxSjPqsSR56XOZOJmpeurnLMeg==", "requires": { "arr-union": "3.1.0", "define-property": "0.2.5", "isobject": "3.0.1", - "lazy-cache": "2.0.2", "static-extend": "0.1.2" }, "dependencies": { @@ -882,25 +889,13 @@ } }, "cliui": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", - "integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.0.0.tgz", + "integrity": "sha512-nY3W5Gu2racvdDk//ELReY+dHjb9PlIcVDFXP72nVIhq2Gy3LuVXYwJoPVudwQnv1shtohpgkdCKT2YaKY0CKw==", "requires": { - "string-width": "1.0.2", - "strip-ansi": "3.0.1", + "string-width": "2.1.1", + "strip-ansi": "4.0.0", "wrap-ansi": "2.1.0" - }, - "dependencies": { - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" - } - } } }, "co": { @@ -944,9 +939,9 @@ } }, "commander": { - "version": "2.12.2", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz", - "integrity": "sha512-BFnaq5ZOGcDN7FlrtBT4xxkgIToalIIxwjxLWVJ8bGTpe1LroqMiqQXdA7ygc7CRvaYS+9zfPGFnJqFSayx+AA==" + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz", + "integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==" }, "component-emitter": { "version": "1.2.1", @@ -995,7 +990,7 @@ "glob2base": "0.0.12", "minimatch": "3.0.4", "mkdirp": "0.5.1", - "resolve": "1.5.0", + "resolve": "1.1.7", "safe-buffer": "5.1.1", "shell-quote": "1.6.1", "subarg": "1.0.0" @@ -1122,9 +1117,12 @@ "integrity": "sha512-QpVuMTEoJMF7cKzi6bvWhRulU1fZqZnvyVQgNhPaxxuTYwyjn/j1v9falseQ/uXWwPnO56RBfwtg4h/EQXmucA==" }, "domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.0.tgz", - "integrity": "sha512-WpwuBlZ2lQRFa4H/4w49deb9rJLot9KmqrKKjMc9qBl7CID+DdC2swoa34ccRl+anL2B6bLp6TjFdIdnzekMBQ==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.1.tgz", + "integrity": "sha512-raigMkn7CJNNo6Ihro1fzG7wr3fHuYVytzquZKX5n0yizGsTcYgzdIUwj1X9pK0VvjeihV+XiclP+DjwbsSKug==", + "requires": { + "webidl-conversions": "4.0.2" + } }, "duplexer": { "version": "0.1.1", @@ -1162,9 +1160,9 @@ } }, "es6-promise": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.2.tgz", - "integrity": "sha512-LSas5vsuA6Q4nEdf9wokY5/AJYXry98i0IzXsv49rYsgDGDNDPbqAYR1Pe23iFxygfbGZNR/5VrHXBCh2BhvUQ==" + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz", + "integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ==" }, "escape-string-regexp": { "version": "1.0.5", @@ -1227,6 +1225,11 @@ "strip-eof": "1.0.0" } }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" + }, "expand-brackets": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-2.1.4.tgz", @@ -1349,26 +1352,16 @@ } }, "expect": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/expect/-/expect-22.0.3.tgz", - "integrity": "sha512-QapzeQkcA3jCx4pDnD07I4SPPxScKbey8TD/WwrnzmpHmL5q0dUtXfUt5OIFOjVBCg+C4zn4Y1zK9Rb9SIDL1g==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-22.1.0.tgz", + "integrity": "sha512-8K+8TjNnZq73KYtqNWKWTbYbN8z4loeL+Pn2bqpmtTdBtLNXJtpz9vkUcQlFsgKMDRA3VM8GXRA6qbV/oBF7Bw==", "requires": { "ansi-styles": "3.2.0", - "jest-diff": "22.0.3", - "jest-get-type": "22.0.3", - "jest-matcher-utils": "22.0.3", - "jest-message-util": "22.0.3", - "jest-regex-util": "22.0.3" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", - "requires": { - "color-convert": "1.9.1" - } - } + "jest-diff": "22.1.0", + "jest-get-type": "22.1.0", + "jest-matcher-utils": "22.1.0", + "jest-message-util": "22.1.0", + "jest-regex-util": "22.1.0" } }, "extend": { @@ -1385,9 +1378,9 @@ } }, "extglob": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/extglob/-/extglob-2.0.3.tgz", - "integrity": "sha512-AyptZexgu7qppEPq59DtN/XJGZDrLcVxSHai+4hdgMMS9EpF4GBvygcWWApno8lL9qSjVpYt7Raao28qzJX1ww==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/extglob/-/extglob-2.0.4.tgz", + "integrity": "sha512-Nmb6QXkELsuBr24CJSkilo6UHHgbekK5UiZgfE6UHD3Eb27YC6oD+bhcT+tJ6cl8dmsgdQxnWlcry8ksBIBLpw==", "requires": { "array-unique": "0.3.2", "define-property": "1.0.0", @@ -1416,7 +1409,7 @@ "requires": { "bash-glob": "1.0.2", "glob-parent": "3.1.0", - "micromatch": "3.1.4", + "micromatch": "3.1.5", "readdir-enhanced": "1.5.2" } }, @@ -1526,9 +1519,9 @@ } }, "fs-extra": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz", - "integrity": "sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", + "integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==", "requires": { "graceful-fs": "4.1.11", "jsonfile": "4.0.0", @@ -1708,6 +1701,13 @@ "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", "requires": { "ansi-regex": "2.1.1" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + } } }, "has-flag": { @@ -1797,6 +1797,15 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" }, + "import-local": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/import-local/-/import-local-1.0.0.tgz", + "integrity": "sha512-vAaZHieK9qjGo58agRBg+bhHX3hoTZU/Oa3GESWLz7t1U62fk63aHuDJJEteXoDeTCcPmUT+z38gkHPZkkmpmQ==", + "requires": { + "pkg-dir": "2.0.0", + "resolve-cwd": "2.0.0" + } + }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -1869,9 +1878,9 @@ "integrity": "sha1-hut1OSgF3cM69xySoO7fdO52BLI=" }, "is-ci": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.0.10.tgz", - "integrity": "sha1-9zkzayYyNlBhqdSCcM1WrjNpMY4=", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.1.0.tgz", + "integrity": "sha512-c7TnwxLePuqIlxHgr7xtxzycJPegNHFuIrBkwbf8hc58//+Op1CqFkyS+xnIMkwn9UsJIwc174BIjkyBmSpjKg==", "requires": { "ci-info": "1.1.2" } @@ -1931,12 +1940,14 @@ } }, "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "is-generator-fn": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "requires": { - "number-is-nan": "1.0.1" - } + "resolved": "https://registry.npmjs.org/is-generator-fn/-/is-generator-fn-1.0.0.tgz", + "integrity": "sha1-lp1J4bszKfa7fwkIm+JleLLd1Go=" }, "is-glob": { "version": "4.0.0", @@ -2095,7 +2106,7 @@ "babel-types": "6.26.0", "babylon": "6.18.0", "istanbul-lib-coverage": "1.1.1", - "semver": "5.4.1" + "semver": "5.5.0" } }, "istanbul-lib-report": { @@ -2155,18 +2166,13 @@ } }, "jest": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest/-/jest-22.0.4.tgz", - "integrity": "sha512-S0tmgK5psULvt/11QzgAZWGpY5y5TkMRzd3T21Q13JzTx37Vx6F0Nw022c9Kc/IbEy+AHkKkGFVO5QafE8MrDg==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest/-/jest-22.1.4.tgz", + "integrity": "sha512-cIPkn+OFGabazPesbhnYkadPftoO2Fo3w84QjeIP+A8eZ5qj7Zs4PuTemAW8StNMxySJr0KPk/LhYG2GUHLexQ==", "requires": { - "jest-cli": "22.0.4" + "jest-cli": "22.1.4" }, "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" - }, "arr-diff": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz", @@ -2220,41 +2226,43 @@ } }, "jest-cli": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-22.0.4.tgz", - "integrity": "sha512-f1lZRM13IwIINzjE3RebXQKtQLiKncpSrbJZ/aTZJXmzEWGdgSayW4ESyhU+xK3uGiJEUSzbHjwPY6nGJ8VbUA==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-22.1.4.tgz", + "integrity": "sha512-p7yOu0Q5uuXb3Q93qEg3LE6eNGgAGueakifxXNEqQx4b0lOl2YlC9t6BLQWNOJ+z42VWK/BIdFjf6lxKcTkjFA==", "requires": { "ansi-escapes": "3.0.0", "chalk": "2.3.0", + "exit": "0.1.2", "glob": "7.1.2", "graceful-fs": "4.1.11", - "is-ci": "1.0.10", + "import-local": "1.0.0", + "is-ci": "1.1.0", "istanbul-api": "1.2.1", "istanbul-lib-coverage": "1.1.1", "istanbul-lib-instrument": "1.9.1", "istanbul-lib-source-maps": "1.2.2", - "jest-changed-files": "22.0.3", - "jest-config": "22.0.4", - "jest-environment-jsdom": "22.0.4", - "jest-get-type": "22.0.3", - "jest-haste-map": "22.0.3", - "jest-message-util": "22.0.3", - "jest-regex-util": "22.0.3", - "jest-resolve-dependencies": "22.0.3", - "jest-runner": "22.0.4", - "jest-runtime": "22.0.4", - "jest-snapshot": "22.0.3", - "jest-util": "22.0.4", - "jest-worker": "22.0.3", + "jest-changed-files": "22.1.4", + "jest-config": "22.1.4", + "jest-environment-jsdom": "22.1.4", + "jest-get-type": "22.1.0", + "jest-haste-map": "22.1.0", + "jest-message-util": "22.1.0", + "jest-regex-util": "22.1.0", + "jest-resolve-dependencies": "22.1.0", + "jest-runner": "22.1.4", + "jest-runtime": "22.1.4", + "jest-snapshot": "22.1.2", + "jest-util": "22.1.4", + "jest-worker": "22.1.0", "micromatch": "2.3.11", - "node-notifier": "5.1.2", + "node-notifier": "5.2.1", "realpath-native": "1.0.0", "rimraf": "2.6.2", "slash": "1.0.0", "string-length": "2.0.0", "strip-ansi": "4.0.0", "which": "1.3.0", - "yargs": "10.0.3" + "yargs": "10.1.2" } }, "kind-of": { @@ -2285,96 +2293,107 @@ "regex-cache": "0.4.4" } }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "yargs": { + "version": "10.1.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-10.1.2.tgz", + "integrity": "sha512-ivSoxqBGYOqQVruxD35+EyCFDYNEFL/Uo6FcOnz+9xZdZzK0Zzw4r4KhbrME1Oo2gOggwJod2MnsdamSG7H9ig==", "requires": { - "ansi-regex": "3.0.0" + "cliui": "4.0.0", + "decamelize": "1.2.0", + "find-up": "2.1.0", + "get-caller-file": "1.0.2", + "os-locale": "2.1.0", + "require-directory": "2.1.1", + "require-main-filename": "1.0.1", + "set-blocking": "2.0.0", + "string-width": "2.1.1", + "which-module": "2.0.0", + "y18n": "3.2.1", + "yargs-parser": "8.1.0" } } } }, "jest-changed-files": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-22.0.3.tgz", - "integrity": "sha512-CG7eNJNO9x1O/3J4Uhe2QXra1MnC9+KS1f2NeOg+7iQ+8dDCgxCtpusmKfu44TnEyKwkIDhDr6htPfPaI+Fwbw==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-22.1.4.tgz", + "integrity": "sha512-EpqJhwt+N/wEHRT+5KrjagVrunduOfMgAb7fjjHkXHFCPRZoVZwl896S7krx7txf5hrMNUkpECnOnO2wBgzJCw==", "requires": { "throat": "4.1.0" } }, "jest-config": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-22.0.4.tgz", - "integrity": "sha512-NcBeixqHjHDZO9+pUj+365LQV2s65d2f0/IrwlUyv0xaJovRNc6eDvoJ/r2UUlHnqjP3Go+R0ECUsXPXjk4SHw==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-22.1.4.tgz", + "integrity": "sha512-ZImFp7STrUDOgQLW5I5UloCiCRMh6HmMIYIoWqaQkxnR5ws7MuZFG/Ns9sZFyfrnyWCvcW91e+XcEfNeoa4Jew==", "requires": { "chalk": "2.3.0", "glob": "7.1.2", - "jest-environment-jsdom": "22.0.4", - "jest-environment-node": "22.0.4", - "jest-get-type": "22.0.3", - "jest-jasmine2": "22.0.4", - "jest-regex-util": "22.0.3", - "jest-resolve": "22.0.4", - "jest-util": "22.0.4", - "jest-validate": "22.0.3", - "pretty-format": "22.0.3" + "jest-environment-jsdom": "22.1.4", + "jest-environment-node": "22.1.4", + "jest-get-type": "22.1.0", + "jest-jasmine2": "22.1.4", + "jest-regex-util": "22.1.0", + "jest-resolve": "22.1.4", + "jest-util": "22.1.4", + "jest-validate": "22.1.2", + "pretty-format": "22.1.0" } }, "jest-diff": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-22.0.3.tgz", - "integrity": "sha512-Y7xN9Lc/NgFvR14lvjrJXB6x2x1LLe5NnMyzLvilBSSOyjy9uAVnR2Bt1YgzdfRrfaxsx7xFUVcqXLUnPkrJcA==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-22.1.0.tgz", + "integrity": "sha512-lowdbU/dzXh+2/MR5QcvU5KPNkO4JdAEYw0PkQCbIQIuy5+g3QZBuVhWh8179Fmpg4CQrz1WgoK/yQHDCHbqqw==", "requires": { "chalk": "2.3.0", "diff": "3.4.0", - "jest-get-type": "22.0.3", - "pretty-format": "22.0.3" + "jest-get-type": "22.1.0", + "pretty-format": "22.1.0" } }, "jest-docblock": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-22.0.3.tgz", - "integrity": "sha512-LhviP2rqIg2IzS6m97W7T032oMrT699Tr6Njjhhl4FCLj+75BUy9CsSmGgfoVEql1uc+myBkssvcbn7T9xDR+A==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-22.1.0.tgz", + "integrity": "sha512-/+OGgBVRJb5wCbXrB1LQvibQBz2SdrvDdKRNzY1gL+OISQJZCR9MOewbygdT5rVzbbkfhC4AR2x+qWmNUdJfjw==", "requires": { "detect-newline": "2.1.0" } }, "jest-environment-jsdom": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-22.0.4.tgz", - "integrity": "sha512-vnjefLZlsNsmnjKcaXkx2IxTBNG40vfRVOdMfcfkPkq85JxFB7wzNtjLx+RIfiNpIZd04C1PXbF0aJIenY85Ng==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-22.1.4.tgz", + "integrity": "sha512-YGqFJzei/kq5BgQ8su7igLoCl34ytUffr5ZoqwLrDzCmXUKyIiuwBFbWe3xFMG/crlDb1emhBXdzWM1yDEDw5Q==", "requires": { - "jest-mock": "22.0.3", - "jest-util": "22.0.4", - "jsdom": "11.5.1" + "jest-mock": "22.1.0", + "jest-util": "22.1.4", + "jsdom": "11.6.2" } }, "jest-environment-node": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-22.0.4.tgz", - "integrity": "sha512-9vjNKb86UivvKCZCudMNixQgdMnOG7ql6iVYnaiK0CmvZ0WQD+mlM10NvgiWpRv4HstcnRL1pY/GSIHXAD6qXw==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-22.1.4.tgz", + "integrity": "sha512-rQmtzgZVdyCzeXsE8i7Alw2483KSd2PYjssZWZYeNzonN/lBeUjjaOCgLWp6FspBzSTnYF7x6cN4umGZxYAhow==", "requires": { - "jest-mock": "22.0.3", - "jest-util": "22.0.4" + "jest-mock": "22.1.0", + "jest-util": "22.1.4" } }, "jest-get-type": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-22.0.3.tgz", - "integrity": "sha512-TaJnc/lnJQ3jwry+NUWkqaJmKrM/Ut3XdK89HfiqdI3DMRLd6Zb4wyKjwuNP37MEQqlNg0YWH4sbBR8D4exjCA==" + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-22.1.0.tgz", + "integrity": "sha512-nD97IVOlNP6fjIN5i7j5XRH+hFsHL7VlauBbzRvueaaUe70uohrkz7pL/N8lx/IAwZRTJ//wOdVgh85OgM7g3w==" }, "jest-haste-map": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-22.0.3.tgz", - "integrity": "sha512-VosIMOFQFu1rTF+MvOWVuv2KVmZ9eTkRgfwW2yUAs6/AhwmIfXRl/tih+fIOYcHzU4Auu1G8Fvl2kkF5g0k6/A==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-22.1.0.tgz", + "integrity": "sha512-vETdC6GboGlZX6+9SMZkXtYRQSKBbQ47sFF7NGglbMN4eyIZBODply8rlcO01KwBiAeiNCKdjUyfonZzJ93JEg==", "requires": { "fb-watchman": "2.0.0", "graceful-fs": "4.1.11", - "jest-docblock": "22.0.3", - "jest-worker": "22.0.3", + "jest-docblock": "22.1.0", + "jest-worker": "22.1.0", "micromatch": "2.3.11", - "sane": "2.2.0" + "sane": "2.3.0" }, "dependencies": { "arr-diff": { @@ -2460,45 +2479,47 @@ } }, "jest-jasmine2": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-22.0.4.tgz", - "integrity": "sha512-pn1XPHUkffHK6oNY1Dfl/+Rg0UuTdlg3aGDnjyK6dZzGEBeiH1uKuSgZEjy3Lj461l3atpzsQyw7ilXPyjFnUw==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-22.1.4.tgz", + "integrity": "sha512-+KoRiG4PUwURB7UXei2jzxvbCebhXgTYS+xWl3FsSYUn3flcxdcOgAsFolx31Dkk/B1bVf1HIKt/B6Ubucp9aQ==", "requires": { "callsites": "2.0.0", "chalk": "2.3.0", - "expect": "22.0.3", + "co": "4.6.0", + "expect": "22.1.0", "graceful-fs": "4.1.11", - "jest-diff": "22.0.3", - "jest-matcher-utils": "22.0.3", - "jest-message-util": "22.0.3", - "jest-snapshot": "22.0.3", - "source-map-support": "0.5.0" + "is-generator-fn": "1.0.0", + "jest-diff": "22.1.0", + "jest-matcher-utils": "22.1.0", + "jest-message-util": "22.1.0", + "jest-snapshot": "22.1.2", + "source-map-support": "0.5.3" } }, "jest-leak-detector": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-22.0.3.tgz", - "integrity": "sha512-xyVdAmcG8M3jWtVeadDUU6MAHLBrjkP4clz2UtTZ1gpe5bRLk27VjQOpzTwK20MkV/6iZQhSuRVuzHS5kD0HpA==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-22.1.0.tgz", + "integrity": "sha512-8QsCWkncWAqdvrXN4yXQp9vgWF6CT3RkRey+d06SIHX913uXzAJhJdZyo6eE+uHVYMxUbxqW93npbUFhAR0YxA==", "requires": { - "pretty-format": "22.0.3" + "pretty-format": "22.1.0" } }, "jest-matcher-utils": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-22.0.3.tgz", - "integrity": "sha512-FJbKpCR3K7YYE/Pnvy5OrLFgPEswpYWIfVtdwT2NC6pBARbYGX39KF3bTxS9yg2mv0YL2zHe3UbwzFsi9nFpVA==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-22.1.0.tgz", + "integrity": "sha512-Zn1OD9wVjILOdvRxgAnqiCN36OX6KJx+P2FHN+3lzQ0omG2N2OAguxE1QXuJJneG2yndlkXjekXFP254c0cSpw==", "requires": { "chalk": "2.3.0", - "jest-get-type": "22.0.3", - "pretty-format": "22.0.3" + "jest-get-type": "22.1.0", + "pretty-format": "22.1.0" } }, "jest-message-util": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-22.0.3.tgz", - "integrity": "sha512-AVBdCx7Oj5wBpMOH089lx7Zgwpdz9HbReA82HuVAlIT4kEQRvCy6Sl9yVWDGJwHTgB/OYQGkgmbv/P/K8TkWNw==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-22.1.0.tgz", + "integrity": "sha512-kftcoawOeOVUGuGWmMupJt7FGLK1pqOrh02FlJwtImmPGZ2yTWCTx2D+N/g95qD2jCbQ/ntH1goBixhAIIxL+g==", "requires": { - "@babel/code-frame": "7.0.0-beta.36", + "@babel/code-frame": "7.0.0-beta.38", "chalk": "2.3.0", "micromatch": "2.3.11", "slash": "1.0.0", @@ -2588,72 +2609,74 @@ } }, "jest-mock": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-22.0.3.tgz", - "integrity": "sha512-donODXcDG03EAEavc9xfJ7fBF/LNVjoZYkmj9DLrQ1B9YcT6wh8Xx7IYg25b8V/8F/eXPMAE0KK5q6Fqe6yAeg==" + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-22.1.0.tgz", + "integrity": "sha512-gL3/C8ds6e1PWiOTsV7sIejPP/ECYQgDbwMzbNCc+ZFPuPH3EpwsVLGmQqPK6okgnDagimbbQnss3kPJ8HCMtA==" }, "jest-regex-util": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-22.0.3.tgz", - "integrity": "sha512-mplC9chiAotES3ClzNhy0SJcfHB2DivooKJZW+2hDdvP8LLB+OUI+D6bJd7sncbKUsyFcmblEvpm/zz/hef7HA==" + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-22.1.0.tgz", + "integrity": "sha512-on0LqVS6Xeh69sw3d1RukVnur+lVOl3zkmb0Q54FHj9wHoq6dbtWqb3TSlnVUyx36hqjJhjgs/QLqs07Bzu72Q==" }, "jest-resolve": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-22.0.4.tgz", - "integrity": "sha512-yoxHsX4MTT2Ra/dFia9VCunzsA/4jMBENMmLjREIUkCIP1edk/PZUOGVVf680Gw04CtmT5stETylcbmbL7hJBw==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-22.1.4.tgz", + "integrity": "sha512-/HuCMeiTD6YJ+NF15bU1mal1r7Gov0GJozA7232XiYve7cOOnU2JwXBx3EQmcIuG38uNrRPjtgpiXkBqfnk4Og==", "requires": { "browser-resolve": "1.11.2", "chalk": "2.3.0" } }, "jest-resolve-dependencies": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-22.0.3.tgz", - "integrity": "sha512-u9MUNJIa9GJ0YFhvM0+Scr4tyX84nC42d3w18Cly1doY7pTT+9momm+TncpuDlFyB2aNmS8SfdEbiLr1e6tBwg==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-22.1.0.tgz", + "integrity": "sha512-76Ll61bD/Sus8wK8d+lw891EtiBJGJkWG8OuVDTEX0z3z2+jPujvQqSB2eQ+kCHyCsRwJ2PSjhn3UHqae/oEtA==", "requires": { - "jest-regex-util": "22.0.3" + "jest-regex-util": "22.1.0" } }, "jest-runner": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-22.0.4.tgz", - "integrity": "sha512-srBkbqmiSB+jzSaG652fmi3kS6rV6wS/4fOG8dxxBg3dCqNQcM2/L3TI3ZK0SwIAcdGJh5Gybs8aDboT8K9Cdw==", - "requires": { - "jest-config": "22.0.4", - "jest-docblock": "22.0.3", - "jest-haste-map": "22.0.3", - "jest-jasmine2": "22.0.4", - "jest-leak-detector": "22.0.3", - "jest-message-util": "22.0.3", - "jest-runtime": "22.0.4", - "jest-util": "22.0.4", - "jest-worker": "22.0.3", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-22.1.4.tgz", + "integrity": "sha512-HAyZ0Q2Fyk7mlbtbSKP75hNs9IP0Md7kzPUN1uNKbvQfZkXA/e7P0ttzAIGQtEbRx656tYwkfWNW+hXvs1i4/g==", + "requires": { + "exit": "0.1.2", + "jest-config": "22.1.4", + "jest-docblock": "22.1.0", + "jest-haste-map": "22.1.0", + "jest-jasmine2": "22.1.4", + "jest-leak-detector": "22.1.0", + "jest-message-util": "22.1.0", + "jest-runtime": "22.1.4", + "jest-util": "22.1.4", + "jest-worker": "22.1.0", "throat": "4.1.0" } }, "jest-runtime": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-22.0.4.tgz", - "integrity": "sha512-+7uEwf/4f8k1E/eViyGK6/M5yA4O3f6TdWViuqF9MV7vXwG2OVJu8YEZa5239nEnHJiwinXp4eZXX+HB4pQRPg==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-22.1.4.tgz", + "integrity": "sha512-r/UjVuQppDRwbUprDlLYdd8MTYY+H8H6BCqRujGjo5/QyIt3b0hppNoOQHF+0bHNtuz/sR9chJ9HJ3A1fiv9Pw==", "requires": { "babel-core": "6.26.0", - "babel-jest": "22.0.4", + "babel-jest": "22.1.0", "babel-plugin-istanbul": "4.1.5", "chalk": "2.3.0", "convert-source-map": "1.5.1", + "exit": "0.1.2", "graceful-fs": "4.1.11", - "jest-config": "22.0.4", - "jest-haste-map": "22.0.3", - "jest-regex-util": "22.0.3", - "jest-resolve": "22.0.4", - "jest-util": "22.0.4", + "jest-config": "22.1.4", + "jest-haste-map": "22.1.0", + "jest-regex-util": "22.1.0", + "jest-resolve": "22.1.4", + "jest-util": "22.1.4", "json-stable-stringify": "1.0.1", "micromatch": "2.3.11", "realpath-native": "1.0.0", "slash": "1.0.0", "strip-bom": "3.0.0", "write-file-atomic": "2.3.0", - "yargs": "10.0.3" + "yargs": "10.1.2" }, "dependencies": { "arr-diff": { @@ -2740,51 +2763,70 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=" + }, + "yargs": { + "version": "10.1.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-10.1.2.tgz", + "integrity": "sha512-ivSoxqBGYOqQVruxD35+EyCFDYNEFL/Uo6FcOnz+9xZdZzK0Zzw4r4KhbrME1Oo2gOggwJod2MnsdamSG7H9ig==", + "requires": { + "cliui": "4.0.0", + "decamelize": "1.2.0", + "find-up": "2.1.0", + "get-caller-file": "1.0.2", + "os-locale": "2.1.0", + "require-directory": "2.1.1", + "require-main-filename": "1.0.1", + "set-blocking": "2.0.0", + "string-width": "2.1.1", + "which-module": "2.0.0", + "y18n": "3.2.1", + "yargs-parser": "8.1.0" + } } } }, "jest-snapshot": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-22.0.3.tgz", - "integrity": "sha512-e/a/EvMsY5XROWy4QWX6PvYziuJ8ttD6+QcnbogODWtx2LGhvVQOb7pmqGTo0tL/p0vzFetZA9GlZSh/EfMepg==", + "version": "22.1.2", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-22.1.2.tgz", + "integrity": "sha512-45co/M0gTe6Y6yHaJLydEZKHOFpFHESLah40jW35DWd3pd7q188bsi0oUY4Kls7PDXUamvTWuTKTZXCtzwSvCw==", "requires": { "chalk": "2.3.0", - "jest-diff": "22.0.3", - "jest-matcher-utils": "22.0.3", + "jest-diff": "22.1.0", + "jest-matcher-utils": "22.1.0", "mkdirp": "0.5.1", "natural-compare": "1.4.0", - "pretty-format": "22.0.3" + "pretty-format": "22.1.0" } }, "jest-util": { - "version": "22.0.4", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-22.0.4.tgz", - "integrity": "sha512-gNNPtcCFkVh7daKIl3/06eoQ90QXGXCyDOfyZ3IEyTWmHBdX3GvklcOtyGcdOvrYEubaZTfMcMKmEeo/6sRTog==", + "version": "22.1.4", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-22.1.4.tgz", + "integrity": "sha512-zM29idoVBPvmpsGubS7YmywVyPe4/m1wE2YhmKp0vVmrQmuby7ObuMqabp82EYlM0Rdp4GNEtaDamW9jg8lgTg==", "requires": { "callsites": "2.0.0", "chalk": "2.3.0", "graceful-fs": "4.1.11", - "is-ci": "1.0.10", - "jest-message-util": "22.0.3", - "jest-validate": "22.0.3", + "is-ci": "1.1.0", + "jest-message-util": "22.1.0", + "jest-validate": "22.1.2", "mkdirp": "0.5.1" } }, "jest-validate": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-22.0.3.tgz", - "integrity": "sha512-GmlLmPCtrSQ3iB4A1uxcfjawaaQnwESCDcUg5tMxJKeBbmPdcWPAb6EWzvANxULPUV7hfPKLwg4xIPpi7cx1/g==", + "version": "22.1.2", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-22.1.2.tgz", + "integrity": "sha512-IjvMsV7GW5ghg5PTQvU23zJqTBmnq10eY+4n47awUeXYEGH27N+JajFPOg6tsN+OYvEPsohPquKoqQ5XBVs/ow==", "requires": { "chalk": "2.3.0", - "jest-get-type": "22.0.3", + "jest-get-type": "22.1.0", "leven": "2.1.0", - "pretty-format": "22.0.3" + "pretty-format": "22.1.0" } }, "jest-worker": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-22.0.3.tgz", - "integrity": "sha512-fPdCTnogFQiR0CP6whEsIly2RfcHxvalqyLjhui6qa1SnOmHiX7L8k4Umo8CBIp5ndWY0+ej1o7OTE5MlzPabg==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-22.1.0.tgz", + "integrity": "sha512-ezLueYAQowk5N6g2J7bNZfq4NWZvMNB5Qd24EmOZLcM5SXTdiFvxykZIoNiMj9C98cCbPaojX8tfR7b1LJwNig==", "requires": { "merge-stream": "1.0.1" } @@ -2804,9 +2846,9 @@ } }, "jsdom": { - "version": "11.5.1", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.5.1.tgz", - "integrity": "sha512-89ztIZ03aYK9f1uUrLXLsZndRge/JnZjzjpaN+lrse3coqz+8PR/dX4WLHpbF5fIKTXhDjFODOJw2328lPJ90g==", + "version": "11.6.2", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.6.2.tgz", + "integrity": "sha512-pAeZhpbSlUp5yQcS6cBQJwkbzmv4tWFaYxHbFVSxzXefqjvtRA851Z5N2P+TguVG9YeUDcgb8pdeVQRJh0XR3Q==", "requires": { "abab": "1.0.4", "acorn": "5.3.0", @@ -2816,22 +2858,24 @@ "content-type-parser": "1.0.2", "cssom": "0.3.2", "cssstyle": "0.2.37", - "domexception": "1.0.0", + "domexception": "1.0.1", "escodegen": "1.9.0", "html-encoding-sniffer": "1.0.2", "left-pad": "1.2.0", "nwmatcher": "1.4.3", - "parse5": "3.0.3", - "pn": "1.0.0", + "parse5": "4.0.0", + "pn": "1.1.0", "request": "2.83.0", "request-promise-native": "1.0.5", "sax": "1.2.4", "symbol-tree": "3.2.2", "tough-cookie": "2.3.3", + "w3c-hr-time": "1.0.1", "webidl-conversions": "4.0.2", "whatwg-encoding": "1.0.3", "whatwg-url": "6.4.0", - "xml-name-validator": "2.0.1" + "ws": "4.0.0", + "xml-name-validator": "3.0.0" } }, "jsesc": { @@ -2978,9 +3022,9 @@ "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=" }, "lolex": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.3.1.tgz", - "integrity": "sha512-mQuW55GhduF3ppo+ZRUTz1PRjEh1hS5BbqU7d8D0ez2OKxHDod7StPPeAVKisZR5aLkHZjdGWSL42LSONUJsZw==" + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.3.2.tgz", + "integrity": "sha512-A5pN2tkFj7H0dGIAM6MFvHKMJcPnjZsOMvR7ujCjfgW5TbV6H9vb1PgxLtHvjqNZTHsUolz+6/WEO0N1xNx2ng==" }, "loose-envify": { "version": "1.3.1", @@ -3042,19 +3086,19 @@ } }, "micromatch": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.4.tgz", - "integrity": "sha512-kFRtviKYoAJT+t7HggMl0tBFGNAKLw/S7N+CO9qfEQyisob1Oy4pao+geRbkyeEd+V9aOkvZ4mhuyPvI/q9Sfg==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.5.tgz", + "integrity": "sha512-ykttrLPQrz1PUJcXjwsTUjGoPJ64StIGNE2lGVD1c9CuguJ+L7/navsE8IcDNndOoCMvYV0qc/exfVbMHkUhvA==", "requires": { "arr-diff": "4.0.0", "array-unique": "0.3.2", "braces": "2.3.0", "define-property": "1.0.0", "extend-shallow": "2.0.1", - "extglob": "2.0.3", + "extglob": "2.0.4", "fragment-cache": "0.2.1", "kind-of": "6.0.2", - "nanomatch": "1.2.6", + "nanomatch": "1.2.7", "object.pick": "1.3.0", "regex-not": "1.0.0", "snapdragon": "0.8.1", @@ -3132,9 +3176,9 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "nanomatch": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.6.tgz", - "integrity": "sha512-WJ6XTCbvWXUFPbi/bDwKcYkCeOGUHzaJj72KbuPqGn78Ba/F5Vu26Zlo6SuMQbCIst1RGKL1zfWBCOGAlbRLAg==", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.7.tgz", + "integrity": "sha512-/5ldsnyurvEw7wNpxLFgjVvBLMta43niEYOy0CJ4ntcYSbx6bugRUTQeFb4BR/WanEL1o3aQgHuVLHQaB6tOqg==", "requires": { "arr-diff": "4.0.0", "array-unique": "0.3.2", @@ -3162,9 +3206,9 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=" }, "nise": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/nise/-/nise-1.2.0.tgz", - "integrity": "sha512-q9jXh3UNsMV28KeqI43ILz5+c3l+RiNW8mhurEwCKckuHQbL+hTJIKKTiUlCPKlgQ/OukFvSnKB/Jk3+sFbkGA==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/nise/-/nise-1.2.2.tgz", + "integrity": "sha512-rvxf+PSZeCKtP0DgmwMmNf1G3I6X1r4WHiP2H88PlIkOkt7mGqufdokjS8caoHBgZzVx0ee/5ytGcGHbZaUw8w==", "requires": { "formatio": "1.2.0", "just-extend": "1.1.27", @@ -3186,12 +3230,12 @@ "integrity": "sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs=" }, "node-notifier": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-5.1.2.tgz", - "integrity": "sha1-L6nhJgX6EACdRFSdb82KY93g5P8=", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-5.2.1.tgz", + "integrity": "sha512-MIBs+AAd6dJ2SklbbE8RUDRlIVhU8MaNLh1A9SUZDUHPiZkWLFde6UNwG41yQHZEToHgJMXqyVZ9UcS/ReOVTg==", "requires": { "growly": "1.3.0", - "semver": "5.4.1", + "semver": "5.5.0", "shellwords": "0.1.1", "which": "1.3.0" } @@ -3203,7 +3247,7 @@ "requires": { "hosted-git-info": "2.5.0", "is-builtin-module": "1.0.0", - "semver": "5.4.1", + "semver": "5.5.0", "validate-npm-package-license": "3.0.1" } }, @@ -3406,18 +3450,26 @@ "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" }, "p-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.1.0.tgz", - "integrity": "sha1-sH/y2aXYi+yAYDWJWiurZqJ5iLw=" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.2.0.tgz", + "integrity": "sha512-Y/OtIaXtUPr4/YpMv1pCL5L5ed0rumAaAeBSj12F+bSlMdys7i8oQF/GUJmfpTS/QoaRrS/k6pma29haJpsMng==", + "requires": { + "p-try": "1.0.0" + } }, "p-locate": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", "requires": { - "p-limit": "1.1.0" + "p-limit": "1.2.0" } }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" + }, "parse-glob": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/parse-glob/-/parse-glob-3.0.4.tgz", @@ -3453,12 +3505,9 @@ } }, "parse5": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz", - "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==", - "requires": { - "@types/node": "8.5.2" - } + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-4.0.0.tgz", + "integrity": "sha512-VrZ7eOd3T1Fk4XWNXMgiGBK/z0MG48BWG2uQNU4I72fkQuKUTZpl+u9k+CxEG0twMVzSmXEEz12z5Fnw1jIQFA==" }, "pascalcase": { "version": "0.1.1", @@ -3547,9 +3596,9 @@ } }, "pn": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/pn/-/pn-1.0.0.tgz", - "integrity": "sha1-HPWjCw2AbNGPiPxBprXUrWFbO6k=" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pn/-/pn-1.1.0.tgz", + "integrity": "sha512-2qHaIQr2VLRFoxe2nASzsV6ef4yOOH+Fi9FBOVH6cqeSgUnoyySPZkxzLuzd+RYOQTRpROA0ztTMqxROKSb/nA==" }, "posix-character-classes": { "version": "0.1.1", @@ -3567,27 +3616,12 @@ "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=" }, "pretty-format": { - "version": "22.0.3", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-22.0.3.tgz", - "integrity": "sha512-qXbDFJ2/Kk3HFIaLdOblbsCKQ09kZu4MKbXB+m/EaqD7PZ/wXe2XcRREmQleMh4wmerxlma6eJTh3nxCXYUmmA==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-22.1.0.tgz", + "integrity": "sha512-0HHR5hCmjDGU4sez3w5zRDAAwn7V0vT4SgPiYPZ1XDm5sT3Icb+Bh+fsOP3+Y3UwPjMr7TbRj+L7eQyMkPAxAw==", "requires": { "ansi-regex": "3.0.0", "ansi-styles": "3.2.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" - }, - "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", - "requires": { - "color-convert": "1.9.1" - } - } } }, "private": { @@ -3704,7 +3738,7 @@ "integrity": "sha1-YUYwSGkKxqRVt1ti+nioj43IXlM=", "requires": { "call-me-maybe": "1.0.1", - "es6-promise": "4.2.2", + "es6-promise": "4.2.4", "glob-to-regexp": "0.3.0" } }, @@ -3797,7 +3831,7 @@ "stringstream": "0.0.5", "tough-cookie": "2.3.3", "tunnel-agent": "0.6.0", - "uuid": "3.1.0" + "uuid": "3.2.1" } }, "request-promise-core": { @@ -3829,13 +3863,23 @@ "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" }, "resolve": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz", - "integrity": "sha512-hgoSGrc3pjzAPHNBg+KnFcK2HwlHTs/YrAGUr6qgTVUZmXv1UEXXl0bZNBKMA9fud6lRYFdPGz0xXxycPzmmiw==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", + "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=" + }, + "resolve-cwd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-2.0.0.tgz", + "integrity": "sha1-AKn3OHVW4nA46uIyyqNypqWbZlo=", "requires": { - "path-parse": "1.0.5" + "resolve-from": "3.0.0" } }, + "resolve-from": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", + "integrity": "sha1-six699nWiBvItuZTM17rywoYh0g=" + }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -3860,9 +3904,9 @@ "integrity": "sha512-1HwIYD/8UlOtFS3QO3w7ey+SdSDFE4HRNLZoZRYVQefrOY3l17epswImeB1ijgJFQJodIaHcwkp3r/myBjFVbg==" }, "sane": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/sane/-/sane-2.2.0.tgz", - "integrity": "sha512-OSJxhHO0CgPUw3lUm3GhfREAfza45smvEI9ozuFrxKG10GHVo0ryW9FK5VYlLvxj0SV7HVKHW0voYJIRu27GWg==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/sane/-/sane-2.3.0.tgz", + "integrity": "sha512-6GB9zPCsqJqQPAGcvEkUPijM1ZUFI+A/DrscL++dXO3Ltt5q5mPDayGxZtr3cBRkrbb4akbwszVVkTIFefEkcg==", "requires": { "anymatch": "1.3.2", "exec-sh": "0.2.1", @@ -3886,9 +3930,9 @@ "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" }, "semver": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", - "integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==" + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" }, "set-blocking": { "version": "2.0.0", @@ -3958,7 +4002,7 @@ "resolved": "https://registry.npmjs.org/simplr-logger/-/simplr-logger-1.0.1.tgz", "integrity": "sha512-lyDPiwbPi3jlOMj1Zufdmy60ibE3EyHgJ3nH/FzFNe9pfSz15mWYOt4FT860XFvxVQkZX7RxrqzPMoPSgAU3nQ==", "requires": { - "tslib": "1.8.1" + "tslib": "1.9.0" } }, "simplr-tslint": { @@ -3967,23 +4011,23 @@ "integrity": "sha512-Piq9BsldiMj5oJVWqMZvxZhr1HBj+OMhzUNNrzkhqkg567dSBFZVHlJepy6IA2o4RpM3V85e/TWygQ9fyhAu7g==" }, "sinon": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-4.1.3.tgz", - "integrity": "sha512-c7u0ZuvBRX1eXuB4jN3BRCAOGiUTlM8SE3TxbJHrNiHUKL7wonujMOB6Fi1gQc00U91IscFORQHDga/eccqpbw==", + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-4.2.2.tgz", + "integrity": "sha512-BEa593xl+IkIc94nKo0O0LauQC/gQy8Gyv4DkzPwF/9DweC5phr1y+42zibCpn9abfkdHxt9r8AhD0R6u9DE/Q==", "requires": { "diff": "3.4.0", "formatio": "1.2.0", "lodash.get": "4.4.2", - "lolex": "2.3.1", - "nise": "1.2.0", - "supports-color": "4.5.0", - "type-detect": "4.0.5" + "lolex": "2.3.2", + "nise": "1.2.2", + "supports-color": "5.1.0", + "type-detect": "4.0.7" }, "dependencies": { "supports-color": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", - "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.1.0.tgz", + "integrity": "sha512-Ry0AwkoKjDpVKK4sV4h6o3UJmNRbjYm2uXhwfj3J56lMVdvnUNqzQVRztOOMGQ++w1K/TjNDFvpJk0F/LoeBCQ==", "requires": { "has-flag": "2.0.0" } @@ -4125,9 +4169,9 @@ } }, "source-map-support": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.0.tgz", - "integrity": "sha512-vUoN3I7fHQe0R/SJLKRdKYuEdRGogsviXFkHHo17AWaTGv17VLnxw+CFXvqy+y4ORZ3doWLQcxRYfwKrsd/H7Q==", + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.3.tgz", + "integrity": "sha512-eKkTgWYeBOQqFGXRfKabMFdnWepo51vWqEdoeikaEPFiJC7MCU5j2h4+6Q8npkZTeLGbSyecZvRxiSoWl3rh+w==", "requires": { "source-map": "0.6.1" }, @@ -4305,21 +4349,6 @@ "requires": { "astral-regex": "1.0.0", "strip-ansi": "4.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "requires": { - "ansi-regex": "3.0.0" - } - } } }, "string-width": { @@ -4329,26 +4358,6 @@ "requires": { "is-fullwidth-code-point": "2.0.0", "strip-ansi": "4.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "requires": { - "ansi-regex": "3.0.0" - } - } } }, "stringstream": { @@ -4357,11 +4366,11 @@ "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" }, "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", "requires": { - "ansi-regex": "2.1.1" + "ansi-regex": "3.0.0" } }, "strip-bom": { @@ -4393,9 +4402,12 @@ } }, "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", + "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", + "requires": { + "has-flag": "2.0.0" + } }, "symbol-tree": { "version": "3.2.2", @@ -4643,83 +4655,86 @@ "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=" }, "ts-extractor": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/ts-extractor/-/ts-extractor-3.1.1.tgz", - "integrity": "sha512-5rU/I/f0JbbddHb0v1b5bJX+/b37VWP9vBpOQPAUVxDCV1eJ4MlKeVcgBAFajL76z9BxZVNXMHvyOtLUcEwHDw==", + "version": "4.0.0-rc.1", + "resolved": "https://registry.npmjs.org/ts-extractor/-/ts-extractor-4.0.0-rc.1.tgz", + "integrity": "sha512-4PFeaYNg3m5m4MHHOWVBQiqbz95hpgGXr2cNnd8rw0q2Qpq6pAmETn5+YwsJqwNdtoN0ASx+rte2EWY8UPXPLw==", "requires": { "@types/fs-extra": "5.0.0", "fs-extra": "5.0.0", "read-package-json": "2.0.12", "simplr-logger": "1.0.1", "typescript": "2.6.2" - }, - "dependencies": { - "@types/fs-extra": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.0.tgz", - "integrity": "sha512-qtxDULQKUenuaDLW003CgC+0T0eiAfH3BrH+vSt87GLzbz5EZ6Ox6mv9rMttvhDOatbb9nYh0E1m7ydoYwUrAg==", - "requires": { - "@types/node": "8.5.2" - } - }, - "fs-extra": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", - "integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==", - "requires": { - "graceful-fs": "4.1.11", - "jsonfile": "4.0.0", - "universalify": "0.1.1" - } - } } }, "ts-jest": { - "version": "22.0.0", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-22.0.0.tgz", - "integrity": "sha512-ATHKHtTzJPczvIj/4xrQxyTvmCUo/NL8pf5KWgLNLQX3dZYA65oJm9liBnegZLfphdhFerCKRtuBFGsmghYy1Q==", + "version": "22.0.2", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-22.0.2.tgz", + "integrity": "sha512-11FP07YRE12atlByBq65uidNexL7/IZsdjaK36A9fSyirCy2zDmT1QGBgMrzd83KAn5bgE3CImdY4ery79H8yQ==", "requires": { "babel-core": "6.26.0", "babel-plugin-istanbul": "4.1.5", "babel-plugin-transform-es2015-modules-commonjs": "6.26.0", - "babel-preset-jest": "22.0.3", + "babel-preset-jest": "22.1.0", "cpx": "1.5.0", "fs-extra": "4.0.3", - "jest-config": "22.0.4", + "jest-config": "22.1.4", "pkg-dir": "2.0.0", - "source-map-support": "0.5.0", - "yargs": "10.0.3" + "source-map-support": "0.5.3", + "yargs": "11.0.0" + }, + "dependencies": { + "fs-extra": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz", + "integrity": "sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==", + "requires": { + "graceful-fs": "4.1.11", + "jsonfile": "4.0.0", + "universalify": "0.1.1" + } + } } }, "tslib": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.8.1.tgz", - "integrity": "sha1-aUavLR1lGnsYY7Ux1uWvpBqkTqw=" + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.0.tgz", + "integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==" }, "tslint": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.8.0.tgz", - "integrity": "sha1-H0mtWy53x2w69N3K5VKuTjYS6xM=", + "version": "5.9.1", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.9.1.tgz", + "integrity": "sha1-ElX4ej/1frCw4fDmEKi0dIBGya4=", "requires": { "babel-code-frame": "6.26.0", "builtin-modules": "1.1.1", "chalk": "2.3.0", - "commander": "2.12.2", + "commander": "2.13.0", "diff": "3.4.0", "glob": "7.1.2", + "js-yaml": "3.10.0", "minimatch": "3.0.4", "resolve": "1.5.0", - "semver": "5.4.1", - "tslib": "1.8.1", - "tsutils": "2.15.0" + "semver": "5.5.0", + "tslib": "1.9.0", + "tsutils": "2.19.1" + }, + "dependencies": { + "resolve": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz", + "integrity": "sha512-hgoSGrc3pjzAPHNBg+KnFcK2HwlHTs/YrAGUr6qgTVUZmXv1UEXXl0bZNBKMA9fud6lRYFdPGz0xXxycPzmmiw==", + "requires": { + "path-parse": "1.0.5" + } + } } }, "tsutils": { - "version": "2.15.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.15.0.tgz", - "integrity": "sha512-kKb1mSqRMwF0GHKya5/hZsI2m7Flg4ONZDeYu4e6Gx+kYAu86zsLNCHcUmNWhCRaUcKshNI272hOzuaCQDzJ2g==", + "version": "2.19.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.19.1.tgz", + "integrity": "sha512-1B3z4H4HddgzWptqLzwrJloDEsyBt8DvZhnFO14k7A4RsQL/UhEfQjD4hpcY5NpF3veBkjJhQJ8Bl7Xp96cN+A==", "requires": { - "tslib": "1.8.1" + "tslib": "1.9.0" } }, "tunnel-agent": { @@ -4739,15 +4754,20 @@ } }, "type-detect": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.5.tgz", - "integrity": "sha512-N9IvkQslUGYGC24RkJk1ba99foK6TkwC2FHAEBlQFBP0RxQZS8ZpJuAZcwiY/w9ZJHFQb1aOXBI60OdxhTrwEQ==" + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.7.tgz", + "integrity": "sha512-4Rh17pAMVdMWzktddFhISRnUnFIStObtUMNGzDwlA6w/77bmGv3aBbRdCmQR6IjzfkTo9otnW+2K/cDRhKSxDA==" }, "typescript": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.6.2.tgz", "integrity": "sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q=" }, + "ultron": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", + "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==" + }, "union-value": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", @@ -4904,9 +4924,9 @@ } }, "uuid": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", - "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", + "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" }, "validate-npm-package-license": { "version": "3.0.1", @@ -4927,6 +4947,14 @@ "extsprintf": "1.3.0" } }, + "w3c-hr-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz", + "integrity": "sha1-gqwr/2PZUOqeMYmlimViX+3xkEU=", + "requires": { + "browser-process-hrtime": "0.1.2" + } + }, "walker": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.7.tgz", @@ -5001,6 +5029,19 @@ "strip-ansi": "3.0.1" }, "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "requires": { + "number-is-nan": "1.0.1" + } + }, "string-width": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", @@ -5010,6 +5051,14 @@ "is-fullwidth-code-point": "1.0.0", "strip-ansi": "3.0.1" } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "2.1.1" + } } } }, @@ -5028,10 +5077,20 @@ "signal-exit": "3.0.2" } }, + "ws": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-4.0.0.tgz", + "integrity": "sha512-QYslsH44bH8O7/W2815u5DpnCpXWpEK44FmaHffNwgJI4JMaSZONgPBTOfrxJ29mXKbXak+LsJ2uAkDTYq2ptQ==", + "requires": { + "async-limiter": "1.0.0", + "safe-buffer": "5.1.1", + "ultron": "1.1.1" + } + }, "xml-name-validator": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-2.0.1.tgz", - "integrity": "sha1-TYuPHszTQZqjYgYb7O9RXh5VljU=" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", + "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==" }, "y18n": { "version": "3.2.1", @@ -5044,11 +5103,11 @@ "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" }, "yargs": { - "version": "10.0.3", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-10.0.3.tgz", - "integrity": "sha512-DqBpQ8NAUX4GyPP/ijDGHsJya4tYqLQrjPr95HNsr1YwL3+daCfvBwg7+gIC6IdJhR2kATh3hb61vjzMWEtjdw==", + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-11.0.0.tgz", + "integrity": "sha512-Rjp+lMYQOWtgqojx1dEWorjCofi1YN7AoFvYV7b1gx/7dAAeuI4kN5SZiEvr0ZmsZTOpDRcCqrpI10L31tFkBw==", "requires": { - "cliui": "3.2.0", + "cliui": "4.0.0", "decamelize": "1.2.0", "find-up": "2.1.0", "get-caller-file": "1.0.2", @@ -5059,7 +5118,17 @@ "string-width": "2.1.1", "which-module": "2.0.0", "y18n": "3.2.1", - "yargs-parser": "8.1.0" + "yargs-parser": "9.0.2" + }, + "dependencies": { + "yargs-parser": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz", + "integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=", + "requires": { + "camelcase": "4.1.0" + } + } } }, "yargs-parser": { diff --git a/packages/ts-docs-gen/.vscode/settings.json b/packages/ts-docs-gen/.vscode/settings.json index 75ded211..74742330 100644 --- a/packages/ts-docs-gen/.vscode/settings.json +++ b/packages/ts-docs-gen/.vscode/settings.json @@ -7,6 +7,6 @@ "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, - "tests/**/__tests__/**/*.test.ts": true + "tests/cases/__tests__/**/*.test.ts": true } } diff --git a/packages/ts-docs-gen/README.md b/packages/ts-docs-gen/README.md index 9f99fba6..46a183cc 100644 --- a/packages/ts-docs-gen/README.md +++ b/packages/ts-docs-gen/README.md @@ -1 +1,45 @@ -# ts-docs-gen \ No newline at end of file +# ts-docs-gen + +_Readme is WIP._ + +Generates documentation from TypeScript files. + +## Get started +```sh +npm install ts-docs-gen -g +``` + +## CLI usage +```sh +ts-docs-gen -h +``` + +### Examples + +#### Without config + +If you want to use `ts-docs-gen` without config file, `entryFile` flag is required. +``` +ts-docs-gen --entryFile ./src/index.ts +``` + +Multiple entry files: +``` +ts-docs-gen --entryFile ./src/index.ts --entryFile ./src/internal.ts +``` + +#### With config + +``` +ts-docs-gen --config ./docs-gen.json +``` + +## Configuration +JSON config properties and CLI flags. + +| Property | CLI Flag | Required | Type | Default | Description | +|-------------|-------------------|------------|----------|---------------------------|--------------------------------------------| +| `entryFile` | `--entryFile` | _required_ | string[] | | TypeScript project entry files. | +| `project` | `--project`, `-p` | _optional_ | string | Current working directory | Full path to TypeScript project directory. | +| `output` | `--output`, `-o` | _optional_ | string | ./docs/api/ | Documentation output directory. | +| `plugin` | `--plugin` | _optional_ | string[] | | Packagename or path to plugin. | diff --git a/packages/ts-docs-gen/docs-gen.json b/packages/ts-docs-gen/docs-gen.json new file mode 100644 index 00000000..fb327e45 --- /dev/null +++ b/packages/ts-docs-gen/docs-gen.json @@ -0,0 +1,3 @@ +{ + "entryFile": "./src/index.ts" +} diff --git a/packages/ts-docs-gen/examples/simple/docs/api/exported-functions.md b/packages/ts-docs-gen/examples/simple/docs/api/exported-functions.md deleted file mode 100644 index a613767a..00000000 --- a/packages/ts-docs-gen/examples/simple/docs/api/exported-functions.md +++ /dev/null @@ -1,26 +0,0 @@ -# exported-functions - -## Functions - -### Foo() - -```typescript -function Foo(): string -``` - -**Return type** - -string - ----------- - -### Bar() - -```typescript -function Bar(): string -``` - -**Return type** - -string - diff --git a/packages/ts-docs-gen/examples/simple/docs/api/index.md b/packages/ts-docs-gen/examples/simple/docs/api/index.md index 65aac989..707a45c1 100644 --- a/packages/ts-docs-gen/examples/simple/docs/api/index.md +++ b/packages/ts-docs-gen/examples/simple/docs/api/index.md @@ -1,632 +1,17 @@ -[InterfaceDeclaration-16]: index.md#props -[InterfaceDeclaration-16]: index.md#props -[InterfaceDeclaration-1]: index.md#foo -[InterfaceDeclaration-2]: index.md#boo -[InterfaceDeclaration-4]: index.md#myconstrainttype -[InterfaceDeclaration-9]: index.md#dictionary -[InterfaceDeclaration-9]: index.md#dictionary -[InterfaceDeclaration-6]: index.md#objectsinterface -[InterfaceDeclaration-12]: index.md#monsterinterface -[ClassDeclaration-0]: index/hello.md#hello -# index +# index.ts -## Functions +## Namespaces -### Component(arg) +### [SimpleNamespace][ModuleDeclaration-0] -```typescript -function Component(arg: T): void -``` +General comment about SimpleNamespace. -**Type parameters** - -| Name | Constraint type | Default type | -| ---- | -------------------------------- | -------------------------------- | -| T | [Props][InterfaceDeclaration-16] | [Props][InterfaceDeclaration-16] | - -**Parameters** - -| Name | Type | -| ---- | ---- | -| arg | T | - -**Return type** - -void - -## Interfaces - -### ExtendedBar - -```typescript -interface ExtendedBar extends Foo, Boo { - OtherStuff: string[]; -} -``` - -**Extends** - -[Foo][InterfaceDeclaration-1]<number> - -[Boo][InterfaceDeclaration-2] - -**Properties** - -| Name | Type | -| ---------- | --------------------- | -| OtherStuff | Array<string> | - ----------- - -### Foo - -```typescript -interface Foo { - Name: string; - Surname: string; - Type: TType; -} -``` - -**Type parameters** - -| Name | -| ----- | -| TType | - -**Properties** - -| Name | Type | -| ------- | ------ | -| Name | string | -| Surname | string | -| Type | TType | - ----------- - -### Boo - -```typescript -interface Boo { - Boos: string[]; -} -``` - -**Properties** - -| Name | Type | -| ---- | --------------------- | -| Boos | Array<string> | ---------- -### AnotherInterface - -```typescript -interface AnotherInterface { - (param1: TValue, param2: TValue): boolean; -} -``` - -#### Call - -```typescript -(param1: TValue, param2: TValue): boolean -``` - -**Type parameters** - -| Name | -| ------ | -| TValue | - -**Parameters** - -| Name | Type | -| ------ | ------ | -| param1 | TValue | -| param2 | TValue | - -**Return type** - -true | false - ----------- - -### MyConstraintType - -```typescript -interface MyConstraintType { - myProperty: string; -} -``` - -**Properties** - -| Name | Type | -| ---------- | ------ | -| myProperty | string | - ----------- - -### MyDefaultType - -```typescript -interface MyDefaultType extends MyConstraintType { - anotherProperty: number; -} -``` - -**Extends** - -[MyConstraintType][InterfaceDeclaration-4] - -**Properties** - -| Name | Type | -| --------------- | ------ | -| anotherProperty | number | - ----------- - -### ObjectsInterface - -```typescript -interface ObjectsInterface { - objectOne: Object; - objectTwo: Object; -} -``` - -**Properties** - -| Name | Type | -| --------- | ------ | -| objectOne | Object | -| objectTwo | Object | - ----------- - -### InterfaceWithCall - -```typescript -interface InterfaceWithCall { - (): { someProperty: T; }; -} -``` - -#### Call - -```typescript -(): { someProperty: T; } -``` - -**Type parameters** - -| Name | -| ---- | -| T | - -**Return type** - -{ someProperty: T; } - ----------- - -### InterfaceWithConstraintType - -```typescript -interface InterfaceWithConstraintType extends Dictionary { - someProperty: string; -} -``` - -**Extends** - -[Dictionary][InterfaceDeclaration-9]<string> - -**Properties** - -| Name | Type | -| ------------ | ------ | -| someProperty | string | - ----------- - -### InterfaceWithMethod - -```typescript -interface InterfaceWithMethod { - someMethodOne(): T; - someMethodTwo(): TReturn; -} -``` - -**Type parameters** - -| Name | -| ---- | -| T | - -#### Methods - -```typescript -someMethodOne(): T -``` - -**Return type** - -T - -```typescript -someMethodTwo(): TReturn -``` - -**Type parameters** - -| Name | -| ------- | -| TReturn | - -**Return type** - -TReturn - ----------- - -### Dictionary - -```typescript -interface Dictionary { - new (): Dictionary; - [key: string]: TValue; -} -``` - -**Type parameters** - -| Name | -| ------ | -| TValue | - -#### Construct - -```typescript -new (): Dictionary -``` - -**Return type** - -[Dictionary][InterfaceDeclaration-9]<TValue> - -#### Index signatures - -```typescript -[key: string]: TValue -``` - -* *Parameter* `key` - string -* *Type* TValue - ----------- - -### MethodsInterface - -```typescript -interface MethodsInterface { - (arg: TValue): void; - someMethod(): string; -} -``` - -#### Call - -```typescript -(arg: TValue): void -``` - -**Type parameters** - -| Name | -| ------ | -| TValue | - -**Parameters** - -| Name | Type | -| ---- | ------ | -| arg | TValue | - -**Return type** - -void - -#### Methods - -```typescript -someMethod(): string -``` - -**Type parameters** - -| Name | -| ---- | -| T | - -**Return type** - -string - ----------- - -### MonsterInterface - -Warning: Beta! - -Deprecated! - -Monster interface - -```typescript -interface MonsterInterface extends ObjectsInterface { - new (): MonsterInterface; - new (someParameter: string): string; - (): { someProperty: T; }; - (key?: string | undefined): { someProperty: T; }; - (key: number): { someProperty: T; }; - readonly [key: string]: TValue; - readonly objectOne: TValue; - objectTwo: TValue; -} -``` - -**Type parameters** - -| Name | Constraint type | Default type | -| ------ | --------------- | ------------ | -| TValue | Object | {} | - -**Extends** - -[ObjectsInterface][InterfaceDeclaration-6] - -#### Construct - -```typescript -new (): MonsterInterface -``` - -**Type parameters** - -| Name | -| ---- | -| T | - -**Return type** - -[MonsterInterface][InterfaceDeclaration-12]<T> - -```typescript -new (someParameter: string): string -``` - -**Parameters** - -| Name | Type | -| ------------- | ------ | -| someParameter | string | - -**Return type** - -string - -#### Call - -```typescript -(): { someProperty: T; } -``` - -**Type parameters** - -| Name | -| ---- | -| T | - -**Return type** - -{ someProperty: T; } - -```typescript -(key?: string | undefined): { someProperty: T; } -``` - -**Type parameters** - -| Name | -| ---- | -| T | - -**Parameters** - -| Name | Type | -| ---- | ----------------------- | -| key | undefined | string | - -**Return type** - -{ someProperty: T; } - -```typescript -(key: number): { someProperty: T; } -``` - -**Type parameters** - -| Name | -| ---- | -| T | - -**Parameters** - -| Name | Type | -| ---- | ------ | -| key | number | - -**Return type** - -{ someProperty: T; } - -#### Index signatures - -```typescript -readonly [key: string]: TValue -``` - -* *Parameter* `key` - string -* *Type* TValue - -**Properties** - -| Name | Type | -| --------- | ------ | -| objectOne | TValue | -| objectTwo | TValue | - ----------- - -### SomeInterface - -```typescript -interface SomeInterface { - [key: string]: string | number; - [key: number]: string; -} -``` - -#### Index signatures - -```typescript -[key: string]: string | number -``` - -* *Parameter* `key` - string -* *Type* string | number - -```typescript -[key: number]: string -``` - -* *Parameter* `key` - number -* *Type* string - ----------- - -### StringsDictionary - -```typescript -interface StringsDictionary { - [key: string]: string; -} -``` - -#### Index signatures - -```typescript -[key: string]: string -``` - -* *Parameter* `key` - string -* *Type* string - ----------- - -### MyInterface - -```typescript -interface MyInterface { - MyPropertyOne: string; - MyPropertyTwo: Object; - MyPropertyThree: number; -} -``` - -**Properties** - -| Name | Type | -| --------------- | ------ | -| MyPropertyOne | string | -| MyPropertyTwo | Object | -| MyPropertyThree | number | - ----------- - -### Props - -```typescript -interface Props { - name: string; -} -``` - -**Properties** - -| Name | Type | -| ---- | ------ | -| name | string | - -## Enums - -### Uogos - -Warning: Beta! - -Deprecated! - -Some information -2nd line of some information -3rd line of some information -4th line of some information -5th line of some information - -> Some summary about this package version. - - -```typescript -enum Uogos { - Jokie = "jokie", - Braskes = "braskes" -} -``` - -**Members** - -| Name | Value | -| ------- | --------- | -| Jokie | "jokie" | -| Braskes | "braskes" | - ----------- - -### ConstSkaiciai - - -```typescript -const enum ConstSkaiciai { - PirmasC = 0, - AntrasC = 1, - TreciasC = 2 -} -``` - -**Members** - -| Name | Value | -| -------- | ----- | -| PirmasC | 0 | -| AntrasC | 1 | -| TreciasC | 2 | - -## Classes +### [AnotherSimpleNamespace][ModuleDeclaration-1] -### [Hello][ClassDeclaration-0] +[SourceFile-0]: index.md#indexts +[ModuleDeclaration-0]: index/simplenamespace.md#simplenamespace +[ModuleDeclaration-1]: index/anothersimplenamespace.md#anothersimplenamespace \ No newline at end of file diff --git a/packages/ts-docs-gen/examples/simple/docs/api/index/anothersimplenamespace.md b/packages/ts-docs-gen/examples/simple/docs/api/index/anothersimplenamespace.md new file mode 100644 index 00000000..54a6dc0a --- /dev/null +++ b/packages/ts-docs-gen/examples/simple/docs/api/index/anothersimplenamespace.md @@ -0,0 +1,31 @@ +# Table of contents + +* [AnotherSimpleNamespace][ModuleDeclaration-1] + * Interfaces + * [SimpleInterface][InterfaceDeclaration-1] + +# AnotherSimpleNamespace + +## Interfaces + +### SimpleInterface + +```typescript +interface SimpleInterface extends SimpleInterface { + Property3: string; +} +``` + +**Extends** + +[SimpleInterface][InterfaceDeclaration-0] + +**Properties** + +| Name | Type | Optional | +| --------- | ------ | -------- | +| Property3 | string | false | + +[ModuleDeclaration-1]: anothersimplenamespace.md#anothersimplenamespace +[InterfaceDeclaration-1]: anothersimplenamespace.md#simpleinterface +[InterfaceDeclaration-0]: simplenamespace.md#simpleinterface \ No newline at end of file diff --git a/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace.md b/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace.md deleted file mode 100644 index c1c32a0e..00000000 --- a/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace.md +++ /dev/null @@ -1,7 +0,0 @@ -[ModuleDeclaration-1]: foonamespace/boonamespace.md#boonamespace -# FooNamespace - -## Namespaces - -### [BooNamespace][ModuleDeclaration-1] - diff --git a/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace/boonamespace.md b/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace/boonamespace.md deleted file mode 100644 index 3ea42f39..00000000 --- a/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace/boonamespace.md +++ /dev/null @@ -1,7 +0,0 @@ -[ModuleDeclaration-2]: boonamespace/boonamespace2.md#boonamespace2 -# BooNamespace - -## Namespaces - -### [BooNamespace2][ModuleDeclaration-2] - diff --git a/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace/boonamespace/boonamespace2.md b/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace/boonamespace/boonamespace2.md deleted file mode 100644 index a6a1066b..00000000 --- a/packages/ts-docs-gen/examples/simple/docs/api/index/foonamespace/boonamespace/boonamespace2.md +++ /dev/null @@ -1,14 +0,0 @@ -# BooNamespace2 - -## Variables - -### Hello - -```typescript -const Hello: "World!"; -``` - -**Type** - -"World!" - diff --git a/packages/ts-docs-gen/examples/simple/docs/api/index/hello.md b/packages/ts-docs-gen/examples/simple/docs/api/index/hello.md deleted file mode 100644 index a7c0022e..00000000 --- a/packages/ts-docs-gen/examples/simple/docs/api/index/hello.md +++ /dev/null @@ -1,49 +0,0 @@ -# Hello - -```typescript -class Hello -``` -## Constructor - -### constructor(arg) - -This is a constructor - -```typescript -public constructor(arg: string) -``` - -**Parameters** - -| Name | Type | Description | -| ---- | ------ | ---------------------- | -| arg | string | This is an argument ;) | - -## Methods - -### render(arg) - -Warning: Beta! - -Comment about Render - -```typescript -public render(arg: T): T -``` - -**Type parameters** - -| Name | Constraint type | Default type | -| ---- | --------------- | ------------ | -| T | String | String | - -**Parameters** - -| Name | Type | Description | -| ---- | ---- | ---------------------- | -| arg | T | Argument comment here. | - -**Return type** - -T - diff --git a/packages/ts-docs-gen/examples/simple/docs/api/index/simplenamespace.md b/packages/ts-docs-gen/examples/simple/docs/api/index/simplenamespace.md new file mode 100644 index 00000000..dca8bbc1 --- /dev/null +++ b/packages/ts-docs-gen/examples/simple/docs/api/index/simplenamespace.md @@ -0,0 +1,46 @@ +# Table of contents + +* [SimpleNamespace][ModuleDeclaration-0] + * Interfaces + * [SimpleInterface][InterfaceDeclaration-0] + * Variables + * [SimpleObject][VariableDeclaration-0] + +# SimpleNamespace + +General comment about SimpleNamespace. + +## Interfaces + +### SimpleInterface + +```typescript +interface SimpleInterface { + Property1: string; + Property2: string; +} +``` + +**Properties** + +| Name | Type | Optional | +| --------- | ------ | -------- | +| Property1 | string | false | +| Property2 | string | false | + +## Variables + +### SimpleObject + +```typescript +const SimpleObject: SimpleInterface; +``` + +**Type** + +[SimpleInterface][InterfaceDeclaration-1] + +[ModuleDeclaration-0]: simplenamespace.md#simplenamespace +[InterfaceDeclaration-0]: simplenamespace.md#simpleinterface +[VariableDeclaration-0]: simplenamespace.md#simpleobject +[InterfaceDeclaration-1]: anothersimplenamespace.md#simpleinterface \ No newline at end of file diff --git a/packages/ts-docs-gen/examples/simple/exported-const-variables.ts b/packages/ts-docs-gen/examples/simple/exported-const-variables.ts deleted file mode 100644 index 42aca37f..00000000 --- a/packages/ts-docs-gen/examples/simple/exported-const-variables.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * First const variable in the exported items. - */ -export const Kintamasis = "Hello World!"; -export const Kintamasis2 = "World, Hello!"; -export const Kintamasis3 = "Not imported!"; diff --git a/packages/ts-docs-gen/examples/simple/exported-functions.ts b/packages/ts-docs-gen/examples/simple/exported-functions.ts deleted file mode 100644 index 6d5cdcfa..00000000 --- a/packages/ts-docs-gen/examples/simple/exported-functions.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function Foo(): string { - return "foo"; -} - -export function Bar(): string { - return "bar"; -} diff --git a/packages/ts-docs-gen/examples/simple/index.ts b/packages/ts-docs-gen/examples/simple/index.ts index f3ac7c21..5b4d1ff4 100644 --- a/packages/ts-docs-gen/examples/simple/index.ts +++ b/packages/ts-docs-gen/examples/simple/index.ts @@ -1,324 +1,22 @@ -// tslint:disable - -export interface ExtendedBar extends Foo, Boo { - OtherStuff: string[]; -} - -export interface Foo { - Name: string; - Surname: string; - Type: TType; -} - -export interface Boo { - Boos: string[]; -} - -export interface AnotherInterface { - (param1: TValue, param2: TValue): boolean; -} - -export interface MyConstraintType { - myProperty: string; -} - -export interface MyDefaultType extends MyConstraintType { - anotherProperty: number; -} - -export interface ObjectsInterface { - objectOne: Object; - objectTwo: Object; -} - -export interface InterfaceWithCall { - (): { someProperty: T }; -} - -export interface InterfaceWithConstraintType extends Dictionary { - someProperty: string; -} - -export interface InterfaceWithMethod { - someMethodOne(): T; - someMethodTwo(): TReturn; -} - -export interface Dictionary { - new(): Dictionary; - [key: string]: TValue; -} - -export interface MethodsInterface { - someMethod(): string; - (arg: TValue): void; -} - -/** - * Monster interface - * @beta - * @deprecated - */ -export interface MonsterInterface extends ObjectsInterface { - new (): MonsterInterface; - new(someParameter: string): string; - - readonly [key: string]: TValue; - - (): { someProperty: T }; - (key?: string): { someProperty: T }; - (key: number): { someProperty: T }; - - readonly objectOne: TValue; - objectTwo: TValue; -} - -export interface SomeInterface { - [key: string]: string | number; - [key: number]: string; -} - -export interface StringsDictionary { - [key: string]: string; -} - -export interface MyInterface { - MyPropertyOne: string; - MyPropertyTwo: Object; - MyPropertyThree: number; -} - - -// import { Foo } from "./exported-functions"; - -// export class World { } -// export class Earth { } -// export class Earth { } - -// export declare const Hello: World & Earth; - -// export const FooFunc = Foo; - -//--------------------------------------------------------- - - -// #region Parameters - -// #endregion Parameters - -// export function Foo(): string { -// return "foo"; -// } - -// /** -// * Some general comment about Bar function. -// * -// * @beta Some comment on beta. -// * @deprecated -// */ -// export function Bar(parameter1: string, parameter2: number): string { -// return "bar"; -// } - -// #region Return types -// export function FunctionWithoutReturnType>(parameter1: string, parameter2: Promise) { -// return "bar"; -// } - -// export function FunctionWithGenericReturnType(): Array { -// return []; -// } - -// export function FunctionWithPrimitiveReturnType(): boolean { -// return true; -// } - -// export function FunctionWithUnionReturnType(): "something" | "nothing" { -// return "nothing"; -// } - -// export function FunctionWithIntersectionReturnType(): Earth & World { -// return {}; -// } -// #endregion Return types - -// ------------------------------------------------------ - -// export * from "./exported-functions"; -// export { Kintamasis as Pakeistas } from "./exported-const-variables"; -// export type A = number & { ok(): TValue }; - -// Two types have a one common field -// export type OneCommonField1 = { -// BarName: string; -// FooName: string; -// }; - -// export type OneCommonField2 = { -// BarName: string; -// BazName: string; -// }; - -// export type OneCommonFieldTypeIntersection = OneCommonField1 | OneCommonField2; - -// export interface MyConstraintType { -// myProperty: string; -// } -// export interface MyDefaultType extends MyConstraintType { -// anotherProperty: number; -// } - -// export function MyFunction(): T { -// return { -// myProperty: "sampleString" -// } as T; -// } - -// export interface MyInterface { -// (param1: TValue, param2: TValue): boolean; -// } - -// /** -// * Some JSdoc information. -// * 2nd line of some JSdoc information. -// * @summary Some summary about this package version. -// * @summary 2nd of some summary about this package version. -// */ -// export const itemsList: string[] = ["a"]; - -// export function Ok(isIt: boolean): boolean { -// return isIt; -// } - -// export function OkWithoutReturnType(isIt: boolean) { -// return isIt; -// } - -// export namespace SomeKindOfModule { -// export const name = "some-kind-of-module"; -// } - -/** - * Some information - * 2nd line of some information - * 3rd line of some information - * 4th line of some information - * 5th line of some information - * @summary Some summary about this package version. - * @summary 2nd of some summary about this package version. - * @deprecated - * @beta - */ -export enum Uogos { - Jokie = "jokie", - Braskes = "braskes" -} - -// export enum Skaiciai { -// Nulis = 0, -// Vienas = 1, -// Du = 2 -// } - -// export enum Sarasas { -// /** -// * Pirmo description'as -// */ -// Pirmas, -// /** -// * Antro description'as -// */ -// Antras, -// /** -// * Trečio description'as -// */ -// Trecias -// } - -export const enum ConstSkaiciai { - PirmasC = 0, - AntrasC = 1, - TreciasC = 2 -} - -// export const enum ConstSarasas { -// /** -// * Pirmo description'as -// */ -// PirmasC, -// /** -// * Antro description'as -// */ -// AntrasC, -// /** -// * Trečio description'as -// */ -// TreciasC -// } - -// export interface Boo { -// Boos: string[]; -// } - -// export interface Foo { -// Name: string; -// Surname: string; -// Type: TType; -// } - -// export interface Bar extends Foo, Boo { -// OtherStuff: string[]; -// } - -// export interface A { -// (aa: boolean): string; -// } - -// export abstract class Foo { -// public Name: string; - -// private somePrivateProperty: any; - -// public GetName(ok: string): string; -// public GetName(ok: string, ok2?: string): string { -// return this.Name; -// } - -// public abstract Bar(): string; -// } - -// /** -// * @deprecated Use uogos instead ;) -// */ -// export type Hello = Uogos; - -export interface Props { - name: string; -} - -export function Component(arg: T): void { } - -export class Hello { - /** - * This is a constructor - * @param arg This is an argument ;) - */ - constructor(arg: string) { } - - /** - * Comment about Render - * @beta - * @param arg Argument comment here. - */ - public render(arg: T): T { - return arg; - } - - // get Foo(): string { - // throw new Error("Method not implemented."); - // } - - // set Foo(arg: string) { } - - // public static set Bar(arg: string) { } -} +/** + * General comment about SimpleNamespace. + */ +export namespace SimpleNamespace { + export interface SimpleInterface { + Property1: string; + Property2: string; + } + + // TODO: Append used references in ApiVariablePlugin with type reference. + export const SimpleObject: AnotherSimpleNamespace.SimpleInterface = { + Property1: "1", + Property2: "2", + Property3: "3" + }; +} + +export namespace AnotherSimpleNamespace { + export interface SimpleInterface extends SimpleNamespace.SimpleInterface { + Property3: string; + } +} diff --git a/packages/ts-docs-gen/examples/simple/my-types.ts b/packages/ts-docs-gen/examples/simple/my-types.ts deleted file mode 100644 index 8295ca0d..00000000 --- a/packages/ts-docs-gen/examples/simple/my-types.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface MyInterface { - foo: string; -} \ No newline at end of file diff --git a/packages/ts-docs-gen/package.json b/packages/ts-docs-gen/package.json index 17b691b8..33709273 100644 --- a/packages/ts-docs-gen/package.json +++ b/packages/ts-docs-gen/package.json @@ -2,7 +2,8 @@ "name": "ts-docs-gen", "version": "0.1.0", "description": "Generating documentation for TypeScript code", - "main": "index.js", + "main": "./dist/index.js", + "typings": "./dist/index.d.ts", "scripts": { "pretest": "npm run build -- --noEmit && npm run build-tests", "test": "npm run tslint && jest && echo All tests passed successfully.", @@ -10,28 +11,31 @@ "test-watch": "start npm run build-tests -- --watchAll && jest --watchAll", "tslint": "tslint --project . --config ./tslint.json && echo Successfully passed tslint test.", "build": "tsc -p .", - "build-tests": "node ../../tools/test-generator-cli/dist/index.js" + "build-tests": "test-generator-cli" }, "engine": "node >= 7.5.0", "author": "simplrjs (https://github.com/simplrjs)", "dependencies": { - "@simplrjs/markdown": "^1.0.7", + "@simplrjs/markdown": "^1.1.0", "@types/fs-extra": "^5.0.0", - "fast-glob": "^1.0.1", + "@types/yargs": "^10.0.1", "fs-extra": "^5.0.0", "simplr-logger": "^1.0.1", - "ts-extractor": "^3.1.1", - "typescript": "^2.6.2" + "ts-extractor": "^4.0.0-rc.1", + "typescript": "^2.6.2", + "yargs": "^11.0.0" }, "devDependencies": { - "@types/jest": "^22.0.0", - "@types/sinon": "^4.1.2", - "jest": "^22.0.4", + "@simplrjs/test-generator-cli": "^0.1.3", + "@types/jest": "^22.1.1", + "@types/sinon": "^4.1.3", + "jest": "^22.1.4", "simplr-tslint": "0.0.1", - "sinon": "^4.1.3", - "ts-jest": "^22.0.0", - "tslint": "^5.8.0" + "sinon": "^4.2.2", + "ts-jest": "^22.0.2", + "tslint": "^5.9.1" }, + "bin": "./dist/cli/launcher.js", "jest": { "collectCoverage": true, "mapCoverage": true, diff --git a/packages/ts-docs-gen/src/abstractions/base-api-item.ts b/packages/ts-docs-gen/src/abstractions/base-api-item.ts new file mode 100644 index 00000000..f53eef99 --- /dev/null +++ b/packages/ts-docs-gen/src/abstractions/base-api-item.ts @@ -0,0 +1,24 @@ +import { ExtractDto } from "ts-extractor"; +import { SerializedApiItem, ReferenceRenderHandler } from "../contracts/serialized-api-item"; + +export abstract class BaseApiItemClass implements SerializedApiItem { + constructor(private extractedData: ExtractDto, private apiItem: TKind) { } + + protected get ExtractedData(): ExtractDto { + return this.extractedData; + } + + public get ApiItem(): TKind { + return this.apiItem; + } + + protected DefaultReferenceRenderer: ReferenceRenderHandler = name => name; + + public abstract ToText(render?: ReferenceRenderHandler): string[]; + + public ToInlineText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string { + return this.ToText(render) + .map(x => x.trim()) + .join(" "); + } +} diff --git a/packages/ts-docs-gen/src/abstractions/base-plugin.ts b/packages/ts-docs-gen/src/abstractions/base-plugin.ts index bbfaebb8..a8ed9d60 100644 --- a/packages/ts-docs-gen/src/abstractions/base-plugin.ts +++ b/packages/ts-docs-gen/src/abstractions/base-plugin.ts @@ -1,52 +1,102 @@ -import { Contracts } from "ts-extractor"; -import { MarkdownBuilder } from "@simplrjs/markdown"; +import { Contracts, ExtractDto } from "ts-extractor"; +import { MarkdownBuilder, MarkdownGenerator } from "@simplrjs/markdown"; import { Plugin, SupportedApiItemKindType, PluginOptions, PluginResult, PluginResultData } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; +import { ApiTypeParameter } from "../api-items/definitions/api-type-parameter"; +import { ApiTypes } from "../api-items/api-type-list"; +import { ReferenceRenderHandler } from "../contracts/serialized-api-item"; -export abstract class BasePlugin implements Plugin { - public abstract SupportedApiItemKinds(): SupportedApiItemKindType[]; +export abstract class BasePlugin implements Plugin { + /** + * Used to identify class as Plugin. + */ + // tslint:disable-next-line:no-empty + public static TsDocsGenPlugin(): void { } + + public abstract SupportedApiDefinitionKind(): SupportedApiItemKindType[]; public CheckApiItem(item: TKind): boolean { return true; } - // TODO: Escape string! - protected RenderTypeParameters(typeParameters: Contracts.ApiTypeParameterDto[]): PluginResultData | undefined { + protected RenderApiItemMetadata(apiItem: Contracts.ApiDefinition): string[] { + const builder = new MarkdownBuilder(); + + // Optimise? + const beta = apiItem.Metadata.JSDocTags.find(x => x.name.toLowerCase() === GeneratorHelpers.JSDocTags.Deprecated); + const deprecated = apiItem.Metadata.JSDocTags.find(x => x.name.toLowerCase() === GeneratorHelpers.JSDocTags.Deprecated); + const internal = apiItem.Metadata.JSDocTags.find(x => x.name.toLowerCase() === GeneratorHelpers.JSDocTags.Internal); + const summary = apiItem.Metadata.JSDocTags.find(x => x.name.toLowerCase() === GeneratorHelpers.JSDocTags.Summary); + const jSDocComment = apiItem.Metadata.DocumentationComment; + + if (beta != null) { + const message = Boolean(beta.text) ? `: ${beta.text}` : ""; + builder + .Bold(`Warning Beta${message}!`) + .EmptyLine(); + } + + if (deprecated != null) { + const message = Boolean(deprecated.text) ? `: ${deprecated.text}` : ""; + builder + .Text(`Deprecated${message}!`) + .EmptyLine(); + } + + if (internal != null) { + const message = Boolean(internal.text) ? `: ${internal.text}` : ""; + builder + .Bold(`Internal${message}!`) + .EmptyLine(); + } + + if (jSDocComment.length > 0) { + builder + .Text(jSDocComment) + .EmptyLine(); + } + + if (summary != null && Boolean(summary.text)) { + builder + .Blockquote(summary.text!.split("\n")) + .EmptyLine(); + } + + return builder.GetOutput(); + } + + protected RenderTypeParameters(extractedData: ExtractDto, typeParameters: ApiTypeParameter[]): PluginResultData | undefined { if (typeParameters.length === 0) { return undefined; } const pluginResult = GeneratorHelpers.GetDefaultPluginResultData(); - const header = ["Name", "Constraint type", "Default type"]; + const header = ["Name", "Constraint", "Default"]; const content = typeParameters.map(typeParameter => { // ConstraintType - let constraintType: GeneratorHelpers.TypeToStringDto; + let constraintType: string; if (typeParameter.ConstraintType != null) { - constraintType = GeneratorHelpers.TypeDtoToMarkdownString(typeParameter.ConstraintType); - GeneratorHelpers.MergePluginResultData(pluginResult, { - UsedReferences: constraintType.References - }); + constraintType = typeParameter.ConstraintType + .ToInlineText(this.RenderReferences(extractedData, pluginResult.UsedReferences)); } else { - constraintType = { References: [], Text: "" }; + constraintType = ""; } // DefaultType - let defaultType: GeneratorHelpers.TypeToStringDto; + let defaultType: string; if (typeParameter.DefaultType != null) { - defaultType = GeneratorHelpers.TypeDtoToMarkdownString(typeParameter.DefaultType); - GeneratorHelpers.MergePluginResultData(pluginResult, { - UsedReferences: defaultType.References - }); + defaultType = typeParameter.DefaultType + .ToInlineText(this.RenderReferences(extractedData, pluginResult.UsedReferences)); } else { - defaultType = { References: [], Text: "" }; + defaultType = ""; } return [ typeParameter.Name, - constraintType.Text, - defaultType.Text + constraintType, + defaultType ]; }); @@ -60,24 +110,43 @@ export abstract class BasePlugin implements Plugin return pluginResult; } - protected RenderType(type?: Contracts.TypeDto): PluginResultData | undefined { + protected RenderType(extractedData: ExtractDto, type: ApiTypes | undefined): PluginResultData | undefined { if (type == null) { return undefined; } - const pluginResult = GeneratorHelpers.GetDefaultPluginResultData(); - const parsedReturnType = GeneratorHelpers.TypeDtoToMarkdownString(type); + const pluginResult = GeneratorHelpers.GetDefaultPluginResultData(); + const parsedReturnType = type.ToInlineText(this.RenderReferences(extractedData, pluginResult.UsedReferences)); pluginResult.Result = new MarkdownBuilder() .EmptyLine() .Bold("Type") .EmptyLine() - .Text(parsedReturnType.Text) + .Text(parsedReturnType) .GetOutput(); - pluginResult.UsedReferences = parsedReturnType.References; return pluginResult; } - public abstract Render(data: PluginOptions): PluginResult; + /** + * Default reference rending with markdown links. + * @param usedReferences populates given array with used references. + */ + protected RenderReferences(extractedData: ExtractDto, usedReferences: string[]): ReferenceRenderHandler { + return (name, reference) => { + if (reference == null) { + return name; + } + const apiItem = extractedData.Registry[reference]; + if (apiItem.ApiKind === Contracts.ApiDefinitionKind.TypeParameter) { + return name; + } + + usedReferences.push(reference); + + return MarkdownGenerator.Link(name, reference, true); + }; + } + + public abstract Render(options: PluginOptions, apiItem: TKind): PluginResult; } diff --git a/packages/ts-docs-gen/src/abstractions/container-plugin.ts b/packages/ts-docs-gen/src/abstractions/container-plugin.ts index b4efafab..d328c74d 100644 --- a/packages/ts-docs-gen/src/abstractions/container-plugin.ts +++ b/packages/ts-docs-gen/src/abstractions/container-plugin.ts @@ -1,93 +1,106 @@ -import { Contracts, ExtractDto } from "ts-extractor"; -import { MarkdownBuilder } from "@simplrjs/markdown"; +import { Contracts } from "ts-extractor"; +import { MarkdownBuilder, MarkdownGenerator } from "@simplrjs/markdown"; + import { BasePlugin } from "./base-plugin"; -import { PluginOptions, PluginResultData } from "../contracts/plugin"; +import { PluginResultData, PluginOptions, SupportedApiItemKindType } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; -import { ApiItemReference } from "../contracts/api-item-reference"; +import { ApiDefinitions } from "../api-items/api-definition-list"; -export interface ApiContainer extends Contracts.ApiBaseItemDto { +export interface ApiContainer extends Contracts.ApiBaseDefinition { Members: Contracts.ApiItemReference[]; } export interface ContainerMembersKindsGroup { Heading: string; - Kinds: Contracts.ApiItemKinds[]; + Kinds: SupportedApiItemKindType[]; +} + +export interface RenderMemberGroupsOptions { + IncludeHr: boolean; + StartingHeadingLevel: number; } -interface ContainerMembersReferencesGroup { +interface ContainerMembersGroup { Heading: string; - References: ApiItemReference[]; + MembersList: ApiDefinitions[]; } export abstract class ContainerPlugin extends BasePlugin { private getItemsReferenceByKind( list: ContainerMembersKindsGroup[], - members: Contracts.ApiItemReference[], - extractedData: ExtractDto - ): ContainerMembersReferencesGroup[] { - const result: ContainerMembersReferencesGroup[] = []; - let membersReferences = GeneratorHelpers.GetApiItemReferences(extractedData, members); + members: ApiDefinitions[] + ): ContainerMembersGroup[] { + const result: ContainerMembersGroup[] = []; + let membersList = [...members]; for (const item of list) { // Filter item references by kind - const apiItemsReferenceByKind = membersReferences.filter(x => item.Kinds.indexOf(extractedData.Registry[x.Id].ApiKind) !== -1); + const serializedApiItems = membersList + .filter(x => item.Kinds.indexOf(x.ApiItem.ApiKind) !== -1 || + item.Kinds.indexOf(GeneratorHelpers.ApiDefinitionKind.Any) !== -1); // Remove references that was used - membersReferences = membersReferences.filter(x => apiItemsReferenceByKind.indexOf(x) === -1); + membersList = membersList.filter(x => serializedApiItems.indexOf(x) === -1); result.push({ Heading: item.Heading, - References: apiItemsReferenceByKind - }); - } - - // TODO: Using ApiKind.Any to add everything to other if some kind is not supported. - if (membersReferences.length !== 0) { - result.push({ - Heading: "Other", - References: membersReferences + MembersList: serializedApiItems }); } return result; } - protected RenderMembersGroups(list: ContainerMembersKindsGroup[], options: PluginOptions): PluginResultData { - const membersReferences = this.getItemsReferenceByKind(list, options.ApiItem.Members, options.ExtractedData); + protected RenderMemberGroups( + pluginOptions: PluginOptions, + list: ContainerMembersKindsGroup[], + members: ApiDefinitions[], + options?: Partial + ): PluginResultData { + const resolvedOptions: RenderMemberGroupsOptions = { + IncludeHr: true, + StartingHeadingLevel: 2, + ...options + }; + + const memberGroups = this.getItemsReferenceByKind(list, members); const pluginResultData = GeneratorHelpers.GetDefaultPluginResultData(); const builder = new MarkdownBuilder(); - for (const { Heading, References } of membersReferences) { - if (References.length > 0) { + for (const { Heading, MembersList } of memberGroups) { + if (MembersList.length > 0) { builder - .Header(Heading, 2) + .Header(Heading, resolvedOptions.StartingHeadingLevel) .EmptyLine(); - for (const reference of References) { - const apiItem = options.ExtractedData.Registry[reference.Id]; + for (const member of MembersList) { + if (pluginOptions.IsPluginResultExists(member.Reference)) { + const headingLink = MarkdownGenerator.Link(member.ToHeadingText(), member.Reference.Id, true); - if (options.IsPluginResultExists(reference)) { builder - .Text(md => md.Header(md.Link(apiItem.Name, reference.Id, true), 3)) + .Text(md => md.Header(headingLink, resolvedOptions.StartingHeadingLevel + 1)) .EmptyLine(); - pluginResultData.UsedReferences.push(reference.Id); } else { - switch (apiItem.ApiKind) { - case Contracts.ApiItemKinds.Namespace: - case Contracts.ApiItemKinds.Class: { - const renderedItem = options.GetItemPluginResult(reference); + switch (member.ApiItem.ApiKind) { + case Contracts.ApiDefinitionKind.Namespace: + case Contracts.ApiDefinitionKind.ImportNamespace: + case Contracts.ApiDefinitionKind.Class: { + const renderedItem = pluginOptions.GetItemPluginResult(member.Reference); pluginResultData.Members.push({ - Reference: reference, + Reference: member.Reference, PluginResult: renderedItem }); + const headingLink = MarkdownGenerator.Link(member.ToHeadingText(), member.Reference.Id, true); builder - .Text(md => md.Header(md.Link(renderedItem.ApiItem.Name, reference.Id, true), 3)) + .Text(md => md.Header(headingLink, resolvedOptions.StartingHeadingLevel + 1)) + .EmptyLine() + .Text(this.RenderApiItemMetadata(renderedItem.ApiItem)) .EmptyLine(); - pluginResultData.UsedReferences.push(reference.Id); + pluginResultData.UsedReferences.push(member.Reference.Id); break; } default: { - const renderedItem = options.GetItemPluginResult(reference); + const renderedItem = pluginOptions.GetItemPluginResult(member.Reference); builder .Text(renderedItem.Result) .EmptyLine(); @@ -100,7 +113,7 @@ export abstract class ContainerPlugin extends BasePl } } - if ((References.indexOf(reference) + 1) !== References.length) { + if ((MembersList.indexOf(member) + 1) !== MembersList.length && resolvedOptions.IncludeHr) { builder .HorizontalRule(undefined, 10) .EmptyLine(); diff --git a/packages/ts-docs-gen/src/abstractions/function-like-plugin.ts b/packages/ts-docs-gen/src/abstractions/function-like-plugin.ts index 0266acee..1574b9c3 100644 --- a/packages/ts-docs-gen/src/abstractions/function-like-plugin.ts +++ b/packages/ts-docs-gen/src/abstractions/function-like-plugin.ts @@ -1,27 +1,32 @@ -import { Contracts } from "ts-extractor"; -import { MarkdownGenerator, MarkdownBuilder } from "@simplrjs/markdown"; +import { Contracts, ExtractDto } from "ts-extractor"; +import { MarkdownBuilder } from "@simplrjs/markdown"; import { BasePlugin } from "./base-plugin"; import { PluginResultData } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; +import { ApiTypes } from "../api-items/api-type-list"; +import { ApiParameter } from "../api-items/definitions/api-parameter"; -export abstract class FunctionLikePlugin extends BasePlugin { - // TODO: Escape string! - protected RenderParameters(parameters: Contracts.ApiParameterDto[]): PluginResultData | undefined { +export abstract class FunctionLikePlugin extends BasePlugin { + protected RenderParameters(extractedData: ExtractDto, parameters: ApiParameter[]): PluginResultData | undefined { if (parameters.length === 0) { return undefined; } const pluginResult = GeneratorHelpers.GetDefaultPluginResultData(); - const header = ["Name", "Type", "Description"]; + const header = ["Name", "Type", "Default value", "Description"]; const content = parameters.map(parameter => { - const parameterTypeDto = GeneratorHelpers.TypeDtoToMarkdownString(parameter.Type); - GeneratorHelpers.MergePluginResultData(pluginResult, { - UsedReferences: parameterTypeDto.References - }); - - return [parameter.Name, MarkdownGenerator.EscapeString(parameterTypeDto.Text), parameter.Metadata.DocumentationComment]; + const type = parameter.Type + .ToInlineText(this.RenderReferences(extractedData, pluginResult.UsedReferences)); + + // TODO: Add Resolving simple metadata. + return [ + parameter.Name, + type, + parameter.ApiItem.Initializer || "", + parameter.ApiItem.Metadata.DocumentationComment + ]; }); pluginResult.Result = new MarkdownBuilder() @@ -34,22 +39,19 @@ export abstract class FunctionLikePlugin extends B return pluginResult; } - protected RenderReturnType(type?: Contracts.TypeDto): PluginResultData | undefined { + protected RenderReturnType(extractedData: ExtractDto, type: ApiTypes | undefined): PluginResultData | undefined { if (type == null) { return undefined; } const pluginResult = GeneratorHelpers.GetDefaultPluginResultData(); - const parsedReturnType = GeneratorHelpers.TypeDtoToMarkdownString(type); - pluginResult.Result = new MarkdownBuilder() .EmptyLine() .Bold("Return type") .EmptyLine() - .Text(parsedReturnType.Text) + .Text(type.ToInlineText(this.RenderReferences(extractedData, pluginResult.UsedReferences))) .GetOutput(); - pluginResult.UsedReferences = parsedReturnType.References; return pluginResult; } } diff --git a/packages/ts-docs-gen/src/api-items/api-callable.ts b/packages/ts-docs-gen/src/api-items/api-callable.ts new file mode 100644 index 00000000..0179e4a9 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-callable.ts @@ -0,0 +1,86 @@ +import { Contracts } from "ts-extractor"; + +import { GeneratorHelpers } from "../generator-helpers"; +import { ApiTypeParameter } from "./definitions/api-type-parameter"; +import { ApiParameter } from "./definitions/api-parameter"; +import { ApiDefinitionBase } from "./api-definition-base"; +import { ApiTypes } from "./api-type-list"; +import { ReferenceRenderHandler } from "../contracts/serialized-api-item"; + +/** + * Base class for callable api items. + */ +export abstract class ApiCallable extends ApiDefinitionBase { + private parameters: ApiParameter[]; + + public get Parameters(): ApiParameter[] { + if (this.parameters == null) { + this.parameters = GeneratorHelpers + .GetApiItemReferences(this.ExtractedData, this.ApiItem.Parameters) + .map(x => this.GetSerializedApiDefinition(x)) + .filter((x): x is ApiParameter => x != null); + } + return this.parameters; + } + + private typeParameters: ApiTypeParameter[]; + + public get TypeParameters(): ApiTypeParameter[] { + if (this.typeParameters == null) { + this.typeParameters = GeneratorHelpers + .GetApiItemReferences(this.ExtractedData, this.ApiItem.TypeParameters) + .map(x => this.GetSerializedApiDefinition(x) as ApiTypeParameter); + } + + return this.typeParameters; + } + + private returnType: ApiTypes | undefined; + + public get ReturnType(): ApiTypes | undefined { + if (this.returnType == null && this.ApiItem.ReturnType != null) { + return GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.ReturnType); + } + + return this.returnType; + } + + protected TypeParametersToString(render: ReferenceRenderHandler): string { + return super.TypeParametersToString(render, this.TypeParameters); + } + + protected ParametersToString(render: ReferenceRenderHandler): string { + return this.Parameters + .map(x => x.ToText()) + .join(", "); + } + + /** + * Example: `(arg: TValue): void` + * @param typeDefChar If empty string, return type is not shown. @default ": " + */ + protected CallableToString(render: ReferenceRenderHandler, typeDefChar: string = ": "): string { + // TypeParameters + const typeParametersString = this.TypeParametersToString(render); + + // Parameters + const parametersString = this.ParametersToString(render); + + // ReturnType + let returnTypeString: string; + if (typeDefChar !== "" && this.ReturnType != null) { + const type = this.SerializedTypeToString(render, this.ReturnType); + returnTypeString = `${typeDefChar}${type}`; + } else { + returnTypeString = ""; + } + + return `${typeParametersString}(${parametersString})${returnTypeString}`; + } + + protected CallableToSimpleString(): string { + const parameters = this.Parameters.map(x => x.Name); + + return `(${parameters.join(", ")})`; + } +} diff --git a/packages/ts-docs-gen/src/api-items/api-definition-base.ts b/packages/ts-docs-gen/src/api-items/api-definition-base.ts new file mode 100644 index 00000000..36b05e99 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-definition-base.ts @@ -0,0 +1,68 @@ +import { Contracts, ExtractDto } from "ts-extractor"; +import { LogLevel } from "simplr-logger"; + +import { BaseApiItemClass } from "../abstractions/base-api-item"; +import { GeneratorHelpers } from "../generator-helpers"; +import { SerializedApiDefinition, ReferenceRenderHandler } from "../contracts/serialized-api-item"; +import { ApiItemReference } from "../contracts/api-item-reference"; +import { ApiDefinitions } from "./api-definition-list"; +import { ApiTypes } from "./api-type-list"; + +/** + * Base definition class with helper functions. + */ +export abstract class ApiDefinitionBase + extends BaseApiItemClass implements SerializedApiDefinition { + + constructor(extractedData: ExtractDto, apiItem: TKind, private reference: ApiItemReference) { + super(extractedData, apiItem); + } + + public get Name(): string { + return this.Reference.Alias || this.ApiItem.Name; + } + + public get Reference(): ApiItemReference { + return this.reference; + } + + private parentItem: ApiDefinitions | undefined; + + public get ParentItem(): ApiDefinitions | undefined { + if (this.ApiItem.ParentId != null) { + const parentReference = { Alias: "", Id: this.ApiItem.ParentId }; + this.parentItem = this.GetSerializedApiDefinition(parentReference); + } + + return this.parentItem; + } + + protected GetSerializedApiDefinition(reference: ApiItemReference): ApiDefinitions | undefined { + const apiItem = this.ExtractedData.Registry[reference.Id]; + return GeneratorHelpers.SerializeApiDefinition(this.ExtractedData, apiItem, reference); + } + + protected TypeParametersToString(render: ReferenceRenderHandler, apiTypeParameters: ApiDefinitionBase[]): string { + if (apiTypeParameters.length === 0) { + return ""; + } + + const members = apiTypeParameters + .map(x => x.ToInlineText(render)) + .join(", "); + + return `<${members}>`; + } + + protected SerializedTypeToString(render: ReferenceRenderHandler, apiType: ApiTypes | undefined): string { + if (apiType == null) { + GeneratorHelpers.LogWithApiItemPosition(LogLevel.Warning, this.ApiItem, "Missing type."); + return Contracts.TypeKeywords.Unknown; + } + + return apiType.ToInlineText(render); + } + + public abstract ToText(render?: ReferenceRenderHandler): string[]; + public abstract ToHeadingText(): string; +} diff --git a/packages/ts-docs-gen/src/api-items/api-definition-container.ts b/packages/ts-docs-gen/src/api-items/api-definition-container.ts new file mode 100644 index 00000000..83a17b25 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-definition-container.ts @@ -0,0 +1,31 @@ +import { Contracts } from "ts-extractor"; +import { ApiDefinitionBase } from "./api-definition-base"; +import { ApiDefinitions } from "./api-definition-list"; +import { GeneratorHelpers } from "../generator-helpers"; +import { ApiItemReference } from "../contracts/api-item-reference"; +import { ReferenceRenderHandler } from "../contracts/serialized-api-item"; +import { Helpers } from "../utils/helpers"; + +export type ApiBaseItemContainerDto = Contracts.ApiBaseDefinition & { Members: Contracts.ApiItemReference[] }; + +export abstract class ApiDefinitionContainer + extends ApiDefinitionBase { + + private members: ApiDefinitions[]; + + public get Members(): ApiDefinitions[] { + if (this.members == null) { + this.members = GeneratorHelpers + .GetApiItemReferences(this.ExtractedData, this.ApiItem.Members) + .map<[ApiItemReference, Contracts.ApiDefinition]>(x => [x, this.ExtractedData.Registry[x.Id]]) + .map(([reference, apiItem]) => GeneratorHelpers.SerializeApiDefinition(this.ExtractedData, apiItem, reference)); + } + return this.members; + } + + protected MembersToText(render: ReferenceRenderHandler, members: ApiDefinitions[], tab: number = 0): string[] { + return Helpers.Flatten( + members.map(x => x.ToText(render).map(y => `${GeneratorHelpers.Tab(tab)}${y}`)) + ); + } +} diff --git a/packages/ts-docs-gen/src/api-items/api-definition-default.ts b/packages/ts-docs-gen/src/api-items/api-definition-default.ts new file mode 100644 index 00000000..0836e7bb --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-definition-default.ts @@ -0,0 +1,51 @@ +import { Contracts, ExtractDto } from "ts-extractor"; +import { ReferenceRenderHandler, SerializedApiDefinition } from "../contracts/serialized-api-item"; +import { BaseApiItemClass } from "../abstractions/base-api-item"; +import { ApiItemReference } from "../contracts/api-item-reference"; +import { GeneratorHelpers } from "../generator-helpers"; + +// Because of circular dependency we had to implement interface and not extend ApiDefinitionBase. +export class ApiDefinitionDefault + extends BaseApiItemClass implements SerializedApiDefinition { + + constructor(extractedData: ExtractDto, apiItem: TKind, private reference: ApiItemReference) { + super(extractedData, apiItem); + } + + public get ParentItem(): SerializedApiDefinition | undefined { + if (this.ApiItem.ParentId == null) { + return undefined; + } + + const apiItem = this.ExtractedData.Registry[this.ApiItem.ParentId]; + return GeneratorHelpers.SerializeApiDefinition( + this.ExtractedData, + this.ApiItem, + { + Alias: apiItem.Name, + Id: this.ApiItem.ParentId + } + ) as SerializedApiDefinition; + } + + public get Reference(): ApiItemReference { + return this.reference; + } + + public get Name(): string { + return this.ApiItem.Name; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [this.Name]; + } + + public ToInlineText(render?: ReferenceRenderHandler | undefined): string { + return this.ToText().join(" "); + } + + public ToHeadingText(): string { + const name = this.Name; + return `${this.ApiItem.ApiKind}: ${name}`; + } +} diff --git a/packages/ts-docs-gen/src/api-items/api-definition-list.ts b/packages/ts-docs-gen/src/api-items/api-definition-list.ts new file mode 100644 index 00000000..58cab711 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-definition-list.ts @@ -0,0 +1,113 @@ +import { Contracts } from "ts-extractor"; +import { SerializedApiDefinitionConstructor } from "../contracts/serialized-api-item"; + +import { ApiDefinitionDefault } from "./api-definition-default"; +// ApiItems +import { ApiSourceFile } from "./definitions/api-source-file"; +import { ApiCall } from "./definitions/api-call"; +import { ApiClass } from "./definitions/api-class"; +import { ApiConstruct } from "./definitions/api-construct"; +import { ApiEnum } from "./definitions/api-enum"; +import { ApiEnumMember } from "./definitions/api-enum-member"; +import { ApiFunction } from "./definitions/api-function"; +import { ApiFunctionExpression } from "./definitions/api-function-expression"; +import { ApiIndex } from "./definitions/api-index"; +import { ApiInterface } from "./definitions/api-interface"; +import { ApiMapped } from "./definitions/api-mapped"; +import { ApiMethod } from "./definitions/api-method"; +import { ApiNamespace } from "./definitions/api-namespace"; +import { ApiParameter } from "./definitions/api-parameter"; +import { ApiProperty } from "./definitions/api-property"; +import { ApiTypeAlias } from "./definitions/api-type-alias"; +import { ApiTypeParameter } from "./definitions/api-type-parameter"; +import { ApiVariable } from "./definitions/api-variable"; +import { ApiTypeLiteral } from "./definitions/api-type-literal"; +import { ApiClassConstructor } from "./definitions/api-class-constructor"; +import { ApiClassProperty } from "./definitions/api-class-property"; +import { ApiClassMethod } from "./definitions/api-class-method"; +import { ApiAccessor } from "./definitions/api-accessor"; + +export { + ApiSourceFile, + ApiCall, + ApiClass, + ApiConstruct, + ApiEnum, + ApiEnumMember, + ApiFunction, + ApiFunctionExpression, + ApiIndex, + ApiInterface, + ApiMapped, + ApiMethod, + ApiNamespace, + ApiParameter, + ApiProperty, + ApiTypeAlias, + ApiTypeParameter, + ApiVariable, + ApiTypeLiteral, + ApiClassConstructor, + ApiClassProperty, + ApiClassMethod, + ApiAccessor +}; + +export type ApiDefinitions = ApiDefinitionDefault | + ApiSourceFile | + ApiEnum | + ApiEnumMember | + ApiFunction | + ApiInterface | + ApiMethod | + ApiNamespace | + ApiParameter | + ApiProperty | + ApiVariable | + ApiTypeAlias | + ApiClass | + ApiClassConstructor | + ApiClassProperty | + ApiClassMethod | + ApiAccessor | + ApiAccessor | + ApiIndex | + ApiCall | + ApiConstruct | + ApiTypeParameter | + ApiTypeLiteral | + ApiFunctionExpression | + ApiMapped; + +// TODO: Fix any. +export const ApiDefinitionList: Array<[Contracts.ApiDefinitionKind, SerializedApiDefinitionConstructor]> = [ + [Contracts.ApiDefinitionKind.SourceFile, ApiSourceFile], + [Contracts.ApiDefinitionKind.Enum, ApiEnum], + [Contracts.ApiDefinitionKind.EnumMember, ApiEnumMember], + [Contracts.ApiDefinitionKind.Function, ApiFunction], + [Contracts.ApiDefinitionKind.Interface, ApiInterface], + [Contracts.ApiDefinitionKind.Method, ApiMethod], + [Contracts.ApiDefinitionKind.Namespace, ApiNamespace], + [Contracts.ApiDefinitionKind.ImportNamespace, ApiNamespace], + [Contracts.ApiDefinitionKind.Parameter, ApiParameter], + [Contracts.ApiDefinitionKind.Property, ApiProperty], + [Contracts.ApiDefinitionKind.Variable, ApiVariable], + [Contracts.ApiDefinitionKind.TypeAlias, ApiTypeAlias], + [Contracts.ApiDefinitionKind.Class, ApiClass], + [Contracts.ApiDefinitionKind.ClassConstructor, ApiClassConstructor], + [Contracts.ApiDefinitionKind.ClassProperty, ApiClassProperty], + [Contracts.ApiDefinitionKind.ClassMethod, ApiClassMethod], + [Contracts.ApiDefinitionKind.GetAccessor, ApiAccessor], + [Contracts.ApiDefinitionKind.SetAccessor, ApiAccessor], + [Contracts.ApiDefinitionKind.Index, ApiIndex], + [Contracts.ApiDefinitionKind.Call, ApiCall], + [Contracts.ApiDefinitionKind.Construct, ApiConstruct], + [Contracts.ApiDefinitionKind.ConstructorType, ApiConstruct], + [Contracts.ApiDefinitionKind.TypeParameter, ApiTypeParameter], + [Contracts.ApiDefinitionKind.TypeLiteral, ApiTypeLiteral], + [Contracts.ApiDefinitionKind.ObjectLiteral, ApiTypeLiteral], + [Contracts.ApiDefinitionKind.FunctionType, ApiFunctionExpression], + [Contracts.ApiDefinitionKind.ArrowFunction, ApiFunctionExpression], + [Contracts.ApiDefinitionKind.FunctionExpression, ApiFunctionExpression], + [Contracts.ApiDefinitionKind.Mapped, ApiMapped] +]; diff --git a/packages/ts-docs-gen/src/api-items/api-definition-with-type.ts b/packages/ts-docs-gen/src/api-items/api-definition-with-type.ts new file mode 100644 index 00000000..ac81d42e --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-definition-with-type.ts @@ -0,0 +1,19 @@ +import { Contracts } from "ts-extractor"; +import { ApiDefinitionBase } from "./api-definition-base"; +import { GeneratorHelpers } from "../generator-helpers"; +import { ApiTypes } from "./api-type-list"; + +export type ApiBaseItemWithTypeDto = Contracts.ApiBaseDefinition & { Type: Contracts.ApiType }; + +export abstract class ApiDefinitionWithType + extends ApiDefinitionBase { + + private type: ApiTypes; + + public get Type(): ApiTypes { + if (this.type == null) { + this.type = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.Type); + } + return this.type; + } +} diff --git a/packages/ts-docs-gen/src/api-items/api-type-base.ts b/packages/ts-docs-gen/src/api-items/api-type-base.ts new file mode 100644 index 00000000..68ada2cc --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-type-base.ts @@ -0,0 +1,22 @@ +import { Contracts } from "ts-extractor"; +import { LogLevel } from "simplr-logger"; +import { SerializedApiType, ReferenceRenderHandler } from "../contracts/serialized-api-item"; +import { BaseApiItemClass } from "../abstractions/base-api-item"; +import { GeneratorHelpers } from "../generator-helpers"; +import { ApiDefinitions } from "./api-definition-list"; + +export abstract class ApiTypeBase extends BaseApiItemClass implements SerializedApiType { + protected GetSerializedApiDefinition(referenceId: string): ApiDefinitions { + const apiItem = this.ExtractedData.Registry[referenceId]; + return GeneratorHelpers.SerializeApiDefinition(this.ExtractedData, apiItem, { Alias: "", Id: referenceId }); + } + + protected SerializedTypeToString(render: ReferenceRenderHandler, apiType: SerializedApiType | undefined): string { + if (apiType == null) { + GeneratorHelpers.LogWithApiItemPosition(LogLevel.Error, this.ApiItem, "Missing type!"); + return Contracts.TypeKeywords.Unknown; + } + + return apiType.ToInlineText(render); + } +} diff --git a/packages/ts-docs-gen/src/api-items/api-type-default.ts b/packages/ts-docs-gen/src/api-items/api-type-default.ts new file mode 100644 index 00000000..6c146650 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-type-default.ts @@ -0,0 +1,12 @@ +import { Contracts } from "ts-extractor"; +import { ReferenceRenderHandler, SerializedApiType } from "../contracts/serialized-api-item"; +import { BaseApiItemClass } from "../abstractions/base-api-item"; + +export class ApiTypeDefault + extends BaseApiItemClass implements SerializedApiType { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [ + this.ApiItem.Text + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/api-type-list.ts b/packages/ts-docs-gen/src/api-items/api-type-list.ts new file mode 100644 index 00000000..66ad6f11 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-type-list.ts @@ -0,0 +1,63 @@ +import { Contracts } from "ts-extractor"; +import { SerializedApiTypeConstructor } from "../contracts/serialized-api-item"; + +import { ApiTypeDefault } from "./api-type-default"; +// ApiType +import { ApiTypeBasic } from "./types/api-type-basic"; +import { ApiTypeReference } from "./types/api-type-reference"; +import { ApiTypeUnionOrIntersection } from "./types/api-type-union-or-intersection"; +import { ApiTypeArray } from "./types/api-type-array"; +import { ApiTypeTuple } from "./types/api-type-tuple"; +import { ApiTypeDefinition } from "./types/api-type-definition"; +import { ApiTypePredicate } from "./types/api-type-predicate"; +import { ApiTypeOperator } from "./types/api-type-operator"; +import { ApiIndexedAccess } from "./types/api-type-indexed-access"; +import { ApiTypeParenthesized } from "./types/api-type-parenthesized"; +import { ApiTypeQuery } from "./types/api-type-query"; + +export { + ApiTypeBasic, + ApiTypeReference, + ApiTypeUnionOrIntersection, + ApiTypeArray, + ApiTypeTuple, + ApiTypeDefinition, + ApiTypePredicate, + ApiTypeOperator, + ApiIndexedAccess, + ApiTypeParenthesized, + ApiTypeQuery +}; + +export type ApiTypes = ApiTypeDefault | + ApiTypeBasic | + ApiTypeReference | + ApiTypeUnionOrIntersection | + ApiTypeArray | + ApiTypeTuple | + ApiTypeDefinition | + ApiTypePredicate | + ApiTypeOperator | + ApiIndexedAccess | + ApiTypeParenthesized | + ApiTypeQuery; + +// TODO: Fix any. +export const ApiTypeList: Array<[Contracts.ApiTypeKind, SerializedApiTypeConstructor]> = [ + [Contracts.ApiTypeKind.Basic, ApiTypeBasic], + [Contracts.ApiTypeKind.Reference, ApiTypeReference], + [Contracts.ApiTypeKind.Union, ApiTypeUnionOrIntersection], + [Contracts.ApiTypeKind.Intersection, ApiTypeUnionOrIntersection], + [Contracts.ApiTypeKind.Array, ApiTypeArray], + [Contracts.ApiTypeKind.Tuple, ApiTypeTuple], + [Contracts.ApiTypeKind.TypeLiteral, ApiTypeDefinition], + [Contracts.ApiTypeKind.Mapped, ApiTypeDefinition], + [Contracts.ApiTypeKind.FunctionType, ApiTypeDefinition], + [Contracts.ApiTypeKind.This, ApiTypeDefinition], + [Contracts.ApiTypeKind.Constructor, ApiTypeDefinition], + [Contracts.ApiTypeKind.TypePredicate, ApiTypePredicate], + [Contracts.ApiTypeKind.TypeOperator, ApiTypeOperator], + [Contracts.ApiTypeKind.IndexedAccess, ApiIndexedAccess], + [Contracts.ApiTypeKind.Parenthesized, ApiTypeParenthesized], + [Contracts.ApiTypeKind.TypeQuery, ApiTypeQuery] +]; diff --git a/packages/ts-docs-gen/src/api-items/api-type-members-base.ts b/packages/ts-docs-gen/src/api-items/api-type-members-base.ts new file mode 100644 index 00000000..2a3c74da --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-type-members-base.ts @@ -0,0 +1,17 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "./api-type-base"; +import { GeneratorHelpers } from "../generator-helpers"; +import { ApiTypes } from "./api-type-list"; + +export abstract class ApiTypeMembersBase extends ApiTypeBase { + private members: ApiTypes[]; + + public get Members(): ApiTypes[] { + if (this.members == null) { + this.members = this.ApiItem.Members + .map(x => GeneratorHelpers.SerializeApiType(this.ExtractedData, x)) + .filter((x): x is ApiTypes => x != null); + } + return this.members; + } +} diff --git a/packages/ts-docs-gen/src/api-items/api-type-reference-base.ts b/packages/ts-docs-gen/src/api-items/api-type-reference-base.ts new file mode 100644 index 00000000..ad6de051 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/api-type-reference-base.ts @@ -0,0 +1,39 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "./api-type-base"; +import { GeneratorHelpers } from "../generator-helpers"; +import { ApiDefinitions } from "./api-definition-list"; +import { ApiTypes } from "./api-type-list"; +import { ReferenceRenderHandler } from "../contracts/serialized-api-item"; + +export abstract class ApiTypeReferenceBase extends ApiTypeBase { + private referenceItem: ApiDefinitions | undefined; + + public get ReferenceItem(): ApiDefinitions | undefined { + if (this.referenceItem == null && this.ApiItem.ReferenceId != null) { + this.referenceItem = this.GetSerializedApiDefinition(this.ApiItem.ReferenceId); + } + return this.referenceItem; + } + + protected GetTypeParameters(typeParameters: Contracts.ApiType[] | undefined): ApiTypes[] | undefined { + if (typeParameters == null) { + return undefined; + } + + return typeParameters + .map(x => GeneratorHelpers.SerializeApiType(this.ExtractedData, x)) + .filter((x): x is ApiTypes => x != null); + } + + protected TypeParametersToString(render: ReferenceRenderHandler, apiItem: ApiTypes[] | undefined): string { + if (apiItem == null) { + return ""; + } + + const members = apiItem + .map(x => x.ToInlineText(render)) + .join(", "); + + return `<${members}>`; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-accessor.ts b/packages/ts-docs-gen/src/api-items/definitions/api-accessor.ts new file mode 100644 index 00000000..e634114d --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-accessor.ts @@ -0,0 +1,56 @@ +import { Contracts } from "ts-extractor"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiDefinitionBase } from "../api-definition-base"; +import { ApiTypes } from "../api-type-list"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export type ApiAccessorKinds = Contracts.ApiGetAccessorDto | Contracts.ApiSetAccessorDto; + +export class ApiAccessor extends ApiDefinitionBase { + private type: ApiTypes | undefined; + + public get Type(): ApiTypes | undefined { + if (this.type == null) { + const resolvedType = this.resolveType(); + if (resolvedType != null) { + this.type = GeneratorHelpers.SerializeApiType(this.ExtractedData, resolvedType); + } + } + return this.type; + } + + private resolveType(): Contracts.ApiType | undefined { + let type: Contracts.ApiType | undefined; + if (this.ApiItem.ApiKind === Contracts.ApiDefinitionKind.GetAccessor) { + // GetAccessor + type = this.ApiItem.Type; + } else if (this.ApiItem.Parameter != null) { + // SetAccessor + const apiParameter = this.ExtractedData.Registry[this.ApiItem.Parameter.Ids[0]] as Contracts.ApiParameterDto; + if (apiParameter != null) { + type = apiParameter.Type; + } + } + + return type; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const $abstract = this.ApiItem.IsAbstract ? " abstract" : ""; + const $static = this.ApiItem.IsStatic ? " static" : ""; + + const typeString = this.SerializedTypeToString(render, this.Type); + let accessorType: string; + if (this.ApiItem.ApiKind === Contracts.ApiDefinitionKind.SetAccessor) { + accessorType = "set"; + } else { + accessorType = "get"; + } + + return [`${this.ApiItem.AccessModifier}${$static}${$abstract} ${accessorType} ${this.Name}: ${typeString};`]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-call.ts b/packages/ts-docs-gen/src/api-items/definitions/api-call.ts new file mode 100644 index 00000000..f42d606d --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-call.ts @@ -0,0 +1,15 @@ +import { Contracts } from "ts-extractor"; +import { ApiCallable } from "../api-callable"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiCall extends ApiCallable { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [ + `${this.CallableToString(render)};` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-class-constructor.ts b/packages/ts-docs-gen/src/api-items/definitions/api-class-constructor.ts new file mode 100644 index 00000000..15639bce --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-class-constructor.ts @@ -0,0 +1,16 @@ +import { Contracts } from "ts-extractor"; +import { ApiCallable } from "../api-callable"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiClassConstructor extends ApiCallable { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + + return [ + `${this.ApiItem.AccessModifier} constructor${this.CallableToString(render, "")};` + ]; + } + + public ToHeadingText(): string { + return `constructor${this.CallableToSimpleString()}`; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-class-method.ts b/packages/ts-docs-gen/src/api-items/definitions/api-class-method.ts new file mode 100644 index 00000000..473dab62 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-class-method.ts @@ -0,0 +1,22 @@ +import { Contracts } from "ts-extractor"; +import { ApiCallable } from "../api-callable"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiClassMethod extends ApiCallable { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const optional = this.ApiItem.IsOptional ? "?" : ""; + const $abstract = this.ApiItem.IsAbstract ? " abstract" : ""; + const async = this.ApiItem.IsAsync ? " async" : ""; + const $static = this.ApiItem.IsStatic ? " static" : ""; + const functionHeader = this.CallableToString(render, `${optional}: `); + + const accessModifier = this.ApiItem.AccessModifier; + + return [`${accessModifier}${$static}${$abstract}${async} ${this.Name}${functionHeader};`]; + + } + + public ToHeadingText(): string { + return `${this.Name}${this.CallableToSimpleString()}`; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-class-property.ts b/packages/ts-docs-gen/src/api-items/definitions/api-class-property.ts new file mode 100644 index 00000000..a349131e --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-class-property.ts @@ -0,0 +1,21 @@ +import { Contracts } from "ts-extractor"; +import { ApiDefinitionWithType } from "../api-definition-with-type"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiClassProperty extends ApiDefinitionWithType { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const optional = this.ApiItem.IsOptional ? "?" : ""; + const readOnly = this.ApiItem.IsReadonly ? " readonly" : ""; + const $abstract = this.ApiItem.IsAbstract ? " abstract" : ""; + const $static = this.ApiItem.IsStatic ? " static" : ""; + + const accessModifier = this.ApiItem.AccessModifier; + const type = this.SerializedTypeToString(render, this.Type); + + return [`${accessModifier}${$static}${$abstract}${readOnly} ${this.Name}${optional}: ${type};`]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-class.ts b/packages/ts-docs-gen/src/api-items/definitions/api-class.ts new file mode 100644 index 00000000..0a73c862 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-class.ts @@ -0,0 +1,70 @@ +import { Contracts } from "ts-extractor"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiTypes } from "../api-type-list"; +import { ApiDefinitionContainer } from "../api-definition-container"; +import { ApiTypeParameter } from "./api-type-parameter"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiClass extends ApiDefinitionContainer { + private typeParameters: ApiTypeParameter[]; + + public get TypeParameters(): ApiTypeParameter[] { + if (this.typeParameters == null) { + this.typeParameters = GeneratorHelpers + .GetApiItemReferences(this.ExtractedData, this.ApiItem.TypeParameters) + .map(x => this.GetSerializedApiDefinition(x) as ApiTypeParameter); + } + return this.typeParameters; + } + + private extends: ApiTypes | undefined; + + public get Extends(): ApiTypes | undefined { + return this.extends; + } + + private implements: ApiTypes[]; + + public get Implements(): ApiTypes[] { + if (this.implements == null) { + this.implements = this.ApiItem.Implements + .map(x => GeneratorHelpers.SerializeApiType(this.ExtractedData, x)) + .filter((x): x is ApiTypes => x != null); + } + return this.implements; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + // Abstract + const $abstract = this.ApiItem.IsAbstract ? "abstract " : ""; + + // TypeParameters + const typeParameters: string = this.TypeParametersToString(render, this.TypeParameters); + + // Extends + let extendsString: string; + if (this.Extends != null) { + extendsString = ` extends ${this.Extends.ToInlineText()}`; + } else { + extendsString = ""; + } + + // Implements + let implementsString: string; + if (this.Implements.length > 0) { + const implementsList = this.Implements.map(x => this.SerializedTypeToString(render, x)); + + implementsString = ` implements ${implementsList.join(", ")}`; + } else { + implementsString = ""; + } + + return [ + `${$abstract}class ${this.Name}${typeParameters}${extendsString}${implementsString}` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-construct.ts b/packages/ts-docs-gen/src/api-items/definitions/api-construct.ts new file mode 100644 index 00000000..86d8b1ab --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-construct.ts @@ -0,0 +1,24 @@ +import { Contracts } from "ts-extractor"; +import { ApiCallable } from "../api-callable"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiConstruct extends ApiCallable { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + switch (this.ApiItem.ApiKind) { + case Contracts.ApiDefinitionKind.Construct: { + return [ + `new ${this.CallableToString(render)};` + ]; + } + case Contracts.ApiDefinitionKind.ConstructorType: { + return [ + `new ${this.CallableToString(render, " => ")}` + ]; + } + } + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-enum-member.ts b/packages/ts-docs-gen/src/api-items/definitions/api-enum-member.ts new file mode 100644 index 00000000..2a63f2e5 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-enum-member.ts @@ -0,0 +1,31 @@ +import { Contracts } from "ts-extractor"; +import { ApiDefinitionBase } from "../api-definition-base"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiEnumMember extends ApiDefinitionBase { + public get Name(): string { + const name = this.Reference.Alias || this.ApiItem.Name; + if (this.ParentItem == null) { + return name; + } + + return `${this.ParentItem.Name}.${name}`; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const name = this.ApiItem.Name; + + let value: string; + if (this.ApiItem.Value !== "") { + value = ` = ${this.ApiItem.Value}`; + } else { + value = ""; + } + + return [`${name}${value}`]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-enum.ts b/packages/ts-docs-gen/src/api-items/definitions/api-enum.ts new file mode 100644 index 00000000..dd124a8f --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-enum.ts @@ -0,0 +1,50 @@ +import { Contracts } from "ts-extractor"; + +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiEnumMember } from "./api-enum-member"; +import { ApiDefinitionBase } from "../api-definition-base"; +import { ApiItemReference } from "../../contracts/api-item-reference"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiEnum extends ApiDefinitionBase { + private enumMembers: ApiEnumMember[]; + + public get EnumMembers(): ApiEnumMember[] { + if (this.enumMembers == null) { + this.enumMembers = GeneratorHelpers + .GetApiItemReferences(this.ExtractedData, this.ApiItem.Members) + .map<[ApiItemReference, Contracts.ApiEnumMemberDto]>(reference => + [reference, this.ExtractedData.Registry[reference.Id] as Contracts.ApiEnumMemberDto] + ) + .map(([reference, enumMember]) => new ApiEnumMember(this.ExtractedData, enumMember, reference)); + } + return this.enumMembers; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const $const = this.ApiItem.IsConst ? "const " : ""; + + // Constructing enum body. + const membersStrings = this.EnumMembers.map((memberItem, index, array) => { + let memberString = `${GeneratorHelpers.Tab()} ${memberItem.ToText()}`; + + // Add a comma if current item is not the last item + if (index !== this.EnumMembers.length - 1) { + memberString += ","; + } + + return memberString; + }); + + // Construct enum code output + return [ + `${$const}enum ${this.Name} {`, + ...membersStrings, + "}" + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-function-expression.ts b/packages/ts-docs-gen/src/api-items/definitions/api-function-expression.ts new file mode 100644 index 00000000..0c8f560c --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-function-expression.ts @@ -0,0 +1,15 @@ +import { Contracts } from "ts-extractor"; +import { ApiCallable } from "../api-callable"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiFunctionExpression extends ApiCallable { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [ + this.CallableToString(render, " => ") + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-function.ts b/packages/ts-docs-gen/src/api-items/definitions/api-function.ts new file mode 100644 index 00000000..65f6b513 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-function.ts @@ -0,0 +1,15 @@ +import { Contracts } from "ts-extractor"; +import { ApiCallable } from "../api-callable"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiFunction extends ApiCallable { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [ + `function ${this.Name}${this.CallableToString(render)};` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-index.ts b/packages/ts-docs-gen/src/api-items/definitions/api-index.ts new file mode 100644 index 00000000..7110b143 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-index.ts @@ -0,0 +1,28 @@ +import { Contracts } from "ts-extractor"; + +import { ApiParameter } from "./api-parameter"; +import { ApiDefinitionWithType } from "../api-definition-with-type"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiIndex extends ApiDefinitionWithType { + private parameter: ApiParameter; + + public get Parameter(): ApiParameter { + if (this.parameter == null) { + const apiItem = this.ExtractedData.Registry[this.ApiItem.Parameter] as Contracts.ApiParameterDto; + this.parameter = new ApiParameter(this.ExtractedData, apiItem, { Alias: apiItem.Name, Id: this.ApiItem.Parameter }); + } + return this.parameter; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const readonly: string = this.ApiItem.IsReadonly ? "readonly " : ""; + const type: string = this.SerializedTypeToString(render, this.Type); + + return [`${readonly}[${this.Parameter.ToInlineText(render)}]: ${type};`]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-interface.ts b/packages/ts-docs-gen/src/api-items/definitions/api-interface.ts new file mode 100644 index 00000000..695a55b7 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-interface.ts @@ -0,0 +1,58 @@ +import { Contracts } from "ts-extractor"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiDefinitionContainer } from "../api-definition-container"; +import { ApiTypes } from "../api-type-list"; +import { ApiTypeParameter } from "./api-type-parameter"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiInterface extends ApiDefinitionContainer { + private typeParameters: ApiTypeParameter[]; + + public get TypeParameters(): ApiTypeParameter[] { + if (this.typeParameters == null) { + this.typeParameters = GeneratorHelpers + .GetApiItemReferences(this.ExtractedData, this.ApiItem.TypeParameters) + .map(x => this.GetSerializedApiDefinition(x) as ApiTypeParameter); + } + return this.typeParameters; + } + + private extends: ApiTypes[]; + + public get Extends(): ApiTypes[] { + if (this.extends == null) { + this.extends = this.ApiItem.Extends + .map(x => GeneratorHelpers.SerializeApiType(this.ExtractedData, x)) + .filter((x): x is ApiTypes => x != null); + } + return this.extends; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + // TypeParameters + const typeParameters: string = this.TypeParametersToString(render, this.TypeParameters); + + // Extends + let extendsString: string; + if (this.ApiItem.Extends != null && this.ApiItem.Extends.length > 0) { + const typesList = this.Extends.map(x => this.SerializedTypeToString(render, x)); + + extendsString = ` extends ${typesList.join(", ")}`; + } else { + extendsString = ""; + } + + // Members + const members = this.MembersToText(render, this.Members, 1); + + return [ + `interface ${this.Name}${typeParameters}${extendsString} {`, + ...members, + `}` + ]; + } + + public ToHeadingText(alias?: string | undefined): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-mapped.ts b/packages/ts-docs-gen/src/api-items/definitions/api-mapped.ts new file mode 100644 index 00000000..19973ed6 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-mapped.ts @@ -0,0 +1,44 @@ +import { Contracts } from "ts-extractor"; +import { LogLevel } from "simplr-logger"; + +import { ApiTypeParameter } from "./api-type-parameter"; +import { ApiDefinitionWithType } from "../api-definition-with-type"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiMapped extends ApiDefinitionWithType { + private typeParameter: ApiTypeParameter | undefined; + + public get TypeParameter(): ApiTypeParameter | undefined { + if (this.typeParameter == null && this.ApiItem.TypeParameter != null) { + const apiItem = this.ExtractedData.Registry[this.ApiItem.TypeParameter] as Contracts.ApiTypeParameterDto; + this.typeParameter = new ApiTypeParameter(this.ExtractedData, apiItem, { Alias: apiItem.Name, Id: this.ApiItem.TypeParameter }); + } + return this.typeParameter; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const readonly = this.ApiItem.IsReadonly ? "readonly " : ""; + const optional = this.ApiItem.IsOptional ? "?" : ""; + + let typeParameterString: string; + if (this.TypeParameter != null) { + typeParameterString = this.TypeParameter.ToInlineText(render); + } else { + GeneratorHelpers.LogWithApiItemPosition(LogLevel.Warning, this.ApiItem, "A type parameter is missing!"); + typeParameterString = Contracts.TypeKeywords.Unknown; + } + + const type = this.SerializedTypeToString(render, this.Type); + + return [ + `{`, + `${GeneratorHelpers.Tab(1)}${readonly}[${typeParameterString}]${optional}: ${type}`, + `}` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-method.ts b/packages/ts-docs-gen/src/api-items/definitions/api-method.ts new file mode 100644 index 00000000..53a5d022 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-method.ts @@ -0,0 +1,17 @@ +import { Contracts } from "ts-extractor"; +import { ApiCallable } from "../api-callable"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiMethod extends ApiCallable { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const optional = this.ApiItem.IsOptional ? "?" : ""; + + return [ + `${this.Name}${this.CallableToString(render, `${optional}: `)};` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-namespace.ts b/packages/ts-docs-gen/src/api-items/definitions/api-namespace.ts new file mode 100644 index 00000000..98b887dc --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-namespace.ts @@ -0,0 +1,14 @@ +import { Contracts } from "ts-extractor"; + +import { ApiDefinitionContainer } from "../api-definition-container"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiNamespace extends ApiDefinitionContainer { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [`namespace ${this.Name}`]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-parameter.ts b/packages/ts-docs-gen/src/api-items/definitions/api-parameter.ts new file mode 100644 index 00000000..5774f84c --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-parameter.ts @@ -0,0 +1,21 @@ +import { Contracts } from "ts-extractor"; + +import { ApiDefinitionWithType } from "../api-definition-with-type"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiParameter extends ApiDefinitionWithType { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const initializerString = this.ApiItem.Initializer ? ` = ${this.ApiItem.Initializer}` : ""; + const isOptionalString = this.ApiItem.IsOptional ? "?" : ""; + + const type = this.SerializedTypeToString(render, this.Type); + + return [ + `${this.Name}${isOptionalString}: ${type}${initializerString}` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-property.ts b/packages/ts-docs-gen/src/api-items/definitions/api-property.ts new file mode 100644 index 00000000..756c32ca --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-property.ts @@ -0,0 +1,18 @@ +import { Contracts } from "ts-extractor"; + +import { ApiDefinitionWithType } from "../api-definition-with-type"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiProperty extends ApiDefinitionWithType { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const optional = this.ApiItem.IsOptional ? "?" : ""; + const readOnly = this.ApiItem.IsReadonly ? "readonly " : ""; + const type = this.SerializedTypeToString(render, this.Type); + + return [`${readOnly}${this.Name}${optional}: ${type};`]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-source-file.ts b/packages/ts-docs-gen/src/api-items/definitions/api-source-file.ts new file mode 100644 index 00000000..022acce5 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-source-file.ts @@ -0,0 +1,14 @@ +import { Contracts } from "ts-extractor"; + +import { ApiDefinitionContainer } from "../api-definition-container"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiSourceFile extends ApiDefinitionContainer { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return this.MembersToText(render, this.Members); + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-type-alias.ts b/packages/ts-docs-gen/src/api-items/definitions/api-type-alias.ts new file mode 100644 index 00000000..a4ac1b3d --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-type-alias.ts @@ -0,0 +1,32 @@ +import { Contracts } from "ts-extractor"; + +import { ApiDefinitionWithType } from "../api-definition-with-type"; +import { ApiTypeParameter } from "./api-type-parameter"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiTypeAlias extends ApiDefinitionWithType { + private typeParameters: ApiTypeParameter[]; + + public get TypeParameters(): ApiTypeParameter[] { + if (this.typeParameters == null) { + this.typeParameters = GeneratorHelpers + .GetApiItemReferences(this.ExtractedData, this.ApiItem.TypeParameters) + .map(x => this.GetSerializedApiDefinition(x) as ApiTypeParameter); + } + return this.typeParameters; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const type = this.Type.ToText().join("\n"); + const typeParameters = this.TypeParametersToString(render, this.TypeParameters); + + return [ + `type ${this.Name}${typeParameters} = ${type};` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-type-literal.ts b/packages/ts-docs-gen/src/api-items/definitions/api-type-literal.ts new file mode 100644 index 00000000..ea94f6de --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-type-literal.ts @@ -0,0 +1,20 @@ +import { Contracts } from "ts-extractor"; +import { ApiDefinitionContainer } from "../api-definition-container"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiTypeLiteral extends ApiDefinitionContainer { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + // Members + const members = this.MembersToText(render, this.Members, 1); + + return [ + `{`, + ...members, + `}` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-type-parameter.ts b/packages/ts-docs-gen/src/api-items/definitions/api-type-parameter.ts new file mode 100644 index 00000000..93c5a68e --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-type-parameter.ts @@ -0,0 +1,52 @@ +import { Contracts } from "ts-extractor"; + +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiDefinitionBase } from "../api-definition-base"; +import { ApiTypes } from "../api-type-list"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiTypeParameter extends ApiDefinitionBase { + private constraintType: ApiTypes | undefined; + + public get ConstraintType(): ApiTypes | undefined { + if (this.constraintType == null && this.ApiItem.ConstraintType != null) { + this.constraintType = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.ConstraintType); + } + return this.constraintType; + } + + private defaultType: ApiTypes | undefined; + + public get DefaultType(): ApiTypes | undefined { + if (this.defaultType == null && this.ApiItem.DefaultType != null) { + this.defaultType = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.DefaultType); + } + return this.defaultType; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer, mapped?: boolean): string[] { + const constraintKeyword = mapped ? "in" : "extends"; + + let constraintString: string; + if (this.ApiItem.ConstraintType != null) { + const type = this.SerializedTypeToString(render, this.ConstraintType); + constraintString = ` ${constraintKeyword} ${type}`; + } else { + constraintString = ""; + } + + let defaultTypeString: string; + if (this.ApiItem.DefaultType != null) { + const type = this.SerializedTypeToString(render, this.DefaultType); + defaultTypeString = ` = ${type}`; + } else { + defaultTypeString = ""; + } + + return [`${this.Name}${constraintString}${defaultTypeString}`]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/definitions/api-variable.ts b/packages/ts-docs-gen/src/api-items/definitions/api-variable.ts new file mode 100644 index 00000000..1fbb604b --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/definitions/api-variable.ts @@ -0,0 +1,18 @@ +import { Contracts } from "ts-extractor"; + +import { ApiDefinitionWithType } from "../api-definition-with-type"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export class ApiVariable extends ApiDefinitionWithType { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const type = this.SerializedTypeToString(render, this.Type); + + return [ + `${this.ApiItem.VariableDeclarationType} ${this.Name}: ${type};` + ]; + } + + public ToHeadingText(): string { + return this.Name; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-array.ts b/packages/ts-docs-gen/src/api-items/types/api-type-array.ts new file mode 100644 index 00000000..b9099b9a --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-array.ts @@ -0,0 +1,27 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "../api-type-base"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiTypes } from "../api-type-list"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Example: `Foo[]` + */ +export class ApiTypeArray extends ApiTypeBase { + private type: ApiTypes; + + public get Type(): ApiTypes { + if (this.type == null) { + this.type = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.Type); + } + return this.type; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const type: string = this.SerializedTypeToString(render, this.Type); + + return [ + `${type}[]` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-basic.ts b/packages/ts-docs-gen/src/api-items/types/api-type-basic.ts new file mode 100644 index 00000000..7b17852e --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-basic.ts @@ -0,0 +1,14 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "../api-type-base"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Example: `string` + */ +export class ApiTypeBasic extends ApiTypeBase { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [ + this.ApiItem.Text + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-definition.ts b/packages/ts-docs-gen/src/api-items/types/api-type-definition.ts new file mode 100644 index 00000000..9ba77a24 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-definition.ts @@ -0,0 +1,24 @@ +import { Contracts } from "ts-extractor"; +import { TsHelpers } from "ts-extractor/dist/internal"; +import { ApiTypeReferenceBase } from "../api-type-reference-base"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +export type TypeDefinitions = Contracts.TypeLiteralTypeDto | + Contracts.MappedTypeDto | + Contracts.FunctionTypeTypeDto | + Contracts.ThisTypeDto | + Contracts.ConstructorTypeDto; + +export class ApiTypeDefinition extends ApiTypeReferenceBase { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + if (this.ReferenceItem == null) { + return [this.ApiItem.Text]; + } + + if (TsHelpers.IsInternalSymbolName(this.ReferenceItem.ApiItem.Name)) { + return this.ReferenceItem.ToText(render); + } + + return [render(this.ReferenceItem.Name, this.ApiItem.ReferenceId)]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-indexed-access.ts b/packages/ts-docs-gen/src/api-items/types/api-type-indexed-access.ts new file mode 100644 index 00000000..2b863eb7 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-indexed-access.ts @@ -0,0 +1,36 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "../api-type-base"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { SerializedApiType, ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Example: `Foo[T]` + */ +export class ApiIndexedAccess extends ApiTypeBase { + private objectType: SerializedApiType; + + public get ObjectType(): SerializedApiType { + if (this.objectType == null) { + this.objectType = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.ObjectType); + } + return this.objectType; + } + + private indexType: SerializedApiType; + + public get IndexType(): SerializedApiType { + if (this.indexType == null) { + this.indexType = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.IndexType); + } + return this.indexType; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const objectType: string = this.SerializedTypeToString(render, this.ObjectType); + const indexType: string = this.SerializedTypeToString(render, this.IndexType); + + return [ + `${objectType}[${indexType}]` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-operator.ts b/packages/ts-docs-gen/src/api-items/types/api-type-operator.ts new file mode 100644 index 00000000..39ae4153 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-operator.ts @@ -0,0 +1,26 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "../api-type-base"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiTypes } from "../api-type-list"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Example: `keyof Foo` + */ +export class ApiTypeOperator extends ApiTypeBase { + private type: ApiTypes; + + public get Type(): ApiTypes { + if (this.type == null) { + this.type = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.Type); + } + return this.type; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const type: string = this.SerializedTypeToString(render, this.Type); + return [ + `${this.ApiItem.Keyword} ${type}` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-parenthesized.ts b/packages/ts-docs-gen/src/api-items/types/api-type-parenthesized.ts new file mode 100644 index 00000000..a337f262 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-parenthesized.ts @@ -0,0 +1,27 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "../api-type-base"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiTypes } from "../api-type-list"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Example: `(string | number)` + */ +export class ApiTypeParenthesized extends ApiTypeBase { + private type: ApiTypes; + + public get Type(): ApiTypes { + if (this.type == null) { + this.type = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.Type); + } + return this.type; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const type: string = this.SerializedTypeToString(render, this.Type); + + return [ + `(${type})` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-predicate.ts b/packages/ts-docs-gen/src/api-items/types/api-type-predicate.ts new file mode 100644 index 00000000..81838bed --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-predicate.ts @@ -0,0 +1,27 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeBase } from "../api-type-base"; +import { GeneratorHelpers } from "../../generator-helpers"; +import { ApiTypes } from "../api-type-list"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Example: `arg is string` + */ +export class ApiTypePredicate extends ApiTypeBase { + private type: ApiTypes; + + public get Type(): ApiTypes { + if (this.type == null) { + this.type = GeneratorHelpers.SerializeApiType(this.ExtractedData, this.ApiItem.Type); + } + return this.type; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const type: string = this.SerializedTypeToString(render, this.Type); + + return [ + `${this.ApiItem.ParameterName} is ${type}` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-query.ts b/packages/ts-docs-gen/src/api-items/types/api-type-query.ts new file mode 100644 index 00000000..ed4669ef --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-query.ts @@ -0,0 +1,24 @@ +import { Contracts } from "ts-extractor"; +import { LogLevel } from "simplr-logger"; +import { ApiTypeReferenceBase } from "../api-type-reference-base"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; +import { GeneratorHelpers } from "../../generator-helpers"; + +/** + * Example: `typeof Foo` + */ +export class ApiTypeQuery extends ApiTypeReferenceBase { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + let name: string; + if (this.ReferenceItem != null) { + name = this.ReferenceItem.Name; + } else { + GeneratorHelpers.LogWithApiItemPosition(LogLevel.Error, this.ApiItem, "Missing reference!"); + name = Contracts.TypeKeywords.Unknown; + } + + return [ + `${this.ApiItem.Keyword} ${name}` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-reference.ts b/packages/ts-docs-gen/src/api-items/types/api-type-reference.ts new file mode 100644 index 00000000..3a7ba1ec --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-reference.ts @@ -0,0 +1,39 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeReferenceBase } from "../api-type-reference-base"; +import { ApiTypes } from "../api-type-list"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Examples: + * - `Foo` + * - `Foo` + */ +export class ApiTypeReference extends ApiTypeReferenceBase { + private typeParameters: ApiTypes[] | undefined; + + public get TypeParameters(): ApiTypes[] | undefined { + if (this.typeParameters == null && this.ApiItem.TypeParameters != null) { + this.typeParameters = this.GetTypeParameters(this.ApiItem.TypeParameters); + } + return this.typeParameters; + } + + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const typeParameters = this.TypeParametersToString(render, this.TypeParameters); + + // Resolve name + let name: string; + if (this.ReferenceItem != null) { + name = this.ReferenceItem.Name; + } else { + name = this.ApiItem.SymbolName || this.ApiItem.Text; + } + + // Rendered reference + const renederedName = render(name, this.ApiItem.ReferenceId); + + return [ + `${renederedName}${typeParameters}` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-tuple.ts b/packages/ts-docs-gen/src/api-items/types/api-type-tuple.ts new file mode 100644 index 00000000..407b788b --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-tuple.ts @@ -0,0 +1,14 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeMembersBase } from "../api-type-members-base"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Example: `[string, number]`. + */ +export class ApiTypeTuple extends ApiTypeMembersBase { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + return [ + `[${this.Members.map(x => x.ToInlineText(render)).join(`, `)}]` + ]; + } +} diff --git a/packages/ts-docs-gen/src/api-items/types/api-type-union-or-intersection.ts b/packages/ts-docs-gen/src/api-items/types/api-type-union-or-intersection.ts new file mode 100644 index 00000000..05b80c78 --- /dev/null +++ b/packages/ts-docs-gen/src/api-items/types/api-type-union-or-intersection.ts @@ -0,0 +1,18 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeMembersBase } from "../api-type-members-base"; +import { ReferenceRenderHandler } from "../../contracts/serialized-api-item"; + +/** + * Examples: + * - `Foo | Bar` + * - `Foo & Bar` + */ +export class ApiTypeUnionOrIntersection extends ApiTypeMembersBase { + public ToText(render: ReferenceRenderHandler = this.DefaultReferenceRenderer): string[] { + const character = this.ApiItem.ApiTypeKind === Contracts.ApiTypeKind.Union ? "|" : "&"; + + return [ + this.Members.map(x => x.ToInlineText(render)).join(` ${character} `) + ]; + } +} diff --git a/packages/ts-docs-gen/src/builders/generator-configuration-builder.ts b/packages/ts-docs-gen/src/builders/generator-configuration-builder.ts index f92bbeea..adc8d7b3 100644 --- a/packages/ts-docs-gen/src/builders/generator-configuration-builder.ts +++ b/packages/ts-docs-gen/src/builders/generator-configuration-builder.ts @@ -8,12 +8,27 @@ import { Plugin } from "../contracts/plugin"; import { PluginRegistry } from "../registries/plugin-registry"; import { DefaultPlugins } from "../default-plugins"; -// TODO: Add method to read compiler options from tsconfig. export class GeneratorConfigurationBuilder { - constructor(private projectDirectory: string) { } + constructor(private projectDirectory: string) { + this.configuration.projectDirectory = projectDirectory; + } private configuration: Partial = {}; private compilerOptions: Partial; + private tsConfigLocation: string | undefined; + + private resolveProjectDirectory(): string { + return this.configuration.projectDirectory || this.projectDirectory; + } + + /** + * @param tsconfigLocation Relative `tsconfig.json` location from `projectDirectory`. + */ + public SetTsConfigLocation(tsconfigLocation: string): this { + this.tsConfigLocation = tsconfigLocation; + + return this; + } public OverrideCompilerOptions(compilerOptions: Partial): this { this.compilerOptions = { @@ -25,7 +40,7 @@ export class GeneratorConfigurationBuilder { } /** - * Override configuration with new configuration object. + * Override configuration with a new configuration object. * * @param configuration Partial configuration object. */ @@ -39,14 +54,14 @@ export class GeneratorConfigurationBuilder { } public SetOutputDirectory(outputDirectory: string): this { - this.configuration.OutputDirectory = outputDirectory; + this.configuration.outputDirectory = outputDirectory; return this; } public AddPlugins(plugins: Plugin[]): this { - const currentPlugins = this.configuration.Plugins || []; - this.configuration.Plugins = [...plugins, ...currentPlugins]; + const currentPlugins = this.configuration.plugins || []; + this.configuration.plugins = [...plugins, ...currentPlugins]; return this; } @@ -59,10 +74,9 @@ export class GeneratorConfigurationBuilder { pluginManager.Register(item); } - if (this.configuration.Plugins != null) { - // TODO: Register default plugins. + if (this.configuration.plugins != null) { // Registering given plugins. - for (const plugin of this.configuration.Plugins) { + for (const plugin of this.configuration.plugins) { pluginManager.Register(plugin); } @@ -71,16 +85,19 @@ export class GeneratorConfigurationBuilder { // Resolve tsconfig let compilerOptions = this.compilerOptions; if (compilerOptions == null) { - compilerOptions = await GetCompilerOptions(path.join(this.projectDirectory, "tsconfig.json")); + const tsconfigLocation = this.tsConfigLocation || path.join(this.resolveProjectDirectory(), "tsconfig.json"); + compilerOptions = await GetCompilerOptions(tsconfigLocation); } // Extractor const extractor = new Extractor({ CompilerOptions: compilerOptions, - ProjectDirectory: this.projectDirectory + ProjectDirectory: this.resolveProjectDirectory(), + Exclude: this.configuration.exclude, + OutputPathSeparator: this.configuration.outputPathSeparator }); - const outputDirectory = this.configuration.OutputDirectory || path.join(this.projectDirectory, "/docs/"); + const outputDirectory = this.configuration.outputDirectory || path.join(this.resolveProjectDirectory(), "/docs/"); return { PluginManager: pluginManager, diff --git a/packages/ts-docs-gen/src/cli/arguments.ts b/packages/ts-docs-gen/src/cli/arguments.ts new file mode 100644 index 00000000..f12cd13d --- /dev/null +++ b/packages/ts-docs-gen/src/cli/arguments.ts @@ -0,0 +1,46 @@ +import * as yargs from "yargs"; + +export interface CliArguments extends yargs.Arguments { + project: string; + output?: string; + entryFile: string[]; + plugin?: string[]; + exclude?: string[]; +} + +/** + * Handles all CLI commands and arguments. + */ +export const ArgsHandler = yargs + .showHelpOnFail(true) + .help("h", "Show help") + .alias("h", "help") + .config() + .version() + .alias("v", "version") + // CLI options + .option("project", { + describe: "Project location.", + default: ".", + type: "string" + }) + .alias("p", "project") + .required("p", "Project location is required.") + .option("entryFile", { + describe: "Entry file or files to generate documentation from.", + type: "array" + }) + .option("exclude", { + describe: "File locations that should not be included generated documentation.", + type: "array" + }) + .option("output", { + describe: "Documentation output directory.", + type: "string" + }) + .alias("o", "output") + .option("plugin", { + describe: "Package name or path to plugin.", + type: "array" + }) + .argv as CliArguments; diff --git a/packages/ts-docs-gen/src/cli/launcher.ts b/packages/ts-docs-gen/src/cli/launcher.ts new file mode 100644 index 00000000..5c6bc734 --- /dev/null +++ b/packages/ts-docs-gen/src/cli/launcher.ts @@ -0,0 +1,45 @@ +#!/usr/bin/env node +import * as path from "path"; + +import { ArgsHandler, CliArguments } from "./arguments"; +import { Logger } from "../utils/logger"; +import { GeneratorConfigurationBuilder } from "../builders/generator-configuration-builder"; +import { GeneratorHelpers } from "../generator-helpers"; +import { Generator } from "../generator"; +import { Helpers } from "../utils/helpers"; + +// TODO: Add logger +(async ({ _, $0, project, plugin, output, entryFile, ...rest }: CliArguments) => { + const builder = new GeneratorConfigurationBuilder(project); + + // Plugins + if (plugin != null) { + for (const pluginName of plugin) { + // Resolve module location + let moduleLocation: string; + if (Helpers.IsPackageName(pluginName)) { + moduleLocation = pluginName; + } else { + moduleLocation = path.resolve(process.cwd(), pluginName); + } + + try { + const plugins = await GeneratorHelpers.ResolvePlugin(moduleLocation); + builder.AddPlugins(plugins); + } catch (error) { + Logger.Error(`An error has occured while processing plugins. Resolved location:"${moduleLocation}".`, error); + } + } + } + + // Output + if (output != null) { + builder.SetOutputDirectory(output); + } + + // Set rest of configuration + builder.OverrideConfiguration(rest); + + const generator = new Generator(await builder.Build(entryFile)); + await generator.WriteToFiles(); +})(ArgsHandler); diff --git a/packages/ts-docs-gen/src/contracts/api-item-reference-registry.ts b/packages/ts-docs-gen/src/contracts/api-item-reference-registry.ts new file mode 100644 index 00000000..a26278f8 --- /dev/null +++ b/packages/ts-docs-gen/src/contracts/api-item-reference-registry.ts @@ -0,0 +1,10 @@ +import { ApiItemReference } from "./api-item-reference"; + +export interface ReadonlyApiItemReferenceRegistry { + GetItem(itemReference: ApiItemReference): TValue | undefined; + Exists(itemReference: ApiItemReference): boolean; +} + +export interface ApiItemReferenceRegistry extends ReadonlyApiItemReferenceRegistry { + AddItem(itemReference: ApiItemReference, value: TValue): void; +} diff --git a/packages/ts-docs-gen/src/contracts/contracts.ts b/packages/ts-docs-gen/src/contracts/contracts.ts new file mode 100644 index 00000000..60b7ce68 --- /dev/null +++ b/packages/ts-docs-gen/src/contracts/contracts.ts @@ -0,0 +1,6 @@ +export * from "./api-item-reference-registry"; +export * from "./api-item-reference"; +export * from "./file-result"; +export * from "./generator-configuration"; +export * from "./plugin"; +export * from "./serialized-api-item"; diff --git a/packages/ts-docs-gen/src/contracts/generator-configuration.ts b/packages/ts-docs-gen/src/contracts/generator-configuration.ts index e6a8a665..4592466d 100644 --- a/packages/ts-docs-gen/src/contracts/generator-configuration.ts +++ b/packages/ts-docs-gen/src/contracts/generator-configuration.ts @@ -10,10 +10,9 @@ export interface GeneratorConfiguration { } export interface WorkingGeneratorConfiguration { - OutputDirectory: string; - ProjectDirectory: string; - Plugins: Plugin[]; - - Exclude: string[]; - OutputPathSeparator: string; + outputDirectory: string; + projectDirectory: string; + plugins: Plugin[]; + exclude: string[]; + outputPathSeparator: string; } diff --git a/packages/ts-docs-gen/src/contracts/plugin-result-registry.ts b/packages/ts-docs-gen/src/contracts/plugin-result-registry.ts deleted file mode 100644 index 3a956da9..00000000 --- a/packages/ts-docs-gen/src/contracts/plugin-result-registry.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { PluginResult } from "./plugin"; -import { ApiItemReference } from "./api-item-reference"; - -export interface ReadonlyPluginResultRegistry { - GetItem(itemReference: ApiItemReference): PluginResult | undefined; - Exists(itemReference: ApiItemReference): boolean; -} - -export interface PluginResultRegistry extends ReadonlyPluginResultRegistry { - AddItem(itemReference: ApiItemReference, pluginResult: PluginResult): void; -} diff --git a/packages/ts-docs-gen/src/contracts/plugin.ts b/packages/ts-docs-gen/src/contracts/plugin.ts index 1b6b4df3..7e688f85 100644 --- a/packages/ts-docs-gen/src/contracts/plugin.ts +++ b/packages/ts-docs-gen/src/contracts/plugin.ts @@ -2,34 +2,38 @@ import { Contracts, ExtractDto } from "ts-extractor"; import { ApiItemReference } from "./api-item-reference"; -export enum ApiItemKindsAdditional { +export enum ApiDefinitionKindAdditional { Any = "any" } -export type SupportedApiItemKindType = Contracts.ApiItemKinds | ApiItemKindsAdditional; +export type SupportedApiItemKindType = Contracts.ApiDefinitionKind | ApiDefinitionKindAdditional; + +export interface PluginConstructor { + new(): Plugin; +} export interface PluginHeading { Heading: string; ApiItemId: string; + Members?: PluginHeading[]; } -export interface PluginMember { +export interface PluginMember { Reference: ApiItemReference; - PluginResult: PluginResult; + PluginResult: PluginResult; } export type GetItemPluginResultHandler = (reference: ApiItemReference) => PluginResult; export type IsPluginResultExistsHandler = (reference: ApiItemReference) => boolean; -export interface PluginOptions { +export interface PluginOptions { Reference: ApiItemReference; - ApiItem: TKind; ExtractedData: ExtractDto; GetItemPluginResult: GetItemPluginResultHandler; IsPluginResultExists: IsPluginResultExistsHandler; } -export interface PluginResultData { +export interface PluginResultData { /** * All headings used in `Result` with ApiItemIds. */ @@ -42,16 +46,16 @@ export interface PluginResultData { * Plugin rendered result. */ Result: string[]; - Members: PluginMember[]; + Members: Array>; } -export interface PluginResult extends PluginResultData { +export interface PluginResult extends PluginResultData { Reference: ApiItemReference; ApiItem: TKind; } -export interface Plugin { - SupportedApiItemKinds(): SupportedApiItemKindType[]; +export interface Plugin { + SupportedApiDefinitionKind(): SupportedApiItemKindType[]; CheckApiItem(item: TKind): boolean; - Render(options: PluginOptions): PluginResult; + Render(options: PluginOptions, apiItem: TKind): PluginResult; } diff --git a/packages/ts-docs-gen/src/contracts/serialized-api-item.ts b/packages/ts-docs-gen/src/contracts/serialized-api-item.ts new file mode 100644 index 00000000..56d559d5 --- /dev/null +++ b/packages/ts-docs-gen/src/contracts/serialized-api-item.ts @@ -0,0 +1,34 @@ +import { Contracts, ExtractDto } from "ts-extractor"; +import { ApiItemReference } from "./api-item-reference"; + +// ApiItemsLists +import { ApiDefinitions } from "../api-items/api-definition-list"; +import { ApiTypes } from "../api-items/api-type-list"; + +export type ReferenceRenderHandler = (name: string, referenceId?: string) => string; + +export interface SerializedApiItem { + ApiItem: TKind; + ToText(render?: ReferenceRenderHandler): string[]; + ToInlineText(render?: ReferenceRenderHandler): string; +} + +export interface SerializedApiDefinitionConstructor { + new(extractedData: ExtractDto, apiItem: TKind, reference: ApiItemReference): ApiDefinitions; +} + +export interface SerializedApiDefinition + extends SerializedApiItem { + ParentItem?: SerializedApiItem; + Name: string; + Reference: ApiItemReference; + ToHeadingText(): string; +} + +export interface SerializedApiTypeConstructor { + new(extractedData: ExtractDto, apiItem: TKind): ApiTypes; +} + +export interface SerializedApiType + extends SerializedApiItem { +} diff --git a/packages/ts-docs-gen/src/debug.ts b/packages/ts-docs-gen/src/debug.ts index 147abc82..d283618c 100644 --- a/packages/ts-docs-gen/src/debug.ts +++ b/packages/ts-docs-gen/src/debug.ts @@ -1,20 +1,45 @@ // This is debug file. DO NOT include in compiled package. import * as path from "path"; +import { Contracts } from "ts-extractor"; import { GeneratorConfigurationBuilder } from "./builders/generator-configuration-builder"; import { Generator } from "./generator"; +import { BasePlugin } from "./abstractions/base-plugin"; +import { PluginOptions, SupportedApiItemKindType, PluginResult } from "./contracts/plugin"; +import { GeneratorHelpers } from "./generator-helpers"; + +export class PluginDebug extends BasePlugin { + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [ + GeneratorHelpers.ApiDefinitionKind.Any + ]; + } + + public Render(options: PluginOptions, apiItem: Contracts.ApiDefinition): PluginResult { + return { + ...GeneratorHelpers.GetDefaultPluginResultData(), + Reference: options.Reference, + ApiItem: apiItem, + Result: [ + "# Debug Plugin", + "", + `${apiItem.Name}: ${apiItem.ApiKind}` + ] + }; + } +} async function Main(): Promise { const projectDirectory = path.join(process.cwd(), "./examples/simple/"); // const entryFiles = ["./index.ts", "./exported-const-variables.ts", "./exported-functions.ts"]; - const entryFiles = ["./exported-functions.ts", "./index.ts"]; + const entryFiles = ["./index.ts"]; const configPromise = new GeneratorConfigurationBuilder(projectDirectory).Build(entryFiles); const config = await configPromise; const generator = new Generator(config); // tslint:disable-next-line:no-console - console.log(generator.OutputData); + // console.log(generator.OutputData); // tslint:disable-next-line:no-debugger await generator.WriteToFiles(); } diff --git a/packages/ts-docs-gen/src/file-manager.ts b/packages/ts-docs-gen/src/file-manager.ts index 60214a1c..894df8f1 100644 --- a/packages/ts-docs-gen/src/file-manager.ts +++ b/packages/ts-docs-gen/src/file-manager.ts @@ -1,31 +1,92 @@ -import { Contracts } from "ts-extractor"; -import { MarkdownGenerator } from "@simplrjs/markdown"; +import { Contracts, ExtractDto } from "ts-extractor"; +import { MarkdownGenerator, MarkdownBuilder, Contracts as MarkdownContracts } from "@simplrjs/markdown"; +import { LogLevel } from "simplr-logger"; import * as path from "path"; import { Helpers } from "./utils/helpers"; -import { PluginResult } from "./contracts/plugin"; +import { PluginResult, PluginHeading } from "./contracts/plugin"; import { FileResult } from "./contracts/file-result"; import { GeneratorHelpers } from "./generator-helpers"; - -interface OutputData { - Result: string[]; - UsedReferences: string[]; -} - -type RenderedItemList = Array; +import { ApiContainer, ContainerMembersKindsGroup } from "./abstractions/container-plugin"; +import { ApiClassPlugin } from "./plugins/api-class-plugin"; +import { ApiSourceFilePlugin } from "./plugins/api-source-file-plugin"; +import { ApiNamespacePlugin } from "./plugins/api-namespace-plugin"; // TODO: remove unused files before generating docs. export class FileManager { + constructor(private extractedData: ExtractDto) { } + /** * */ - private filesList: Map = new Map(); + private filesList: Map> = new Map(); /** * */ private referenceToFile: Map = new Map(); - public AddEntryFile(itemResult: PluginResult): void { + private resolveMemberKindsList(apiItemKind: Contracts.ApiDefinitionKind): ContainerMembersKindsGroup[] | undefined { + switch (apiItemKind) { + case Contracts.ApiDefinitionKind.Class: { + return ApiClassPlugin.MemberKindsList; + } + case Contracts.ApiDefinitionKind.Namespace: { + return ApiNamespacePlugin.MemberKindsList; + } + case Contracts.ApiDefinitionKind.SourceFile: { + return ApiSourceFilePlugin.MemberKindsList; + } + } + } + + private renderTableOfContents(containerResult: PluginResult): string[] { + const memberKindsList = this.resolveMemberKindsList(containerResult.ApiItem.ApiKind); + + if (memberKindsList == null) { + return []; + } + + const tableList: MarkdownContracts.MarkdownList = []; + + containerResult.Headings.forEach(heading => { + const headingMembers = heading.Members; + if (headingMembers == null || headingMembers.length === 0) { + return; + } + + // Adding first level heading link. + const headingLink = MarkdownGenerator.Link(heading.Heading, heading.ApiItemId, true); + tableList.push(headingLink); + + memberKindsList.forEach(memberKindGroup => { + // Filtering headings by kind group. + const membersOfKind = headingMembers + .filter(x => memberKindGroup.Kinds.indexOf(this.extractedData.Registry[x.ApiItemId].ApiKind) !== -1); + + if (membersOfKind.length === 0) { + return []; + } + + const membersReferences = membersOfKind.map(x => MarkdownGenerator.Link(x.Heading, x.ApiItemId, true)); + + // Adding headings of single kind group. + tableList.push([memberKindGroup.Heading, membersReferences]); + }); + }); + + if (tableList.length === 0) { + return []; + } + + return new MarkdownBuilder() + .Header("Table of contents", 1) + .EmptyLine() + .UnorderedList(tableList) + .EmptyLine() + .GetOutput(); + } + + public AddEntryFile(itemResult: PluginResult): void { const filePath = path.basename( itemResult.ApiItem.Location.FileName, path.extname(itemResult.ApiItem.Location.FileName @@ -35,15 +96,42 @@ export class FileManager { this.AddItem(itemResult, filePath); } - public AddItem(itemResult: PluginResult, filePath: string): void { - const items = this.filesList.get(filePath) || []; - items.push(itemResult); - this.filesList.set(filePath, items); - // Adding headings. - for (const heading of itemResult.Headings) { + private addItemHeadings(headings: PluginHeading[], filePath: string): void { + for (const heading of headings) { this.referenceToFile.set(heading.ApiItemId, `${filePath}#${Helpers.HeadingToAnchor(heading.Heading)}`); + + if (heading.Members != null) { + this.addItemHeadings(heading.Members, filePath); + } + } + } + + private resolveReferenceFile(referenceId: string): string | undefined { + const apiItem = this.extractedData.Registry[referenceId]; + const serializedApiItem = GeneratorHelpers + .SerializeApiDefinition(this.extractedData, apiItem, { Alias: apiItem.Name, Id: referenceId }); + + if (!this.referenceToFile.has(referenceId) && serializedApiItem.ParentItem != null) { + return this.resolveReferenceFile(serializedApiItem.ParentItem.Reference.Id); + } + + return this.referenceToFile.get(referenceId); + } + + private removeBrokenLinks(result: string[], referenceId: string): string[] { + const linkDefinition = new RegExp(`\\[(.+)\\]\\[${referenceId}\\]`, "g"); + return result.map(x => x.replace(linkDefinition, "$1")); + } + + public AddItem(itemResult: PluginResult, filePath: string): void { + if (this.filesList.get(filePath) == null) { + this.filesList.set(filePath, itemResult); } + this.filesList.set(filePath, itemResult); + // Adding headings. + this.addItemHeadings(itemResult.Headings, filePath); + // HeadingsMap if (itemResult.Members != null) { for (const member of itemResult.Members) { @@ -62,34 +150,42 @@ export class FileManager { public ToFilesOutput(): FileResult[] { const files: FileResult[] = []; - for (const [fileLocation, items] of this.filesList) { + for (const [fileLocation, item] of this.filesList) { + // Link definitions to file location. const linkDefinitions: string[] = []; - for (const item of items.reverse()) { - item.UsedReferences - .forEach(referenceId => { - const filePath = path.dirname(fileLocation); - - const referenceString = this.referenceToFile.get(referenceId); - const resolvePath = GeneratorHelpers.StandardisePath(path.relative(filePath, referenceString || "#__error")); - - linkDefinitions.push( - MarkdownGenerator.LinkDefinition(referenceId, resolvePath) - ); - - if (!referenceString) { - console.warn(`Reference "${referenceId}" not found. Check ${fileLocation}.`); - } - }); - } - - const itemsResult = Helpers.Flatten(items.map(x => [x.Result, ""])); + // Plugin result. + let pluginResult = item.Result; + item.UsedReferences.forEach(referenceId => { + const filePath = path.dirname(fileLocation); + + const referenceString = this.resolveReferenceFile(referenceId); + // referenceString is not falsy. + if (referenceString) { + const resolvePath = GeneratorHelpers.StandardizePath(path.relative(filePath, referenceString)); + + linkDefinitions.push( + MarkdownGenerator.LinkDefinition(referenceId, resolvePath) + ); + } else { + // Removes broken links. + pluginResult = this.removeBrokenLinks(pluginResult, referenceId); + const apiItem = this.extractedData.Registry[referenceId]; + + GeneratorHelpers.LogWithApiItemPosition( + LogLevel.Warning, + apiItem, + "Declaration is used as type and not exported in entry files." + ); + } + }); files.push({ - FileLocation: GeneratorHelpers.StandardisePath(fileLocation), + FileLocation: GeneratorHelpers.StandardizePath(fileLocation), Result: [ - ...linkDefinitions, - ...itemsResult + ...this.renderTableOfContents(item), + ...pluginResult, + ...linkDefinitions ] }); } diff --git a/packages/ts-docs-gen/src/generator-helpers.ts b/packages/ts-docs-gen/src/generator-helpers.ts index 562fed93..37a72880 100644 --- a/packages/ts-docs-gen/src/generator-helpers.ts +++ b/packages/ts-docs-gen/src/generator-helpers.ts @@ -1,21 +1,92 @@ -import { Contracts, ExtractDto, TSHelpers } from "ts-extractor"; +import { Contracts, ExtractDto } from "ts-extractor"; import { LogLevel } from "simplr-logger"; -import { MarkdownGenerator, MarkdownBuilder, Contracts as MarkdownContracts } from "@simplrjs/markdown"; +import { Contracts as MarkdownContracts } from "@simplrjs/markdown"; import * as path from "path"; import { ApiItemReference } from "./contracts/api-item-reference"; -import { ApiItemKindsAdditional, PluginResultData } from "./contracts/plugin"; +import { + ApiDefinitionKindAdditional, + PluginResultData, + Plugin, + PluginConstructor +} from "./contracts/plugin"; import { Logger } from "./utils/logger"; -import { Helpers } from "./utils/helpers"; +import { SerializedApiDefinitionConstructor, SerializedApiTypeConstructor } from "./contracts/serialized-api-item"; +import { ApiDefinitionList, ApiDefinitions } from "./api-items/api-definition-list"; +import { ApiTypeList, ApiTypes } from "./api-items/api-type-list"; +import { ApiDefinitionDefault } from "./api-items/api-definition-default"; +import { ApiTypeDefault } from "./api-items/api-type-default"; export namespace GeneratorHelpers { - export type TypeToStringDto = ReferenceDto; + /** + * Checks if object has `TsDocsGenPlugin` static function. + */ + export function IsPluginClass(arg: any): arg is PluginConstructor { + return arg.TsDocsGenPlugin != null; + } + + /** + * Resolves plugins from given file. + * @param file Plugin name or path to plugin. + */ + export async function ResolvePlugin(file: string): Promise { + const $module: { [key: string]: any } = await import(file); + const result: Plugin[] = []; + + if ($module == null) { + return []; + } + + for (const key in $module) { + if ($module.hasOwnProperty(key)) { + const value = $module[key]; + + if (GeneratorHelpers.IsPluginClass(value)) { + result.push(new value()); + } + } + } + + return result; + } + + //#region Serialize ApiItem + export function SerializeApiDefinition( + extractedData: ExtractDto, + apiItem: TKind, + reference: ApiItemReference + ): ApiDefinitions { + for (const [kind, constructorItem] of ApiDefinitionList) { + if (kind === apiItem.ApiKind) { + const $constructor: SerializedApiDefinitionConstructor = constructorItem; + const serializedApiItem = new $constructor(extractedData, apiItem, reference); + + return serializedApiItem; + } + } + + LogWithApiItemPosition(LogLevel.Warning, apiItem, `"${apiItem.ApiKind}" is not supported!`); + return new ApiDefinitionDefault(extractedData, apiItem, reference); + } + + export function SerializeApiType(extractedData: ExtractDto, apiType: Contracts.ApiType): ApiTypes { + if (apiType != null) { + for (const [kind, constructorItem] of ApiTypeList) { + if (kind === apiType.ApiTypeKind) { + const $constructor: SerializedApiTypeConstructor = constructorItem; + + return new $constructor(extractedData, apiType); + } + } + } - export interface ReferenceDto { - References: string[]; - Text: T; + LogWithApiItemPosition(LogLevel.Error, apiType, `"${apiType.ApiTypeKind}" is not supported`); + return new ApiTypeDefault(extractedData, apiType); } + //#endregion Serialize ApiItem + + // #region Defaults and constants export enum JSDocTags { Beta = "beta", Deprecated = "deprecated", @@ -23,12 +94,10 @@ export namespace GeneratorHelpers { Summary = "summary" } - // #region Defaults and constants - export const MARKDOWN_EXT = ".md"; - export const ApiItemKinds: typeof ApiItemKindsAdditional & typeof Contracts.ApiItemKinds = - Object.assign(ApiItemKindsAdditional, Contracts.ApiItemKinds); + export const ApiDefinitionKind: typeof ApiDefinitionKindAdditional & typeof Contracts.ApiDefinitionKind = + Object.assign(ApiDefinitionKindAdditional, Contracts.ApiDefinitionKind); export const DEFAULT_CODE_OPTIONS = { lang: "typescript" @@ -43,8 +112,8 @@ export namespace GeneratorHelpers { // #region General helpers - export function GetApiItemKinds(): typeof Contracts.ApiItemKinds & typeof ApiItemKindsAdditional { - return Object.assign(Contracts.ApiItemKinds, ApiItemKindsAdditional); + export function GetApiDefinitionKind(): typeof Contracts.ApiDefinitionKind & typeof ApiDefinitionKindAdditional { + return Object.assign(Contracts.ApiDefinitionKind, ApiDefinitionKindAdditional); } export function GetApiItemReferences( @@ -59,7 +128,7 @@ export namespace GeneratorHelpers { const apiItem = extractedData.Registry[referenceId]; switch (apiItem.ApiKind) { - case Contracts.ApiItemKinds.Export: { + case Contracts.ApiDefinitionKind.Export: { if (apiItem.SourceFileId != null) { const sourceFileReference = { Alias: apiItem.Name, Ids: [apiItem.SourceFileId] }; const referencesList = GetApiItemReferences(extractedData, [sourceFileReference]); @@ -67,8 +136,8 @@ export namespace GeneratorHelpers { } break; } - case Contracts.ApiItemKinds.ImportSpecifier: - case Contracts.ApiItemKinds.ExportSpecifier: { + case Contracts.ApiDefinitionKind.ImportSpecifier: + case Contracts.ApiDefinitionKind.ExportSpecifier: { if (apiItem.ApiItems == null) { LogWithApiItemPosition( LogLevel.Warning, @@ -83,7 +152,7 @@ export namespace GeneratorHelpers { overallReferences = overallReferences.concat(referencesList); break; } - case Contracts.ApiItemKinds.SourceFile: { + case Contracts.ApiDefinitionKind.SourceFile: { if (apiItem.Members == null) { LogWithApiItemPosition( LogLevel.Warning, @@ -109,38 +178,23 @@ export namespace GeneratorHelpers { return overallReferences; } - export function GetApiItemsFromReference( - items: Contracts.ApiItemReference[], - extractedData: ExtractDto, - apiItemKind?: Contracts.ApiItemKinds - ): T[] { - const apiItems: T[] = []; - - for (const itemReferences of items) { - for (const referenceId of itemReferences.Ids) { - const apiItem = extractedData.Registry[referenceId] as T; - if (apiItemKind == null || apiItemKind != null && apiItem.ApiKind === apiItemKind) { - apiItems.push(apiItem); - } - } - } - - return apiItems; - } - - export function LogWithApiItemPosition(logLevel: LogLevel, apiItem: Contracts.ApiItemDto, message: string): void { + export function LogWithApiItemPosition( + logLevel: LogLevel, + apiItem: Contracts.ApiBaseDefinition | Contracts.ApiBaseType, + ...message: string[] + ): void { const { FileName, Line, Character } = apiItem.Location; - const linePrefix = `${FileName}[${Line}:${Character + 1}]`; + const linePrefix = `${FileName}(${Line + 1},${Character})`; Logger.Log(logLevel, `${linePrefix}: ${message}`); } - export function StandardisePath(pathString: string): string { + export function StandardizePath(pathString: string): string { return pathString.split(path.sep).join("/"); } - export function IsApiItemKind( - itemKind: Contracts.ApiItemKinds, - apiItem: Contracts.ApiItemDto): apiItem is TKindDto { + export function IsApiItemKind( + itemKind: Contracts.ApiDefinitionKind, + apiItem: Contracts.ApiDefinition): apiItem is TKindDto { return apiItem.ApiKind === itemKind; } @@ -157,7 +211,7 @@ export namespace GeneratorHelpers { return a; } - export function GetDefaultPluginResultData(): PluginResultData { + export function GetDefaultPluginResultData(): PluginResultData { return { Headings: [], Result: [], @@ -169,111 +223,6 @@ export namespace GeneratorHelpers { // #region Render helpers - // TODO: implement type literal and function type. - export function TypeDtoToMarkdownString(type: Contracts.TypeDto): TypeToStringDto { - let references: string[] = []; - let text: string = ""; - - switch (type.ApiTypeKind) { - case Contracts.TypeKinds.Union: - case Contracts.TypeKinds.Intersection: { - const symbol = type.ApiTypeKind === Contracts.TypeKinds.Union ? "|" : "&"; - - if (type.ReferenceId != null) { - text = MarkdownGenerator.Link(type.Name || type.Text, type.ReferenceId, true); - references.push(type.ReferenceId); - break; - } - - type.Types - .map(TypeDtoToMarkdownString) - .forEach(typeItem => { - references = references.concat(typeItem.References); - - if (text === "") { - text = typeItem.Text; - } else { - text += ` ${symbol} ${typeItem.Text}`; - } - }); - break; - } - case Contracts.TypeKinds.Basic: - default: { - // Basic type with reference. - if (type.Name == null || TSHelpers.IsInternalSymbolName(type.Name)) { - text = type.Text; - } else { - // FIXME: do not use flag string. Exclude Type parameters references. - if (type.ReferenceId != null && type.FlagsString !== "TypeParameter") { - text = MarkdownGenerator.Link(type.Name || type.Text, type.ReferenceId, true); - references.push(type.ReferenceId); - } else { - text = type.Name; - } - } - - // Generics - if (type.Name != null && type.Generics != null) { - const generics = type.Generics.map(TypeDtoToMarkdownString); - references = references.concat(...generics.map(x => x.References)); - - text += MarkdownGenerator.EscapeString(`<${generics.map(x => x.Text).join(", ")}>`); - } - } - } - - return { - References: references, - Text: text - }; - } - - export function RenderApiItemMetadata(apiItem: Contracts.ApiItemDto): string[] { - const builder = new MarkdownBuilder(); - - // Optimise? - const isBeta = apiItem.Metadata.JSDocTags.findIndex(x => x.name.toLowerCase() === JSDocTags.Beta) !== -1; - const deprecated = apiItem.Metadata.JSDocTags.find(x => x.name.toLowerCase() === JSDocTags.Deprecated); - const internal = apiItem.Metadata.JSDocTags.find(x => x.name.toLowerCase() === JSDocTags.Internal); - const summary = apiItem.Metadata.JSDocTags.find(x => x.name.toLowerCase() === JSDocTags.Summary); - const jSDocComment = apiItem.Metadata.DocumentationComment; - - if (isBeta) { - builder - .Text(`Warning: Beta!`) - .EmptyLine(); - } - - if (deprecated != null) { - const message = Boolean(deprecated.text) ? `: ${deprecated.text}` : ""; - builder - .Text(`Deprecated${message}!`) - .EmptyLine(); - } - - if (internal != null) { - const message = Boolean(internal.text) ? `: ${internal.text}` : ""; - builder - .Bold(`Internal${message}`) - .EmptyLine(); - } - - if (jSDocComment.length > 0) { - builder - .Text(jSDocComment) - .EmptyLine(); - } - - if (summary != null && Boolean(summary.text)) { - builder - .Blockquote(summary.text!.split("\n")) - .EmptyLine(); - } - - return builder.GetOutput(); - } - const TAB_STRING = " "; export function Tab(size: number = 1): string { @@ -284,7 +233,7 @@ export namespace GeneratorHelpers { return result; } - export function FixSentence(sentence: string, punctuationMark: string = "."): string { + export function EnsureFullStop(sentence: string, punctuationMark: string = "."): string { const trimmedSentence = sentence.trim(); const punctuationMarks = ".!:;,-"; @@ -298,454 +247,4 @@ export namespace GeneratorHelpers { } // #endregion Render helpers - - // #region Stringifiers - - // TODO: optimize. - export function ApiInterfaceToString( - apiItem: Contracts.ApiInterfaceDto, - extractedData: ExtractDto - ): string[] { - const typeParameters = GetApiItemsFromReference(apiItem.TypeParameters, extractedData); - const typeParametersString = TypeParametersToString(typeParameters); - - let extendsString: string; - - if (apiItem.Extends.length === 0) { - extendsString = ""; - } else { - const typesExtended = apiItem.Extends - .map(x => x.Text) - .join(", "); - extendsString = ` extends ${typesExtended}`; - } - - const builder = new MarkdownBuilder() - .Text(`interface ${apiItem.Name}${typeParametersString}${extendsString} {`); - - const constructMembers = GetApiItemsFromReference( - apiItem.Members, - extractedData, - Contracts.ApiItemKinds.Construct - ); - constructMembers.forEach(member => { - const parameters = GetApiItemsFromReference(member.Parameters, extractedData); - const memberTypeParameters = GetApiItemsFromReference(member.TypeParameters, extractedData); - builder.Text(`${Tab(1)}${ApiConstructToString(memberTypeParameters, parameters, member.ReturnType)};`); - }); - - const callMembers = GetApiItemsFromReference( - apiItem.Members, - extractedData, - Contracts.ApiItemKinds.Call - ); - callMembers.forEach(member => { - const parameters = GetApiItemsFromReference(member.Parameters, extractedData); - const memberTypeParameters = GetApiItemsFromReference(member.TypeParameters, extractedData); - builder.Text(`${Tab(1)}${ApiCallToString(memberTypeParameters, parameters, member.ReturnType)};`); - }); - - const indexMembers = GetApiItemsFromReference( - apiItem.Members, - extractedData, - Contracts.ApiItemKinds.Index - ); - indexMembers.forEach(member => { - const parameter = extractedData.Registry[member.Parameter] as Contracts.ApiParameterDto; - builder.Text(`${Tab(1)}${ApiIndexToString(parameter, member.Type, member.IsReadonly)};`); - }); - - const methodMembers = GetApiItemsFromReference( - apiItem.Members, - extractedData, - Contracts.ApiItemKinds.Method - ); - methodMembers.forEach(member => { - const parameters = GetApiItemsFromReference(member.Parameters, extractedData); - const memberTypeParameters = GetApiItemsFromReference(member.TypeParameters, extractedData); - - builder.Text(`${Tab(1)}${ApiMethodToString(member.Name, memberTypeParameters, parameters, member.ReturnType)};`); - }); - - const propertyMembers = GetApiItemsFromReference( - apiItem.Members, - extractedData, - Contracts.ApiItemKinds.Property - ); - propertyMembers.forEach(member => { - builder.Text(`${Tab(1)}${ApiPropertyToString(member)};`); - }); - - builder.Text("}"); - - return builder.GetOutput(); - } - - export function ApiTypeToString(item: Contracts.ApiTypeDto, alias?: string): string { - const name = alias != null ? alias : item.Name; - - return `type ${name} = ${item.Type.Text};`; - } - - export function ApiInterfaceToSimpleString(alias: string, apiItem: Contracts.ApiInterfaceDto): string { - const name = alias || apiItem.Name; - return `interface ${name}`; - } - - export function ApiIndexToString(parameter: Contracts.ApiParameterDto, type: Contracts.TypeDto, readOnly: boolean = false): string { - const typeString = TypeDtoToMarkdownString(type).Text; - const parameterTypeString = TypeDtoToMarkdownString(parameter.Type).Text; - - const readOnlyString = readOnly ? "readonly " : ""; - - return `${readOnlyString}[${parameter.Name}: ${parameterTypeString}]: ${typeString}`; - } - - export function ApiPropertyToString(apiItem: Contracts.ApiPropertyDto): string { - const optional = apiItem.IsOptional ? "?" : ""; - const readOnly = apiItem.IsReadonly ? "readonly " : ""; - - return `${readOnly}${apiItem.Name}${optional}: ${apiItem.Type.Text}`; - } - - export function ApiAccessorToString( - apiItem: Contracts.ApiGetAccessorDto | Contracts.ApiSetAccessorDto, - type: Contracts.TypeDto | undefined, - alias?: string - ): string { - const name = alias || apiItem.Name; - const abstract = apiItem.IsAbstract ? " abstract" : ""; - const $static = apiItem.IsStatic ? " static" : ""; - - const typeString = type != null ? type.Text : "???"; - let accessorType: string; - if (apiItem.ApiKind === Contracts.ApiItemKinds.SetAccessor) { - accessorType = "set"; - } else { - accessorType = "get"; - } - - return `${apiItem.AccessModifier}${$static}${abstract} ${accessorType} ${name}: ${typeString};`; - } - - export function ApiClassPropertyToString(apiItem: Contracts.ApiClassPropertyDto, alias?: string): string { - const name = alias || apiItem.Name; - - const optional = apiItem.IsOptional ? "?" : ""; - const readOnly = apiItem.IsReadonly ? " readonly" : ""; - const abstract = apiItem.IsAbstract ? " abstract" : ""; - const $static = apiItem.IsStatic ? " static" : ""; - - return `${apiItem.AccessModifier}${$static}${abstract}${readOnly} ${name}${optional}: ${apiItem.Type.Text};`; - } - - export function ApiEnumToString(apiItem: Contracts.ApiEnumDto, memberItems: Contracts.ApiEnumMemberDto[], alias?: string): string[] { - const name = alias || apiItem.Name; - const $const = apiItem.IsConst ? "const " : ""; - - // Constructing enum body. - const membersStrings = memberItems.map((memberItem, index, array) => { - // Add an enum name - let memberString = `${GeneratorHelpers.Tab()} ${memberItem.Name}`; - - // Add an enum member value if it exists. - if (memberItem.Value) { - memberString += ` = ${memberItem.Value}`; - } - - // Add a comma if current item is not the last item - if (index !== memberItems.length - 1) { - memberString += ","; - } - - return memberString; - }); - - // Construct enum code output - return [ - `${$const}enum ${name} {`, - ...membersStrings, - "}" - ]; - } - - export function ApiVariableToString(item: Contracts.ApiVariableDto, alias?: string): string { - const name = alias != null ? alias : item.Name; - - return `${item.VariableDeclarationType} ${name}: ${item.Type.Text};`; - } - - export function ClassToString( - apiItem: Contracts.ApiClassDto, - typeParameters?: Contracts.ApiTypeParameterDto[], - alias?: string - ): string { - const name = alias || apiItem.Name; - // Abstract - const abstract = apiItem.IsAbstract ? "abstract " : ""; - - // TypeParameters - const typeParametersString: string = TypeParametersToString(typeParameters); - - // Extends - let extendsString: string; - if (apiItem.Extends != null) { - extendsString = ` extends ${apiItem.Extends.Text}`; - } else { - extendsString = ""; - } - - // Implements - let implementsString: string; - if (apiItem.Implements != null && apiItem.Implements.length > 0) { - implementsString = ` implements ${apiItem.Implements.map(x => x.Text).join(", ")}`; - } else { - implementsString = ""; - } - - return `${abstract}class ${name}${typeParametersString}${extendsString}${implementsString}`; - } - - export function TypeParametersToString(typeParameters?: Contracts.ApiTypeParameterDto[]): string { - if (typeParameters != null && typeParameters.length > 0) { - const params: string[] = typeParameters.map(TypeParameterToString); - return `<${params.join(", ")}>`; - } else { - return ""; - } - } - - export function TypeParameterToString(apiItem: Contracts.ApiTypeParameterDto): string { - const extendsString = apiItem.ConstraintType != null ? ` extends ${apiItem.ConstraintType.Text}` : ""; - const defaultType = apiItem.DefaultType != null ? ` = ${apiItem.DefaultType.Text}` : ""; - - return `${apiItem.Name}${extendsString}${defaultType}`; - } - - // #endregion Stringifiers - - // #region Tables - export function ApiPropertiesToTableString(properties: Contracts.ApiPropertyDto[]): ReferenceDto { - const headers = ["Name", "Type", "Optional"]; - return ApiItemsToTableString(headers, properties, ApiPropertyToTableRow); - } - - export function ApiPropertyToTableRow(property: Contracts.ApiPropertyDto): ReferenceDto { - const parameterTypeDto = TypeDtoToMarkdownString(property.Type); - const isOptionalString = property.IsOptional ? "Yes" : ""; - - return { - Text: [property.Name, parameterTypeDto.Text, isOptionalString], - References: parameterTypeDto.References - }; - } - - export function ApiParametersToTableString(parameters: Contracts.ApiParameterDto[]): ReferenceDto { - const headers = ["Name", "Type", "Optional", "Initial value", "Description"]; - return ApiItemsToTableString(headers, parameters, ApiParameterToTableRow); - } - - // TODO: implement description. - // TODO: implement IsSpread. - export function ApiParameterToTableRow(parameter: Contracts.ApiParameterDto): ReferenceDto { - const parameterTypeDto = TypeDtoToMarkdownString(parameter.Type); - const isOptionalString = parameter.IsOptional ? "Yes" : ""; - const initializerString = parameter.Initializer || ""; - - return { - Text: [parameter.Name, MarkdownGenerator.EscapeString(parameterTypeDto.Text), isOptionalString, initializerString], - References: parameterTypeDto.References - }; - } - - export function ApiTypeParametersTableToString(typeParameters: Contracts.ApiTypeParameterDto[]): ReferenceDto { - const headers = ["Name", "Constraint type", "Default type"]; - return ApiItemsToTableString(headers, typeParameters, ApiTypeParameterToTableRow); - } - - // TODO: add description from @template jsdoc tag. - export function ApiTypeParameterToTableRow(typeParameter: Contracts.ApiTypeParameterDto): ReferenceDto { - let referenceIds: string[] = []; - let constraintType: string = ""; - let defaultType: string = ""; - - if (typeParameter.ConstraintType) { - const parsedConstraintType = TypeDtoToMarkdownString(typeParameter.ConstraintType); - - referenceIds = referenceIds.concat(parsedConstraintType.References); - constraintType = MarkdownGenerator.EscapeString(parsedConstraintType.Text); - } - - if (typeParameter.DefaultType) { - const parsedDefaultType = TypeDtoToMarkdownString(typeParameter.DefaultType); - - referenceIds = referenceIds.concat(parsedDefaultType.References); - defaultType = MarkdownGenerator.EscapeString(parsedDefaultType.Text); - } - - return { - Text: [typeParameter.Name, constraintType, defaultType], - References: referenceIds - }; - } - - export function ApiItemsToTableString( - headers: string[], - items: TApiDto[], - itemToString: (item: TApiDto) => ReferenceDto - ): ReferenceDto { - if (items.length === 0) { - return { - References: [], - Text: [] - }; - } - - const rows = items.map(itemToString); - const content = rows.map(row => row.Text); - const referenceIds = Helpers.Flatten(rows.map(row => row.References)); - - return { - Text: MarkdownGenerator.Table(headers, content, DEFAULT_TABLE_OPTIONS), - References: referenceIds - }; - } - - //#endregion Tables - - // #region Call strings - /** - * Builds call declaration. - * - * Return example: `(arg: TValue): void`. - */ - export function ApiCallToString( - typeParameters?: Contracts.ApiTypeParameterDto[], - parameters?: Contracts.ApiParameterDto[], - returnType?: Contracts.TypeDto - ): string { - // TypeParameters - const typeParametersString = TypeParametersToString(typeParameters); - - // Parameters - let parametersString: string; - if (parameters != null && parameters.length > 0) { - parametersString = parameters - .map(ApiParameterToString) - .join(", "); - } else { - parametersString = ""; - } - - // ReturnType - const returnTypeString = returnType != null ? `: ${returnType.Text}` : ""; - - return `${typeParametersString}(${parametersString})${returnTypeString}`; - } - - /** - * Builds ApiParameter string. - * - * Return example: `arg: TValue`. - */ - export function ApiParameterToString(apiItem: Contracts.ApiParameterDto): string { - // FIXME: `?` and `| undefined` in a single statement. - const initializerString = apiItem.Initializer ? ` = ${apiItem.Initializer}` : ""; - const isOptionalString = apiItem.IsOptional ? "?" : ""; - return `${apiItem.Name}${isOptionalString}: ${apiItem.Type.Text}${initializerString}`; - } - - export function ApiClassConstructorToString( - apiItem: Contracts.ApiClassConstructorDto, - parameters?: Contracts.ApiParameterDto[], - returnType?: Contracts.TypeDto - ): string { - const callString = ApiCallToString(undefined, parameters, returnType); - return `${apiItem.AccessModifier} constructor${callString}`; - } - - /** - * Builds function head from ApiFunction. - * - * Return example: `function foo(arg: TValue): void`. - */ - export function ApiFunctionToString( - apiItem: Contracts.ApiFunctionDto, - typeParameters?: Contracts.ApiTypeParameterDto[], - parameters?: Contracts.ApiParameterDto[], - alias?: string - ): string { - const name = alias || apiItem.Name; - const callString = ApiCallToString(typeParameters, parameters, apiItem.ReturnType); - - return `function ${name}${callString}`; - } - - /** - * Builds construct declaration. - * - * Return example: `new (arg: TValue): void`. - */ - export function ApiConstructToString( - typeParameters?: Contracts.ApiTypeParameterDto[], - parameters?: Contracts.ApiParameterDto[], - returnType?: Contracts.TypeDto - ): string { - const callString = ApiCallToString(typeParameters, parameters, returnType); - - return `new ${callString}`; - } - - /** - * Builds method declaration. - * - * Return example: `someMethod(arg: TValue): void`. - */ - export function ApiMethodToString( - name: string, - typeParameters?: Contracts.ApiTypeParameterDto[], - parameters?: Contracts.ApiParameterDto[], - returnType?: Contracts.TypeDto - ): string { - const callString = ApiCallToString(typeParameters, parameters, returnType); - - return `${name}${callString}`; - } - - /** - * Builds class method declaration. - * - * Return example: `public static SomeMethod(arg: TValue): void`. - */ - export function ApiClassMethodToString( - apiItem: Contracts.ApiClassMethodDto, - typeParameters: Contracts.ApiTypeParameterDto[], - parameters: Contracts.ApiParameterDto[], - alias?: string - ): string { - const name = alias || apiItem.Name; - - const optional = apiItem.IsOptional ? "?" : ""; - const abstract = apiItem.IsAbstract ? " abstract" : ""; - const async = apiItem.IsAsync ? " async" : ""; - const $static = apiItem.IsStatic ? " static" : ""; - const functionHeader = ApiMethodToString(`${name}${optional}`, typeParameters, parameters, apiItem.ReturnType); - - return `${apiItem.AccessModifier}${$static}${abstract}${async} ${functionHeader}`.trim(); - } - - /** - * Build simplified method declaration - * - * Return example: `someMethod(parameter1, parameter2)`. - */ - export function MethodToSimpleString(text: string, parameters: Contracts.ApiParameterDto[]): string { - const parametersString = parameters - .map(x => x.Name) - .join(", "); - - return `${text}(${parametersString})`; - } - - // #endregion Call strings } diff --git a/packages/ts-docs-gen/src/generator.ts b/packages/ts-docs-gen/src/generator.ts index ae8bcfbe..1a2ce462 100644 --- a/packages/ts-docs-gen/src/generator.ts +++ b/packages/ts-docs-gen/src/generator.ts @@ -9,13 +9,12 @@ import { ApiDefaultPlugin } from "./plugins/api-default-plugin"; import { ApiItemReference } from "./contracts/api-item-reference"; import { PluginResult, PluginOptions, GetItemPluginResultHandler } from "./contracts/plugin"; import { FileResult } from "./contracts/file-result"; -import { PluginResultRegistry } from "./contracts/plugin-result-registry"; -import { PluginResultRegistry as PluginResultRegistryClass } from "./registries/plugin-result-registry"; +import { ApiItemReferenceRegistry } from "./registries/api-item-reference-registry"; export class Generator { constructor(private configuration: GeneratorConfiguration) { - this.fileManager = new FileManager(); - this.pluginResultRegistry = new PluginResultRegistryClass(); + this.fileManager = new FileManager(configuration.ExtractedData); + this.pluginResultRegistry = new ApiItemReferenceRegistry(); const { ExtractedData } = this.configuration; for (const entryFile of ExtractedData.EntryFiles) { @@ -29,7 +28,7 @@ export class Generator { this.outputData = this.fileManager.ToFilesOutput(); } - private pluginResultRegistry: PluginResultRegistry; + private pluginResultRegistry: ApiItemReferenceRegistry; private fileManager: FileManager; private outputData: FileResult[]; @@ -69,25 +68,24 @@ export class Generator { private renderApiItem( apiItemReference: ApiItemReference, - apiItem: Contracts.ApiItemDto + apiItem: Contracts.ApiDefinition ): PluginResult { const plugins = this.configuration.PluginManager.GetPluginsByKind(apiItem.ApiKind); const pluginOptions: PluginOptions = { ExtractedData: this.configuration.ExtractedData, Reference: apiItemReference, - ApiItem: apiItem, GetItemPluginResult: this.getItemPluginResult, IsPluginResultExists: reference => this.pluginResultRegistry.Exists(reference) }; for (const plugin of plugins) { if (plugin.CheckApiItem(apiItem)) { - return plugin.Render(pluginOptions); + return plugin.Render(pluginOptions, apiItem); } } const defaultPlugin = new ApiDefaultPlugin(); - return defaultPlugin.Render(pluginOptions); + return defaultPlugin.Render(pluginOptions, apiItem); } } diff --git a/packages/ts-docs-gen/src/index.ts b/packages/ts-docs-gen/src/index.ts index e69de29b..18bceeb2 100644 --- a/packages/ts-docs-gen/src/index.ts +++ b/packages/ts-docs-gen/src/index.ts @@ -0,0 +1,13 @@ +// Abstractions +export * from "./abstractions/base-plugin"; +// ApiItems +export * from "./api-items/api-definition-list"; +export * from "./api-items/api-type-list"; +// Builders +export * from "./builders/generator-configuration-builder"; +// Contracts +import * as Contracts from "./contracts/contracts"; + +export { + Contracts +}; diff --git a/packages/ts-docs-gen/src/plugins/api-callable-plugin.ts b/packages/ts-docs-gen/src/plugins/api-callable-plugin.ts index 6075f2d9..87c02674 100644 --- a/packages/ts-docs-gen/src/plugins/api-callable-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-callable-plugin.ts @@ -1,67 +1,68 @@ -import { Contracts } from "ts-extractor"; +import { Contracts, ExtractDto } from "ts-extractor"; import { MarkdownBuilder } from "@simplrjs/markdown"; import { SupportedApiItemKindType, PluginResult, PluginOptions } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; import { FunctionLikePlugin } from "../abstractions/function-like-plugin"; +import { ApiConstruct } from "../api-items/definitions/api-construct"; +import { ApiItemReference } from "../contracts/api-item-reference"; +import { ApiCall } from "../api-items/definitions/api-call"; +import { ApiMethod } from "../api-items/definitions/api-method"; +import { ApiCallable } from "../api-items/api-callable"; export type CallableApiItem = Contracts.ApiCallDto | Contracts.ApiMethodDto | Contracts.ApiConstructDto; export class ApiCallablePlugin extends FunctionLikePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { return [ - GeneratorHelpers.ApiItemKinds.Construct, - GeneratorHelpers.ApiItemKinds.Call, - GeneratorHelpers.ApiItemKinds.Method + GeneratorHelpers.ApiDefinitionKind.Construct, + GeneratorHelpers.ApiDefinitionKind.Call, + GeneratorHelpers.ApiDefinitionKind.Method ]; } - private resolveItemCode( + private resolveSerializedApiItem( + extractedData: ExtractDto, apiItem: CallableApiItem, - parameters: Contracts.ApiParameterDto[], - typeParameters: Contracts.ApiTypeParameterDto[] - ): string { + reference: ApiItemReference + ): ApiCallable { switch (apiItem.ApiKind) { - case Contracts.ApiItemKinds.Construct: { - return GeneratorHelpers.ApiConstructToString(typeParameters, parameters, apiItem.ReturnType); + case Contracts.ApiDefinitionKind.ConstructorType: + case Contracts.ApiDefinitionKind.Construct: { + return new ApiConstruct(extractedData, apiItem, reference); } - case Contracts.ApiItemKinds.Call: { - return GeneratorHelpers.ApiCallToString(typeParameters, parameters, apiItem.ReturnType); + case Contracts.ApiDefinitionKind.Call: { + return new ApiCall(extractedData, apiItem, reference); } - case Contracts.ApiItemKinds.Method: { - return GeneratorHelpers.ApiMethodToString(apiItem.Name, typeParameters, parameters, apiItem.ReturnType); + case Contracts.ApiDefinitionKind.Method: { + return new ApiMethod(extractedData, apiItem, reference); } } } - public Render(options: PluginOptions): PluginResult { + public Render(options: PluginOptions, apiItem: CallableApiItem): PluginResult { + const serializedApiItem = this.resolveSerializedApiItem(options.ExtractedData, apiItem, options.Reference); + const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference }; - // ApiParameters - const apiParameters = - GeneratorHelpers.GetApiItemsFromReference(options.ApiItem.Parameters, options.ExtractedData); - // ApiTypeParameters - const apiTypeParameters = - GeneratorHelpers.GetApiItemsFromReference(options.ApiItem.TypeParameters, options.ExtractedData); - pluginResult.Result = new MarkdownBuilder() - .Code(this.resolveItemCode(options.ApiItem, apiParameters, apiTypeParameters), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Code(serializedApiItem.ToInlineText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); // TypeParameters - const typeParametersResult = this.RenderTypeParameters(apiTypeParameters); + const typeParametersResult = this.RenderTypeParameters(options.ExtractedData, serializedApiItem.TypeParameters); GeneratorHelpers.MergePluginResultData(pluginResult, typeParametersResult); // Parameters - const parametersResult = this.RenderParameters(apiParameters); + const parametersResult = this.RenderParameters(options.ExtractedData, serializedApiItem.Parameters); GeneratorHelpers.MergePluginResultData(pluginResult, parametersResult); // ReturnType - const returnTypeResult = this.RenderReturnType(options.ApiItem.ReturnType); + const returnTypeResult = this.RenderReturnType(options.ExtractedData, serializedApiItem.ReturnType); GeneratorHelpers.MergePluginResultData(pluginResult, returnTypeResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-class-accessor-plugin.ts b/packages/ts-docs-gen/src/plugins/api-class-accessor-plugin.ts index 607b3437..a90e1636 100644 --- a/packages/ts-docs-gen/src/plugins/api-class-accessor-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-class-accessor-plugin.ts @@ -1,78 +1,48 @@ -import { Contracts, ExtractDto } from "ts-extractor"; +import { Contracts } from "ts-extractor"; import { MarkdownBuilder } from "@simplrjs/markdown"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; import { BasePlugin } from "../abstractions/base-plugin"; +import { ApiAccessor } from "../api-items/definitions/api-accessor"; export type Kind = Contracts.ApiSetAccessorDto | Contracts.ApiGetAccessorDto; export class ApiClassAccessorPlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { return [ - GeneratorHelpers.ApiItemKinds.GetAccessor, - GeneratorHelpers.ApiItemKinds.SetAccessor, + GeneratorHelpers.ApiDefinitionKind.GetAccessor, + GeneratorHelpers.ApiDefinitionKind.SetAccessor, ]; } - private getHeading(data: PluginOptions): string { - let accessorType: string; - if (data.ApiItem.ApiKind === Contracts.ApiItemKinds.SetAccessor) { - accessorType = "set"; - } else { - accessorType = "get"; - } + public Render(options: PluginOptions, apiItem: Kind): PluginResult { + const serializedApiItem = new ApiAccessor(options.ExtractedData, apiItem, options.Reference); - return `${accessorType} ${data.Reference.Alias}`; - } - - private resolveType(apiItem: Kind, extractedData: ExtractDto): Contracts.TypeDto | undefined { - let type: Contracts.TypeDto | undefined; - if (apiItem.ApiKind === Contracts.ApiItemKinds.GetAccessor) { - // GetAccessor - - type = apiItem.Type; - } else if (apiItem.Parameter != null) { - // SetAccessor - - const apiParameter = extractedData.Registry[apiItem.Parameter.Ids[0]] as Contracts.ApiParameterDto; - if (apiParameter != null) { - type = apiParameter.Type; - } - } - - return type; - } - - public Render(options: PluginOptions): PluginResult { - const heading = this.getHeading(options); - const type = this.resolveType(options.ApiItem, options.ExtractedData); + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { ApiItemId: options.Reference.Id, Heading: heading } - ] + ], + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(GeneratorHelpers.ApiAccessorToString( - options.ApiItem, - type, - options.Reference.Alias - ), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); // Type - const typeResult = this.RenderType(type); + const typeResult = this.RenderType(options.ExtractedData, serializedApiItem.Type); GeneratorHelpers.MergePluginResultData(pluginResult, typeResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-class-constructor-plugin.ts b/packages/ts-docs-gen/src/plugins/api-class-constructor-plugin.ts index f90ef37d..5ed18315 100644 --- a/packages/ts-docs-gen/src/plugins/api-class-constructor-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-class-constructor-plugin.ts @@ -4,40 +4,40 @@ import { MarkdownBuilder } from "@simplrjs/markdown"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; import { FunctionLikePlugin } from "../abstractions/function-like-plugin"; +import { ApiClassConstructor } from "../api-items/definitions/api-class-constructor"; export class ApiClassConstructorPlugin extends FunctionLikePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.ClassConstructor]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.ClassConstructor]; } - public Render(options: PluginOptions): PluginResult { - // ApiParameters - const apiParameters = GeneratorHelpers - .GetApiItemsFromReference(options.ApiItem.Parameters, options.ExtractedData); + public Render(options: PluginOptions, apiItem: Contracts.ApiClassConstructorDto): PluginResult { + const serializedApiItem = new ApiClassConstructor(options.ExtractedData, apiItem, options.Reference); - const heading = GeneratorHelpers.MethodToSimpleString("constructor", apiParameters); + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { Heading: heading, ApiItemId: options.Reference.Id } - ] + ], + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(GeneratorHelpers.ApiClassConstructorToString(options.ApiItem, apiParameters), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); // Parameters - const parametersResult = this.RenderParameters(apiParameters); + const parametersResult = this.RenderParameters(options.ExtractedData, serializedApiItem.Parameters); GeneratorHelpers.MergePluginResultData(pluginResult, parametersResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-class-method-plugin.ts b/packages/ts-docs-gen/src/plugins/api-class-method-plugin.ts index 5da07cf0..a98b00fe 100644 --- a/packages/ts-docs-gen/src/plugins/api-class-method-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-class-method-plugin.ts @@ -4,60 +4,52 @@ import { MarkdownBuilder } from "@simplrjs/markdown"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; import { FunctionLikePlugin } from "../abstractions/function-like-plugin"; +import { ApiClassMethod } from "../api-items/definitions/api-class-method"; export class ApiClassMethodPlugin extends FunctionLikePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.ClassMethod]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.ClassMethod]; } - public CheckApiItem(item: Contracts.ApiItemDto): boolean { + public CheckApiItem(item: Contracts.ApiDefinition): boolean { return true; } - public Render(options: PluginOptions): PluginResult { - // Parameters - const apiParameters = GeneratorHelpers - .GetApiItemsFromReference(options.ApiItem.Parameters, options.ExtractedData); - // TypeParameters - const apiTypeParameters = GeneratorHelpers - .GetApiItemsFromReference(options.ApiItem.TypeParameters, options.ExtractedData); + public Render(options: PluginOptions, apiItem: Contracts.ApiClassMethodDto): PluginResult { + const serializedApiItem = new ApiClassMethod(options.ExtractedData, apiItem, options.Reference); - const heading = GeneratorHelpers.MethodToSimpleString(options.Reference.Alias, apiParameters); + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { Heading: heading, ApiItemId: options.Reference.Id } - ] + ], + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(GeneratorHelpers.ApiClassMethodToString( - options.ApiItem, - apiTypeParameters, - apiParameters, - options.Reference.Alias - ), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); // TypeParameters - const typeParametersResult = this.RenderTypeParameters(apiTypeParameters); + const typeParametersResult = this.RenderTypeParameters(options.ExtractedData, serializedApiItem.TypeParameters); GeneratorHelpers.MergePluginResultData(pluginResult, typeParametersResult); // Parameters - const parametersResult = this.RenderParameters(apiParameters); + const parametersResult = this.RenderParameters(options.ExtractedData, serializedApiItem.Parameters); GeneratorHelpers.MergePluginResultData(pluginResult, parametersResult); // ReturnType - const returnTypeResult = this.RenderReturnType(options.ApiItem.ReturnType); + const returnTypeResult = this.RenderReturnType(options.ExtractedData, serializedApiItem.ReturnType); GeneratorHelpers.MergePluginResultData(pluginResult, returnTypeResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-class-plugin.ts b/packages/ts-docs-gen/src/plugins/api-class-plugin.ts index 443c0227..166a0a57 100644 --- a/packages/ts-docs-gen/src/plugins/api-class-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-class-plugin.ts @@ -1,71 +1,85 @@ import { Contracts } from "ts-extractor"; import { MarkdownBuilder } from "@simplrjs/markdown"; -import * as path from "path"; import { GeneratorHelpers } from "../generator-helpers"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { ContainerPlugin, ContainerMembersKindsGroup } from "../abstractions/container-plugin"; +import { ApiClass } from "../api-items/definitions/api-class"; export class ApiClassPlugin extends ContainerPlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Class]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Class]; } - public Render(data: PluginOptions): PluginResult { - const heading = path.basename(data.ApiItem.Name, path.extname(data.ApiItem.Name)); + public static readonly MemberKindsList: ContainerMembersKindsGroup[] = [ + { + Heading: "Index", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Index] + }, + { + Heading: "Constructor", + Kinds: [GeneratorHelpers.ApiDefinitionKind.ClassConstructor] + }, + { + Heading: "Methods", + Kinds: [GeneratorHelpers.ApiDefinitionKind.ClassMethod] + }, + { + Heading: "Properties", + Kinds: [ + GeneratorHelpers.ApiDefinitionKind.ClassProperty, + GeneratorHelpers.ApiDefinitionKind.GetAccessor, + GeneratorHelpers.ApiDefinitionKind.SetAccessor, + ] + }, + { + Heading: "Other", + Kinds: [ + GeneratorHelpers.ApiDefinitionKind.Any + ] + } + ]; + + public Render(options: PluginOptions, apiItem: Contracts.ApiClassDto): PluginResult { + const serializedApiItem = new ApiClass(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: data.ApiItem, - Reference: data.Reference, - Headings: [ - { - Heading: heading, - ApiItemId: data.Reference.Id - } - ] + ApiItem: apiItem, + Reference: options.Reference, + UsedReferences: [options.Reference.Id] }; - // Resolve ApiItems from references. - const typeParameters = GeneratorHelpers - .GetApiItemsFromReference(data.ApiItem.TypeParameters, data.ExtractedData); - // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 1) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(data.ApiItem)) - .Code(GeneratorHelpers.ClassToString( - data.ApiItem, - typeParameters, - data.Reference.Alias - ), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); + // TypeParameters + const typeParametersResult = this.RenderTypeParameters(options.ExtractedData, serializedApiItem.TypeParameters); + GeneratorHelpers.MergePluginResultData(pluginResult, typeParametersResult); + // ApiMembers - const memberKindsList: ContainerMembersKindsGroup[] = [ - { - Heading: "Index", - Kinds: [Contracts.ApiItemKinds.Index] - }, - { - Heading: "Constructor", - Kinds: [Contracts.ApiItemKinds.ClassConstructor] - }, - { - Heading: "Methods", - Kinds: [Contracts.ApiItemKinds.ClassMethod] - }, - { - Heading: "Properties", - Kinds: [ - Contracts.ApiItemKinds.ClassProperty, - Contracts.ApiItemKinds.GetAccessor, - Contracts.ApiItemKinds.SetAccessor, - ] - } - ]; - const members = this.RenderMembersGroups(memberKindsList, data); - GeneratorHelpers.MergePluginResultData(pluginResult, members); + const membersResult = this.RenderMemberGroups(options, ApiClassPlugin.MemberKindsList, serializedApiItem.Members); + + // Treat members' headings as members of class heading. + const membersHeadings = membersResult.Headings; + + // Clearing headings from members result to prevent repeated inclusion. + membersResult.Headings = []; + + pluginResult.Headings.push({ + Heading: heading, + ApiItemId: options.Reference.Id, + Members: membersHeadings + }); + + // Merging rest of the members result + GeneratorHelpers.MergePluginResultData(pluginResult, membersResult); return pluginResult; } diff --git a/packages/ts-docs-gen/src/plugins/api-class-property-plugin.ts b/packages/ts-docs-gen/src/plugins/api-class-property-plugin.ts index 36144af9..742e6fee 100644 --- a/packages/ts-docs-gen/src/plugins/api-class-property-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-class-property-plugin.ts @@ -4,38 +4,39 @@ import { MarkdownBuilder } from "@simplrjs/markdown"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; import { BasePlugin } from "../abstractions/base-plugin"; +import { ApiClassProperty } from "../api-items/definitions/api-class-property"; export class ApiClassPropertyPlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.ClassProperty]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.ClassProperty]; } - public Render(options: PluginOptions): PluginResult { - const heading = options.Reference.Alias; + public Render(options: PluginOptions, apiItem: Contracts.ApiClassPropertyDto): PluginResult { + const serializedApiItem = new ApiClassProperty(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { ApiItemId: options.Reference.Id, Heading: heading } - ] + ], + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(GeneratorHelpers.ApiClassPropertyToString( - options.ApiItem, - options.Reference.Alias - ), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); - const typeResult = this.RenderType(options.ApiItem.Type); + const typeResult = this.RenderType(options.ExtractedData, serializedApiItem.Type); GeneratorHelpers.MergePluginResultData(pluginResult, typeResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-default-plugin.ts b/packages/ts-docs-gen/src/plugins/api-default-plugin.ts index 78e9a57d..45e5a607 100644 --- a/packages/ts-docs-gen/src/plugins/api-default-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-default-plugin.ts @@ -4,32 +4,36 @@ import { MarkdownBuilder } from "@simplrjs/markdown"; import { PluginOptions, PluginResult, SupportedApiItemKindType } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; import { BasePlugin } from "../abstractions/base-plugin"; +import { ApiDefinitionDefault } from "../api-items/api-definition-default"; -export class ApiDefaultPlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Any]; +export class ApiDefaultPlugin extends BasePlugin { + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Any]; } - public Render(options: PluginOptions): PluginResult { - const heading = `${options.ApiItem.ApiKind}: ${options.Reference.Alias}`; + public Render(options: PluginOptions, apiItem: Contracts.ApiDefinition): PluginResult { + const serializedApiItem = new ApiDefinitionDefault(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { Heading: heading, ApiItemId: options.Reference.Id } - ] + ], + UsedReferences: [options.Reference.Id] }; pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Bold(`Warning: unsupported api item kind ${options.ApiItem.ApiKind}!`) + .Text(md => md.Bold(`Warning: unsupported api item kind ${md.Italic(apiItem.ApiKind)}!`)) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) + .Text(this.RenderApiItemMetadata(apiItem)) .GetOutput(); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-enum-plugin.ts b/packages/ts-docs-gen/src/plugins/api-enum-plugin.ts index 63148d96..9542076e 100644 --- a/packages/ts-docs-gen/src/plugins/api-enum-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-enum-plugin.ts @@ -4,58 +4,53 @@ import { MarkdownGenerator, MarkdownBuilder } from "@simplrjs/markdown"; import { GeneratorHelpers } from "../generator-helpers"; import { SupportedApiItemKindType, PluginResult, PluginOptions } from "../contracts/plugin"; import { BasePlugin } from "../abstractions/base-plugin"; +import { ApiEnum } from "../api-items/definitions/api-enum"; +import { ApiEnumMember } from "../api-items/definitions/api-enum-member"; export class ApiEnumPlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Enum]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Enum]; } - public CheckApiItem(item: Contracts.ApiItemDto): boolean { + public CheckApiItem(item: Contracts.ApiEnumDto): boolean { return true; } - private renderEnumTable(members: Contracts.ApiEnumMemberDto[]): string[] { + private renderEnumTable(members: ApiEnumMember[]): string[] { // Table header. const header = ["Name", "Value", "Description"]; - const content = members.map(x => [x.Name, x.Value, x.Metadata.DocumentationComment]); + const content = members.map(x => [x.ApiItem.Name, x.ApiItem.Value, x.ApiItem.Metadata.DocumentationComment]); return MarkdownGenerator.Table(header, content, { removeColumnIfEmpty: true }); } - public Render(options: PluginOptions): PluginResult { - const heading: string = options.Reference.Alias; + public Render(options: PluginOptions, apiItem: Contracts.ApiEnumDto): PluginResult { + const serializedApiItem = new ApiEnum(options.ExtractedData, apiItem, options.Reference); + + const heading: string = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { Heading: heading, ApiItemId: options.Reference.Id } - ] + ], + UsedReferences: [options.Reference.Id] }; - // Enum members - const enumMembers = GeneratorHelpers.GetApiItemsFromReference( - options.ApiItem.Members, - options.ExtractedData - ); - pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) + .Text(this.RenderApiItemMetadata(apiItem)) .EmptyLine() - .Code(GeneratorHelpers.ApiEnumToString( - options.ApiItem, - enumMembers, - options.Reference.Alias - ), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .EmptyLine() .Bold("Members") .EmptyLine() - .Text(this.renderEnumTable(enumMembers)) + .Text(this.renderEnumTable(serializedApiItem.EnumMembers)) .GetOutput(); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-function-plugin.ts b/packages/ts-docs-gen/src/plugins/api-function-plugin.ts index bee15bf0..ff7a76b6 100644 --- a/packages/ts-docs-gen/src/plugins/api-function-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-function-plugin.ts @@ -4,56 +4,48 @@ import { MarkdownBuilder } from "@simplrjs/markdown"; import { GeneratorHelpers } from "../generator-helpers"; import { SupportedApiItemKindType, PluginResult, PluginOptions } from "../contracts/plugin"; import { FunctionLikePlugin } from "../abstractions/function-like-plugin"; +import { ApiFunction } from "../api-items/definitions/api-function"; export class ApiFunctionPlugin extends FunctionLikePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Function]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Function]; } - public Render(options: PluginOptions): PluginResult { - // Parameters - const apiParameters = GeneratorHelpers - .GetApiItemsFromReference(options.ApiItem.Parameters, options.ExtractedData); - // TypeParameters - const apiTypeParameters = GeneratorHelpers - .GetApiItemsFromReference(options.ApiItem.TypeParameters, options.ExtractedData); + public Render(options: PluginOptions, apiItem: Contracts.ApiFunctionDto): PluginResult { + const serializedApiItem = new ApiFunction(options.ExtractedData, apiItem, options.Reference); - const heading = GeneratorHelpers.MethodToSimpleString(options.Reference.Alias, apiParameters); + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { Heading: heading, ApiItemId: options.Reference.Id } - ] + ], + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(GeneratorHelpers.ApiFunctionToString( - options.ApiItem, - apiTypeParameters, - apiParameters, - options.Reference.Alias - ), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); // TypeParameters - const typeParametersResult = this.RenderTypeParameters(apiTypeParameters); + const typeParametersResult = this.RenderTypeParameters(options.ExtractedData, serializedApiItem.TypeParameters); GeneratorHelpers.MergePluginResultData(pluginResult, typeParametersResult); // Parameters - const parametersResult = this.RenderParameters(apiParameters); + const parametersResult = this.RenderParameters(options.ExtractedData, serializedApiItem.Parameters); GeneratorHelpers.MergePluginResultData(pluginResult, parametersResult); // ReturnType - const returnTypeResult = this.RenderReturnType(options.ApiItem.ReturnType); + const returnTypeResult = this.RenderReturnType(options.ExtractedData, serializedApiItem.ReturnType); GeneratorHelpers.MergePluginResultData(pluginResult, returnTypeResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-index-plugin.ts b/packages/ts-docs-gen/src/plugins/api-index-plugin.ts index d8b2b228..840a66f7 100644 --- a/packages/ts-docs-gen/src/plugins/api-index-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-index-plugin.ts @@ -4,41 +4,36 @@ import { MarkdownBuilder, MarkdownGenerator as md } from "@simplrjs/markdown"; import { SupportedApiItemKindType, PluginResult, PluginOptions } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; import { BasePlugin } from "../abstractions/base-plugin"; +import { ApiIndex } from "../api-items/definitions/api-index"; export class ApiIndexPlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Index]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Index]; } - public Render(options: PluginOptions): PluginResult { + public Render(options: PluginOptions, apiItem: Contracts.ApiIndexDto): PluginResult { + const serializedApiItem = new ApiIndex(options.ExtractedData, apiItem, options.Reference); + const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference }; - // Parameter - const parameter = options.ExtractedData.Registry[options.ApiItem.Parameter] as Contracts.ApiParameterDto; + + const parameter = serializedApiItem.Parameter; // Types - const parameterType = GeneratorHelpers.TypeDtoToMarkdownString(parameter.Type); - const indexType = GeneratorHelpers.TypeDtoToMarkdownString(options.ApiItem.Type); - GeneratorHelpers.MergePluginResultData(pluginResult, { - UsedReferences: [ - ...parameterType.References, - ...indexType.References - ] - }); - - // Header - const indexDeclarationString = GeneratorHelpers.ApiIndexToString(parameter, options.ApiItem.Type, options.ApiItem.IsReadonly); - const builder = new MarkdownBuilder() - .Code(indexDeclarationString, GeneratorHelpers.DEFAULT_CODE_OPTIONS) - .EmptyLine(); - - pluginResult.Result = builder + const parameterTypeString = parameter.Type + .ToInlineText(this.RenderReferences(options.ExtractedData, pluginResult.UsedReferences)); + const typeString = serializedApiItem.Type + .ToInlineText(this.RenderReferences(options.ExtractedData, pluginResult.UsedReferences)); + + pluginResult.Result = new MarkdownBuilder() + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .EmptyLine() .UnorderedList([ - `${md.Italic("Parameter")} ${md.InlineCode(parameter.Name)} - ${parameterType.Text}`, - `${md.Italic("Type")} ${indexType.Text}` + `${md.Italic("Parameter")} ${md.InlineCode(parameter.Name)} - ${parameterTypeString}`, + `${md.Italic("Type")} ${typeString}` ]) .GetOutput(); diff --git a/packages/ts-docs-gen/src/plugins/api-interface-plugin.ts b/packages/ts-docs-gen/src/plugins/api-interface-plugin.ts index 2d008c14..2556b98e 100644 --- a/packages/ts-docs-gen/src/plugins/api-interface-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-interface-plugin.ts @@ -1,29 +1,45 @@ -import { Contracts } from "ts-extractor"; -import { MarkdownBuilder, MarkdownGenerator } from "@simplrjs/markdown"; +import { Contracts, ExtractDto } from "ts-extractor"; +import { MarkdownBuilder } from "@simplrjs/markdown"; import { SupportedApiItemKindType, PluginResult, PluginOptions, - GetItemPluginResultHandler, PluginResultData } from "../contracts/plugin"; import { GeneratorHelpers } from "../generator-helpers"; -import { ApiItemReference } from "../contracts/api-item-reference"; -import { BasePlugin } from "../abstractions/base-plugin"; - -interface ExtractedItemDto { - Reference: ApiItemReference; - ApiItem: TApiItemDto; -} - -export class ApiInterfacePlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Interface]; +import { ApiInterface } from "../api-items/definitions/api-interface"; +import { ApiTypes } from "../api-items/api-type-list"; +import { ContainerPlugin, ContainerMembersKindsGroup } from "../abstractions/container-plugin"; +import { ApiDefinitions } from "../api-items/api-definition-list"; +import { ApiProperty } from "../api-items/definitions/api-property"; + +export class ApiInterfacePlugin extends ContainerPlugin { + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Interface]; } - private renderConstraintTypes(apiItem: Contracts.ApiInterfaceDto): PluginResultData | undefined { - if (apiItem.Extends.length === 0) { + public static readonly MemberKindsList: ContainerMembersKindsGroup[] = [ + { + Heading: "Construct", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Construct] + }, + { + Heading: "Call", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Call] + }, + { + Heading: "Index", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Index] + }, + { + Heading: "Method", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Method] + } + ]; + + private renderConstraintTypes(extractedData: ExtractDto, extendsItems: ApiTypes[]): PluginResultData | undefined { + if (extendsItems.length === 0) { return undefined; } @@ -31,14 +47,12 @@ export class ApiInterfacePlugin extends BasePlugin { .EmptyLine() .Bold("Extends"); - const references = []; + const references: string[] = []; - for (const type of apiItem.Extends) { - const typeDto = GeneratorHelpers.TypeDtoToMarkdownString(type); - references.push(...typeDto.References); + for (const type of extendsItems) { builder .EmptyLine() - .Text(typeDto.Text); + .Text(type.ToInlineText(this.RenderReferences(extractedData, references))); } return { @@ -48,138 +62,80 @@ export class ApiInterfacePlugin extends BasePlugin { }; } - private renderPropertyMembers(memberItems: ExtractedItemDto[]): PluginResultData | undefined { - const apiItems = memberItems.filter>( - this.isReferenceOfApiItemKind.bind(undefined, Contracts.ApiItemKinds.Property) - ).map(x => x.ApiItem); + private renderPropertyMembers(extractedData: ExtractDto, members: ApiDefinitions[]): PluginResultData | undefined { + const properties: ApiProperty[] = members + .filter((x): x is ApiProperty => x.ApiItem.ApiKind === Contracts.ApiDefinitionKind.Property); - if (apiItems.length === 0) { + if (properties.length === 0) { return undefined; } + const pluginResult = GeneratorHelpers.GetDefaultPluginResultData(); - const table = GeneratorHelpers.ApiPropertiesToTableString(apiItems); - const builder = new MarkdownBuilder() + const headers = ["Name", "Type", "Optional", "Description"]; + const content = properties + .map(x => [ + x.Name, + x.Type.ToInlineText(this.RenderReferences(extractedData, pluginResult.UsedReferences)), + String(x.ApiItem.IsOptional), + x.ApiItem.Metadata.DocumentationComment + ]); + + pluginResult.Result = new MarkdownBuilder() .EmptyLine() .Bold("Properties") .EmptyLine() - .Text(table.Text); - - return { - ...GeneratorHelpers.GetDefaultPluginResultData(), - UsedReferences: table.References, - Result: builder.GetOutput(), - }; - } - - private isReferenceOfApiItemKind( - itemKind: Contracts.ApiItemKinds, - extractedItem: ExtractedItemDto - ): extractedItem is ExtractedItemDto { - return extractedItem.ApiItem.ApiKind === itemKind; - } - - private renderMemberItemsGroup( - title: string, - apiItemKind: Contracts.ApiItemKinds, - memberItems: ExtractedItemDto[], - getPluginResult: GetItemPluginResultHandler - ): PluginResultData | undefined { - const items = memberItems.filter(this.isReferenceOfApiItemKind.bind(undefined, apiItemKind)); - - if (items.length === 0) { - return undefined; - } - - const pluginResult = GeneratorHelpers.GetDefaultPluginResultData(); - pluginResult.Result.push("", MarkdownGenerator.Header(title, 4)); - - for (const item of items) { - pluginResult.Result.push(""); - const itemPluginResult = getPluginResult(item.Reference); - - GeneratorHelpers.MergePluginResultData(pluginResult, itemPluginResult); - } + .Table(headers, content, GeneratorHelpers.DEFAULT_TABLE_OPTIONS) + .GetOutput(); return pluginResult; } - public Render(options: PluginOptions): PluginResult { - const heading = options.Reference.Alias; + public Render(options: PluginOptions, apiItem: Contracts.ApiInterfaceDto): PluginResult { + const serializedApiItem = new ApiInterface(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { ApiItemId: options.Reference.Id, Heading: heading } - ] + ], + UsedReferences: [options.Reference.Id] }; - const memberReferences = GeneratorHelpers.GetApiItemReferences(options.ExtractedData, options.ApiItem.Members); - const memberItems = memberReferences.map(itemReference => ({ - Reference: itemReference, - ApiItem: options.ExtractedData.Registry[itemReference.Id] - })); - - const interfaceString = GeneratorHelpers.ApiInterfaceToString(options.ApiItem, options.ExtractedData); - const builder = new MarkdownBuilder() + pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(interfaceString, GeneratorHelpers.DEFAULT_CODE_OPTIONS); - - pluginResult.Result = builder.GetOutput(); + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .GetOutput(); // Type parameters - const apiTypeParameters = GeneratorHelpers - .GetApiItemsFromReference(options.ApiItem.TypeParameters, options.ExtractedData); - const typeParametersResult = this.RenderTypeParameters(apiTypeParameters); + const typeParametersResult = this.RenderTypeParameters(options.ExtractedData, serializedApiItem.TypeParameters); GeneratorHelpers.MergePluginResultData(pluginResult, typeParametersResult); // Constraint types - const constraintTypesResult = this.renderConstraintTypes(options.ApiItem); + const constraintTypesResult = this.renderConstraintTypes(options.ExtractedData, serializedApiItem.Extends); GeneratorHelpers.MergePluginResultData(pluginResult, constraintTypesResult); - // Construct items - const constructMembersResult = this.renderMemberItemsGroup( - "Construct", - Contracts.ApiItemKinds.Construct, - memberItems, - options.GetItemPluginResult - ); - GeneratorHelpers.MergePluginResultData(pluginResult, constructMembersResult); - - // Call items - const callMembersResult = this.renderMemberItemsGroup( - "Call", - Contracts.ApiItemKinds.Call, - memberItems, - options.GetItemPluginResult - ); - GeneratorHelpers.MergePluginResultData(pluginResult, callMembersResult); - - // Index items - const indexMembersResult = this.renderMemberItemsGroup( - "Index signatures", - Contracts.ApiItemKinds.Index, - memberItems, - options.GetItemPluginResult - ); - GeneratorHelpers.MergePluginResultData(pluginResult, indexMembersResult); - - // Method items - const methodMembersResult = this.renderMemberItemsGroup( - "Methods", - Contracts.ApiItemKinds.Method, - memberItems, - options.GetItemPluginResult + // Members + const membersResult = this.RenderMemberGroups( + options, + ApiInterfacePlugin.MemberKindsList, + serializedApiItem.Members, + { + IncludeHr: false, + StartingHeadingLevel: 4 + } ); - GeneratorHelpers.MergePluginResultData(pluginResult, methodMembersResult); + GeneratorHelpers.MergePluginResultData(pluginResult, membersResult); // Property items - const propertyMembersResult = this.renderPropertyMembers(memberItems); + const propertyMembersResult = this.renderPropertyMembers(options.ExtractedData, serializedApiItem.Members); GeneratorHelpers.MergePluginResultData(pluginResult, propertyMembersResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-namespace-plugin.ts b/packages/ts-docs-gen/src/plugins/api-namespace-plugin.ts index a20f0c92..e9d2d783 100644 --- a/packages/ts-docs-gen/src/plugins/api-namespace-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-namespace-plugin.ts @@ -1,70 +1,92 @@ import { Contracts } from "ts-extractor"; import { MarkdownBuilder } from "@simplrjs/markdown"; -import * as path from "path"; import { GeneratorHelpers } from "../generator-helpers"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { ContainerPlugin, ContainerMembersKindsGroup } from "../abstractions/container-plugin"; +import { ApiNamespace } from "../api-items/definitions/api-namespace"; export class ApiNamespacePlugin extends ContainerPlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Namespace]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [ + GeneratorHelpers.ApiDefinitionKind.Namespace, + GeneratorHelpers.ApiDefinitionKind.ImportNamespace + ]; } - public Render(data: PluginOptions): PluginResult { - const heading = path.basename(data.ApiItem.Name, path.extname(data.ApiItem.Name)); + public static readonly MemberKindsList: ContainerMembersKindsGroup[] = [ + { + Heading: "Functions", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Function] + }, + { + Heading: "Interfaces", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Interface] + }, + { + Heading: "Types", + Kinds: [GeneratorHelpers.ApiDefinitionKind.TypeAlias] + }, + { + Heading: "Enums", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Enum] + }, + { + Heading: "Classes", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Class] + }, + { + Heading: "Namespaces", + Kinds: [ + GeneratorHelpers.ApiDefinitionKind.Namespace, + GeneratorHelpers.ApiDefinitionKind.ImportNamespace + ] + }, + { + Heading: "Variables", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Variable] + }, + { + Heading: "Other", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Any] + } + ]; + + public Render(options: PluginOptions, apiItem: Contracts.ApiNamespaceDto): PluginResult { + const serializedApiItem = new ApiNamespace(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: data.ApiItem, - Reference: data.Reference, - Headings: [ - { - Heading: heading, - ApiItemId: data.Reference.Id - } - ] + ApiItem: apiItem, + Reference: options.Reference, + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 1) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(data.ApiItem)) + .Text(this.RenderApiItemMetadata(apiItem)) .GetOutput(); // Members - const memberKindsList: ContainerMembersKindsGroup[] = [ - { - Heading: "Functions", - Kinds: [Contracts.ApiItemKinds.Function] - }, - { - Heading: "Interfaces", - Kinds: [Contracts.ApiItemKinds.Interface] - }, - { - Heading: "Types", - Kinds: [Contracts.ApiItemKinds.Type] - }, - { - Heading: "Enums", - Kinds: [Contracts.ApiItemKinds.Enum] - }, - { - Heading: "Classes", - Kinds: [Contracts.ApiItemKinds.Class] - }, - { - Heading: "Namespaces", - Kinds: [Contracts.ApiItemKinds.Namespace] - }, - { - Heading: "Variables", - Kinds: [Contracts.ApiItemKinds.Variable] - } - ]; - const renderedMembers = this.RenderMembersGroups(memberKindsList, data); - GeneratorHelpers.MergePluginResultData(pluginResult, renderedMembers); + const membersResult = this.RenderMemberGroups(options, ApiNamespacePlugin.MemberKindsList, serializedApiItem.Members); + + // Treat members' headings as members of namespace heading. + const membersHeadings = membersResult.Headings; + + // Clearing headings from members result to prevent repeated inclusion. + membersResult.Headings = []; + + pluginResult.Headings.push({ + Heading: heading, + ApiItemId: options.Reference.Id, + Members: membersHeadings + }); + + // Merging rest of the members result + GeneratorHelpers.MergePluginResultData(pluginResult, membersResult); return pluginResult; } diff --git a/packages/ts-docs-gen/src/plugins/api-source-file-plugin.ts b/packages/ts-docs-gen/src/plugins/api-source-file-plugin.ts index fbc6c42f..acf866a4 100644 --- a/packages/ts-docs-gen/src/plugins/api-source-file-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-source-file-plugin.ts @@ -1,70 +1,89 @@ import { Contracts } from "ts-extractor"; import { MarkdownBuilder } from "@simplrjs/markdown"; -import * as path from "path"; import { GeneratorHelpers } from "../generator-helpers"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { ContainerPlugin, ContainerMembersKindsGroup } from "../abstractions/container-plugin"; +import { ApiSourceFile } from "../api-items/definitions/api-source-file"; export class ApiSourceFilePlugin extends ContainerPlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.SourceFile]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.SourceFile]; } - public Render(data: PluginOptions): PluginResult { - const heading = path.basename(data.ApiItem.Name, path.extname(data.ApiItem.Name)); + public static readonly MemberKindsList: ContainerMembersKindsGroup[] = [ + { + Heading: "Functions", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Function] + }, + { + Heading: "Interfaces", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Interface] + }, + { + Heading: "Types", + Kinds: [GeneratorHelpers.ApiDefinitionKind.TypeAlias] + }, + { + Heading: "Enums", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Enum] + }, + { + Heading: "Classes", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Class] + }, + { + Heading: "Namespaces", + Kinds: [ + GeneratorHelpers.ApiDefinitionKind.Namespace, + GeneratorHelpers.ApiDefinitionKind.ImportNamespace + ] + }, + { + Heading: "Variables", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Variable] + }, + { + Heading: "Other", + Kinds: [GeneratorHelpers.ApiDefinitionKind.Any] + } + ]; + + public Render(options: PluginOptions, apiItem: Contracts.ApiSourceFileDto): PluginResult { + const serializedApiItem = new ApiSourceFile(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: data.ApiItem, - Reference: data.Reference, - Headings: [ - { - Heading: heading, - ApiItemId: data.Reference.Id - } - ] + ApiItem: apiItem, + Reference: options.Reference, + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 1) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(data.ApiItem)) + .Text(this.RenderApiItemMetadata(apiItem)) .GetOutput(); // Members - const memberKindsList: ContainerMembersKindsGroup[] = [ - { - Heading: "Functions", - Kinds: [Contracts.ApiItemKinds.Function] - }, - { - Heading: "Interfaces", - Kinds: [Contracts.ApiItemKinds.Interface] - }, - { - Heading: "Types", - Kinds: [Contracts.ApiItemKinds.Type] - }, - { - Heading: "Enums", - Kinds: [Contracts.ApiItemKinds.Enum] - }, - { - Heading: "Classes", - Kinds: [Contracts.ApiItemKinds.Class] - }, - { - Heading: "Namespaces", - Kinds: [Contracts.ApiItemKinds.Namespace] - }, - { - Heading: "Variables", - Kinds: [Contracts.ApiItemKinds.Variable] - } - ]; - const members = this.RenderMembersGroups(memberKindsList, data); - GeneratorHelpers.MergePluginResultData(pluginResult, members); + const membersResult = this.RenderMemberGroups(options, ApiSourceFilePlugin.MemberKindsList, serializedApiItem.Members); + + // Treat members' headings as members of source file heading. + const membersHeadings = membersResult.Headings; + + // Clearing headings from members result to prevent repeated inclusion. + membersResult.Headings = []; + + pluginResult.Headings.push({ + Heading: heading, + ApiItemId: options.Reference.Id, + Members: membersHeadings, + }); + + // Merging rest of the members result + GeneratorHelpers.MergePluginResultData(pluginResult, membersResult); return pluginResult; } diff --git a/packages/ts-docs-gen/src/plugins/api-type-plugin.ts b/packages/ts-docs-gen/src/plugins/api-type-plugin.ts index 4e83a89e..d7059a11 100644 --- a/packages/ts-docs-gen/src/plugins/api-type-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-type-plugin.ts @@ -4,42 +4,44 @@ import { MarkdownBuilder } from "@simplrjs/markdown"; import { GeneratorHelpers } from "../generator-helpers"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { BasePlugin } from "../abstractions/base-plugin"; +import { ApiTypeAlias } from "../api-items/definitions/api-type-alias"; -export class ApiTypePlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Type]; +export class ApiTypePlugin extends BasePlugin { + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.TypeAlias]; } - public Render(options: PluginOptions): PluginResult { - const heading = options.Reference.Alias; + public Render(options: PluginOptions, apiItem: Contracts.ApiTypeAliasDto): PluginResult { + const serializedApiItem = new ApiTypeAlias(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { Heading: heading, ApiItemId: options.Reference.Id } - ] + ], + UsedReferences: [options.Reference.Id] }; // Header pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(GeneratorHelpers.ApiTypeToString(options.ApiItem), GeneratorHelpers.DEFAULT_CODE_OPTIONS) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); // TypeParameters - const apiTypeParameters = GeneratorHelpers - .GetApiItemsFromReference(options.ApiItem.TypeParameters, options.ExtractedData); - const typeParametersResult = this.RenderTypeParameters(apiTypeParameters); + const typeParametersResult = this.RenderTypeParameters(options.ExtractedData, serializedApiItem.TypeParameters); GeneratorHelpers.MergePluginResultData(pluginResult, typeParametersResult); // Type - const typeResult = this.RenderType(options.ApiItem.Type); + const typeResult = this.RenderType(options.ExtractedData, serializedApiItem.Type); GeneratorHelpers.MergePluginResultData(pluginResult, typeResult); return pluginResult; diff --git a/packages/ts-docs-gen/src/plugins/api-variable-plugin.ts b/packages/ts-docs-gen/src/plugins/api-variable-plugin.ts index 1f01c288..1f892ba0 100644 --- a/packages/ts-docs-gen/src/plugins/api-variable-plugin.ts +++ b/packages/ts-docs-gen/src/plugins/api-variable-plugin.ts @@ -4,40 +4,41 @@ import { MarkdownBuilder } from "@simplrjs/markdown"; import { GeneratorHelpers } from "../generator-helpers"; import { SupportedApiItemKindType, PluginOptions, PluginResult } from "../contracts/plugin"; import { BasePlugin } from "../abstractions/base-plugin"; +import { ApiVariable } from "../api-items/definitions/api-variable"; export class ApiVariablePlugin extends BasePlugin { - public SupportedApiItemKinds(): SupportedApiItemKindType[] { - return [GeneratorHelpers.ApiItemKinds.Variable]; + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Variable]; } - public Render(options: PluginOptions): PluginResult { - const heading: string = options.Reference.Alias; + public Render(options: PluginOptions, apiItem: Contracts.ApiVariableDto): PluginResult { + const serializedApiItem = new ApiVariable(options.ExtractedData, apiItem, options.Reference); + + const heading = serializedApiItem.ToHeadingText(); const pluginResult: PluginResult = { ...GeneratorHelpers.GetDefaultPluginResultData(), - ApiItem: options.ApiItem, + ApiItem: apiItem, Reference: options.Reference, Headings: [ { Heading: heading, ApiItemId: options.Reference.Id } - ] + ], + UsedReferences: [options.Reference.Id] }; - // Type - const typeStringDto = GeneratorHelpers.TypeDtoToMarkdownString(options.ApiItem.Type); - pluginResult.Result = new MarkdownBuilder() .Header(heading, 3) .EmptyLine() - .Text(GeneratorHelpers.RenderApiItemMetadata(options.ApiItem)) - .Code(GeneratorHelpers.ApiVariableToString(options.ApiItem), GeneratorHelpers.DEFAULT_CODE_OPTIONS) - .EmptyLine() - .Bold("Type") - .EmptyLine() - .Text(typeStringDto.Text) + .Text(this.RenderApiItemMetadata(apiItem)) + .Code(serializedApiItem.ToText(), GeneratorHelpers.DEFAULT_CODE_OPTIONS) .GetOutput(); + // Type + const typeResult = this.RenderType(options.ExtractedData, serializedApiItem.Type); + GeneratorHelpers.MergePluginResultData(pluginResult, typeResult); + return pluginResult; } } diff --git a/packages/ts-docs-gen/src/registries/plugin-result-registry.ts b/packages/ts-docs-gen/src/registries/api-item-reference-registry.ts similarity index 51% rename from packages/ts-docs-gen/src/registries/plugin-result-registry.ts rename to packages/ts-docs-gen/src/registries/api-item-reference-registry.ts index d622c1db..2b98f7b3 100644 --- a/packages/ts-docs-gen/src/registries/plugin-result-registry.ts +++ b/packages/ts-docs-gen/src/registries/api-item-reference-registry.ts @@ -1,12 +1,11 @@ import { ApiItemReference } from "../contracts/api-item-reference"; -import { PluginResult } from "../contracts/plugin"; -import { PluginResultRegistry as PluginResultRegistryInterface } from "../contracts/plugin-result-registry"; +import { ApiItemReferenceRegistry as ApiItemReferenceRegistryInterface } from "../contracts/api-item-reference-registry"; -export class PluginResultRegistry implements PluginResultRegistryInterface { - private results: Map = new Map(); +export class ApiItemReferenceRegistry implements ApiItemReferenceRegistryInterface { + private map: Map = new Map(); private getKey(itemReference: ApiItemReference): ApiItemReference | undefined { - for (const [reference] of this.results) { + for (const [reference] of this.map) { if (itemReference.Alias === reference.Alias && itemReference.Id === reference.Id) { return reference; @@ -16,15 +15,15 @@ export class PluginResultRegistry implements PluginResultRegistryInterface { return undefined; } - public AddItem(itemReference: ApiItemReference, pluginResult: PluginResult): void { + public AddItem(itemReference: ApiItemReference, value: TValue): void { const key = this.getKey(itemReference) || itemReference; - this.results.set(key, pluginResult); + this.map.set(key, value); } - public GetItem(itemReference: ApiItemReference): PluginResult | undefined { + public GetItem(itemReference: ApiItemReference): TValue | undefined { const realKey = this.getKey(itemReference); if (realKey != null) { - return this.results.get(realKey); + return this.map.get(realKey); } else { return undefined; } diff --git a/packages/ts-docs-gen/src/registries/plugin-registry.ts b/packages/ts-docs-gen/src/registries/plugin-registry.ts index 3f8e203b..64c45756 100644 --- a/packages/ts-docs-gen/src/registries/plugin-registry.ts +++ b/packages/ts-docs-gen/src/registries/plugin-registry.ts @@ -1,39 +1,38 @@ import { Contracts } from "ts-extractor"; -import { Plugin, SupportedApiItemKindType, ApiItemKindsAdditional } from "../contracts/plugin"; +import { Plugin, SupportedApiItemKindType, ApiDefinitionKindAdditional } from "../contracts/plugin"; export class PluginRegistry { constructor() { // Initialize Plugins map. - for (const [, kindValue] of Object.entries(Contracts.ApiItemKinds)) { - this.registeredPlugins.set(kindValue as Contracts.ApiItemKinds, []); + for (const [, kindValue] of Object.entries(Contracts.ApiDefinitionKind)) { + this.registeredPlugins.set(kindValue as Contracts.ApiDefinitionKind, []); } } - private registeredPlugins: Map = new Map(); + private registeredPlugins: Map = new Map(); - private isSupportedKindsHasAny(kinds: SupportedApiItemKindType[]): kinds is ApiItemKindsAdditional[] { - return Boolean(kinds.find(x => x === ApiItemKindsAdditional.Any)); + private isSupportedKindsHasAny(kinds: SupportedApiItemKindType[]): kinds is ApiDefinitionKindAdditional[] { + return Boolean(kinds.find(x => x === ApiDefinitionKindAdditional.Any)); } public Register(plugin: Plugin): void { - const supportedKinds = plugin.SupportedApiItemKinds(); + const supportedKinds: SupportedApiItemKindType[] = plugin.SupportedApiDefinitionKind(); if (this.isSupportedKindsHasAny(supportedKinds)) { for (const [key, value] of this.registeredPlugins) { this.registeredPlugins.set(key, [plugin, ...value]); } return; - } - - // FIXME: Remove `as`. Somehow it doesn't work. - for (const kind of supportedKinds as Contracts.ApiItemKinds[]) { - const registeredPluginsOfKind = this.registeredPlugins.get(kind) || []; - this.registeredPlugins.set(kind, [plugin, ...registeredPluginsOfKind]); + } else { + for (const kind of supportedKinds as Contracts.ApiDefinitionKind[]) { + const registeredPluginsOfKind = this.registeredPlugins.get(kind) || []; + this.registeredPlugins.set(kind, [plugin, ...registeredPluginsOfKind]); + } } } - public GetPluginsByKind(kind: Contracts.ApiItemKinds): Plugin[] { + public GetPluginsByKind(kind: Contracts.ApiDefinitionKind): Plugin[] { return this.registeredPlugins.get(kind) || []; } } diff --git a/packages/ts-docs-gen/src/utils/helpers.ts b/packages/ts-docs-gen/src/utils/helpers.ts index adbe288f..90a25b28 100644 --- a/packages/ts-docs-gen/src/utils/helpers.ts +++ b/packages/ts-docs-gen/src/utils/helpers.ts @@ -1,11 +1,16 @@ +import * as path from "path"; + export namespace Helpers { export function Flatten(arr: any[][]): any[] { return arr.reduce((flat, toFlatten) => flat.concat(Array.isArray(toFlatten) ? Flatten(toFlatten) : toFlatten), []); } - // TODO: Move this to @simplrjs/markdown package. export function HeadingToAnchor(heading: string): string { return heading.trim().toLowerCase().replace(/[^\w\- ]+/g, "").replace(/\s/g, "-").replace(/\-+$/, ""); } + + export function IsPackageName(text: string): boolean { + return (!path.isAbsolute(text) && text.indexOf("./") === -1 && text.indexOf("../") === -1); + } } diff --git a/packages/ts-docs-gen/tests/__tests__/api-items/api-definition-list.test.ts b/packages/ts-docs-gen/tests/__tests__/api-items/api-definition-list.test.ts new file mode 100644 index 00000000..0393ee92 --- /dev/null +++ b/packages/ts-docs-gen/tests/__tests__/api-items/api-definition-list.test.ts @@ -0,0 +1,18 @@ +import { Contracts } from "ts-extractor"; +import { ApiDefinitionList } from "@src/api-items/api-definition-list"; + +import { CheckLists } from "../test-helpers"; + +it("Check if all definitions are supported from ts-extractor.", () => { + const ignoreKinds: Contracts.ApiDefinitionKind[] = [ + Contracts.ApiDefinitionKind.Export, + Contracts.ApiDefinitionKind.ExportSpecifier, + Contracts.ApiDefinitionKind.Export, + Contracts.ApiDefinitionKind.ImportSpecifier + ]; + const kinds = Object.values(Contracts.ApiDefinitionKind); + const values = ApiDefinitionList.map(([kind]) => kind); + + const result = CheckLists(kinds, values, ignoreKinds); + expect(result).toMatchObject([]); +}); diff --git a/packages/ts-docs-gen/tests/__tests__/api-items/api-type-list.test.ts b/packages/ts-docs-gen/tests/__tests__/api-items/api-type-list.test.ts new file mode 100644 index 00000000..b1b05b28 --- /dev/null +++ b/packages/ts-docs-gen/tests/__tests__/api-items/api-type-list.test.ts @@ -0,0 +1,13 @@ +import { Contracts } from "ts-extractor"; +import { ApiTypeList } from "@src/api-items/api-type-list"; + +import { CheckLists } from "../test-helpers"; + +it("Check if all types are supported from ts-extractor.", () => { + const ignoreKinds: Contracts.ApiTypeKind[] = []; + const kinds = Object.values(Contracts.ApiTypeKind); + const values = ApiTypeList.map(([kind]) => kind); + + const result = CheckLists(kinds, values, ignoreKinds); + expect(result).toMatchObject([]); +}); diff --git a/packages/ts-docs-gen/tests/__tests__/test-helpers.ts b/packages/ts-docs-gen/tests/__tests__/test-helpers.ts new file mode 100644 index 00000000..4877e09f --- /dev/null +++ b/packages/ts-docs-gen/tests/__tests__/test-helpers.ts @@ -0,0 +1,20 @@ +/** + * @param a First list. + * @param b Second list that will be compared with first list. + * @param ignoreValues Values that can be ignored from first list. + * @return An array of missing elements in second list. + */ +export function CheckLists(a: string[], b: string[], ignoreValues?: string[]): string[] { + const result: string[] = []; + for (const value of a) { + if (ignoreValues != null && ignoreValues.findIndex(x => x === value) !== -1) { + continue; + } + + if (b.findIndex(x => x === value) === -1) { + result.push(value); + } + } + + return result; +} diff --git a/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-1.test.ts.snap b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-1.test.ts.snap index 19bb8c47..0e0bccd1 100644 --- a/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-1.test.ts.snap +++ b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-1.test.ts.snap @@ -5,40 +5,120 @@ Array [ Object { "FileLocation": "index.md", "Result": Array [ - "[ClassDeclaration-2]: index/earth.md#earth", - "[ClassDeclaration-1]: index/world.md#world", - "[InterfaceDeclaration-1]: index.md#foointerface", - "[InterfaceDeclaration-2]: index.md#boo", - "[InterfaceDeclaration-4]: index.md#myconstrainttype", - "[InterfaceDeclaration-9]: index.md#dictionary", - "[InterfaceDeclaration-9]: index.md#dictionary", - "[InterfaceDeclaration-6]: index.md#objectsinterface", - "[InterfaceDeclaration-12]: index.md#monsterinterface", - "[ClassDeclaration-0]: index/foo.md#foo", - "[ClassDeclaration-1]: index/world.md#world", - "[ClassDeclaration-2]: index/earth.md#earth", - "# index", + "# Table of contents", + "", + "* [index.ts][SourceFile-0]", + " * Functions", + " * [AnotherFoo][FunctionDeclaration-1]", + " * [GetFoo][FunctionDeclaration-0]", + " * [FunctionWithOneParameter][FunctionDeclaration-2]", + " * [FunctionWithNoParameters][FunctionDeclaration-3]", + " * [FunctionWithMultipleParameters][FunctionDeclaration-4]", + " * [Bar][FunctionDeclaration-5]", + " * [FunctionWithMultipleTypeParameters][FunctionDeclaration-6]", + " * [FunctionWithTypeParameterDefault][FunctionDeclaration-7]", + " * [FunctionWithTypeParameterConstraint][FunctionDeclaration-8]", + " * [FunctionWithoutReturnType][FunctionDeclaration-9]", + " * [FunctionWithGenericReturnType][FunctionDeclaration-10]", + " * [FunctionWithPrimitiveReturnType][FunctionDeclaration-11]", + " * [FunctionWithUnionReturnType][FunctionDeclaration-12]", + " * [FunctionWithIntersectionReturnType][FunctionDeclaration-13]", + " * [MyFunction][FunctionDeclaration-14]", + " * [FunctionWithInitializedNumberParameter][FunctionDeclaration-15]", + " * [FunctionWithInitializedStringParameter][FunctionDeclaration-16]", + " * Interfaces", + " * [ExtendedBar][InterfaceDeclaration-0]", + " * [FooInterface][InterfaceDeclaration-1]", + " * [Boo][InterfaceDeclaration-2]", + " * [AnotherInterface][InterfaceDeclaration-3]", + " * [MyConstraintType][InterfaceDeclaration-4]", + " * [MyDefaultType][InterfaceDeclaration-5]", + " * [ObjectsInterface][InterfaceDeclaration-6]", + " * [InterfaceWithCall][InterfaceDeclaration-7]", + " * [InterfaceWithConstraintType][InterfaceDeclaration-8]", + " * [InterfaceWithMethod][InterfaceDeclaration-10]", + " * [Dictionary][InterfaceDeclaration-9]", + " * [MethodsInterface][InterfaceDeclaration-11]", + " * [MonsterInterface][InterfaceDeclaration-12]", + " * [SomeInterface][InterfaceDeclaration-13]", + " * [StringsDictionary][InterfaceDeclaration-14]", + " * [MyInterface][InterfaceDeclaration-15]", + " * Types", + " * [SimpleType][TypeAliasDeclaration-0]", + " * [SimpleTypeParameters][TypeAliasDeclaration-1]", + " * [GenericType][TypeAliasDeclaration-2]", + " * [UnionType][TypeAliasDeclaration-3]", + " * [UnionTypeWithLiterals][TypeAliasDeclaration-4]", + " * [IntersectionType][TypeAliasDeclaration-5]", + " * [IntersectionTypeWithLiterals][TypeAliasDeclaration-6]", + " * [Easing][TypeAliasDeclaration-7]", + " * [Numbers][TypeAliasDeclaration-8]", + " * [Name][TypeAliasDeclaration-9]", + " * [NameResolver][TypeAliasDeclaration-10]", + " * [NameOrResolver][TypeAliasDeclaration-11]", + " * [Tree][TypeAliasDeclaration-12]", + " * [LinkedList][TypeAliasDeclaration-13]", + " * [Negative][TypeAliasDeclaration-14]", + " * [IndexType][TypeAliasDeclaration-15]", + " * [SelectedNumbers][TypeAliasDeclaration-16]", + " * [PartialSimpleType][TypeAliasDeclaration-17]", + " * [Proxy][TypeAliasDeclaration-19]", + " * [TypeWithMultipleTypeParameters][TypeAliasDeclaration-20]", + " * [Readonly][TypeAliasDeclaration-21]", + " * [Partial][TypeAliasDeclaration-18]", + " * [Nullable][TypeAliasDeclaration-22]", + " * [Proxify][TypeAliasDeclaration-23]", + " * [Pick][TypeAliasDeclaration-24]", + " * [Record][TypeAliasDeclaration-25]", + " * Enums", + " * [EnumList][EnumDeclaration-0]", + " * [EnumListWithNumberValues][EnumDeclaration-1]", + " * [EnumListWithStringValues][EnumDeclaration-2]", + " * Variables", + " * [SampleConst][VariableDeclaration-0]", + " * [ArrowFunctionConst][VariableDeclaration-1]", + " * [letString][VariableDeclaration-2]", + " * [varString][VariableDeclaration-3]", + " * [functionVar][VariableDeclaration-4]", + " * [ObjectLiteralConst][VariableDeclaration-5]", + " * [SymbolConst][VariableDeclaration-6]", + " * [MapConst][VariableDeclaration-7]", + " * [AnyMap][VariableDeclaration-8]", + " * [RegexConst][VariableDeclaration-9]", + " * [NumberLiteralConst][VariableDeclaration-10]", + " * [PredefinedArray][VariableDeclaration-11]", + " * [Tuple][VariableDeclaration-12]", + " * [TrueConst][VariableDeclaration-13]", + " * [BooleanConst][VariableDeclaration-14]", + " * [FooConst][VariableDeclaration-15]", + " * [FooLet][VariableDeclaration-16]", + " * [GetFooConst][VariableDeclaration-17]", + " * [NameResolverConst][VariableDeclaration-18]", + " * [StringOrNull][VariableDeclaration-19]", + " * [FunctionConst][VariableDeclaration-20]", + "", + "# index.ts", "", "## Functions", "", - "### AnotherFoo(parameter1, parameter2)", + "### AnotherFoo", "", "\`\`\`typescript", - "function AnotherFoo(parameter1: string, parameter2: Promise): string", + "function AnotherFoo(parameter1: string, parameter2: Promise): string;", "\`\`\`", "", "**Type parameters**", "", - "| Name | Constraint type |", - "| ---- | --------------- |", - "| T | Object |", + "| Name | Constraint |", + "| ---- | ---------- |", + "| T | Object |", "", "**Parameters**", "", - "| Name | Type |", - "| ---------- | -------------------- |", - "| parameter1 | string |", - "| parameter2 | Promise&\\\\#60;T&\\\\#62; |", + "| Name | Type |", + "| ---------- | ---------- |", + "| parameter1 | string |", + "| parameter2 | Promise |", "", "**Return type**", "", @@ -46,22 +126,22 @@ Array [ "", "----------", "", - "### GetFoo()", + "### GetFoo", "", "\`\`\`typescript", - "function GetFoo(): Promise", + "function GetFoo(): Promise;", "\`\`\`", "", "**Return type**", "", - "Promise<void>", + "Promise", "", "----------", "", - "### FunctionWithOneParameter(parameter)", + "### FunctionWithOneParameter", "", "\`\`\`typescript", - "function FunctionWithOneParameter(parameter: string): void", + "function FunctionWithOneParameter(parameter: string): void;", "\`\`\`", "", "**Parameters**", @@ -76,10 +156,10 @@ Array [ "", "----------", "", - "### FunctionWithNoParameters()", + "### FunctionWithNoParameters", "", "\`\`\`typescript", - "function FunctionWithNoParameters(): void", + "function FunctionWithNoParameters(): void;", "\`\`\`", "", "**Return type**", @@ -88,10 +168,10 @@ Array [ "", "----------", "", - "### FunctionWithMultipleParameters(parameter1, parameter2)", + "### FunctionWithMultipleParameters", "", "\`\`\`typescript", - "function FunctionWithMultipleParameters(parameter1: string, parameter2: number): void", + "function FunctionWithMultipleParameters(parameter1: string, parameter2: number): void;", "\`\`\`", "", "**Parameters**", @@ -107,16 +187,16 @@ Array [ "", "----------", "", - "### Bar(parameter1, parameter2)", + "### Bar", "", - "Warning: Beta!", + "**Warning Beta!**", "", - "Deprecated!", + "Deprecated!", "", "Some general comment about Bar function.", "", "\`\`\`typescript", - "function Bar(parameter1: string, parameter2: number): string", + "function Bar(parameter1: string, parameter2: number): string;", "\`\`\`", "", "**Parameters**", @@ -132,20 +212,20 @@ Array [ "", "----------", "", - "### FunctionWithMultipleTypeParameters(parameter1, parameter2)", + "### FunctionWithMultipleTypeParameters", "", "Comment on Function with multiple type parameters.", "", "\`\`\`typescript", - "function FunctionWithMultipleTypeParameters(parameter1: T, parameter2: P): string", + "function FunctionWithMultipleTypeParameters(parameter1: T, parameter2: P): string;", "\`\`\`", "", "**Type parameters**", "", - "| Name | Constraint type |", - "| ---- | --------------- |", - "| T | Object |", - "| P | |", + "| Name | Constraint |", + "| ---- | ---------- |", + "| T | Object |", + "| P | |", "", "**Parameters**", "", @@ -160,19 +240,19 @@ Array [ "", "----------", "", - "### FunctionWithTypeParameterDefault(parameter1, parameter2)", + "### FunctionWithTypeParameterDefault", "", "Some general comment about Function with type parameter default function.", "", "\`\`\`typescript", - "function FunctionWithTypeParameterDefault(parameter1: string, parameter2: T): string", + "function FunctionWithTypeParameterDefault(parameter1: string, parameter2: T): string;", "\`\`\`", "", "**Type parameters**", "", - "| Name | Constraint type | Default type |", - "| ---- | --------------- | ------------ |", - "| T | Object | {} |", + "| Name | Constraint | Default |", + "| ---- | ---------- | ------- |", + "| T | Object | {} |", "", "**Parameters**", "", @@ -187,19 +267,19 @@ Array [ "", "----------", "", - "### FunctionWithTypeParameterConstraint(parameter1, parameter2)", + "### FunctionWithTypeParameterConstraint", "", "Some general comment about AnotherBar function.", "", "\`\`\`typescript", - "function FunctionWithTypeParameterConstraint(parameter1: string, parameter2: T): string", + "function FunctionWithTypeParameterConstraint(parameter1: string, parameter2: T): string;", "\`\`\`", "", "**Type parameters**", "", - "| Name | Constraint type |", - "| ---- | --------------- |", - "| T | Object |", + "| Name | Constraint |", + "| ---- | ---------- |", + "| T | Object |", "", "**Parameters**", "", @@ -214,24 +294,24 @@ Array [ "", "----------", "", - "### FunctionWithoutReturnType(parameter1, parameter2)", + "### FunctionWithoutReturnType", "", "\`\`\`typescript", - "function FunctionWithoutReturnType(parameter1: string, parameter2: Promise): string", + "function FunctionWithoutReturnType(parameter1: string, parameter2: Promise): string;", "\`\`\`", "", "**Type parameters**", "", - "| Name | Constraint type |", - "| ---- | ---------------- |", - "| T | Array<T> |", + "| Name | Constraint |", + "| ---- | ---------- |", + "| T | T[] |", "", "**Parameters**", "", - "| Name | Type |", - "| ---------- | -------------------- |", - "| parameter1 | string |", - "| parameter2 | Promise&\\\\#60;T&\\\\#62; |", + "| Name | Type |", + "| ---------- | ---------- |", + "| parameter1 | string |", + "| parameter2 | Promise |", "", "**Return type**", "", @@ -239,34 +319,34 @@ Array [ "", "----------", "", - "### FunctionWithGenericReturnType()", + "### FunctionWithGenericReturnType", "", "\`\`\`typescript", - "function FunctionWithGenericReturnType(): string[]", + "function FunctionWithGenericReturnType(): string[];", "\`\`\`", "", "**Return type**", "", - "Array<string>", + "string[]", "", "----------", "", - "### FunctionWithPrimitiveReturnType()", + "### FunctionWithPrimitiveReturnType", "", "\`\`\`typescript", - "function FunctionWithPrimitiveReturnType(): boolean", + "function FunctionWithPrimitiveReturnType(): boolean;", "\`\`\`", "", "**Return type**", "", - "true | false", + "boolean", "", "----------", "", - "### FunctionWithUnionReturnType()", + "### FunctionWithUnionReturnType", "", "\`\`\`typescript", - "function FunctionWithUnionReturnType(): \\"something\\" | \\"nothing\\"", + "function FunctionWithUnionReturnType(): \\"something\\" | \\"nothing\\";", "\`\`\`", "", "**Return type**", @@ -275,10 +355,10 @@ Array [ "", "----------", "", - "### FunctionWithIntersectionReturnType()", + "### FunctionWithIntersectionReturnType", "", "\`\`\`typescript", - "function FunctionWithIntersectionReturnType(): Earth & World", + "function FunctionWithIntersectionReturnType(): Earth & World;", "\`\`\`", "", "**Return type**", @@ -287,19 +367,19 @@ Array [ "", "----------", "", - "### MyFunction()", + "### MyFunction", "", "Function with TypeParameter as TypeLiteral.", "", "\`\`\`typescript", - "function MyFunction(): T", + "function MyFunction(): T;", "\`\`\`", "", "**Type parameters**", "", - "| Name | Constraint type | Default type |", - "| ---- | ----------------------------------------------------------- | ----------------------- |", - "| T | { myProperty: string; myPropertyTwo?: number | undefined; } | { myProperty: string; } |", + "| Name | Constraint | Default |", + "| ---- | ---------------------------------------------------------------- | ----------------------- |", + "| T | { myProperty: string; myPropertyTwo?: number | undefined; } | { myProperty: string; } |", "", "**Return type**", "", @@ -307,17 +387,17 @@ Array [ "", "----------", "", - "### FunctionWithInitializedNumberParameter(someParameter)", + "### FunctionWithInitializedNumberParameter", "", "\`\`\`typescript", - "function FunctionWithInitializedNumberParameter(someParameter: number = 12): number", + "function FunctionWithInitializedNumberParameter(someParameter: number = 12): number;", "\`\`\`", "", "**Parameters**", "", - "| Name | Type |", - "| ------------- | ------ |", - "| someParameter | number |", + "| Name | Type | Default value |", + "| ------------- | ------ | ------------- |", + "| someParameter | number | 12 |", "", "**Return type**", "", @@ -325,17 +405,17 @@ Array [ "", "----------", "", - "### FunctionWithInitializedStringParameter(someParameter)", + "### FunctionWithInitializedStringParameter", "", "\`\`\`typescript", - "function FunctionWithInitializedStringParameter(someParameter: string = \\"12\\"): string", + "function FunctionWithInitializedStringParameter(someParameter: string = \\"12\\"): string;", "\`\`\`", "", "**Parameters**", "", - "| Name | Type |", - "| ------------- | ------ |", - "| someParameter | string |", + "| Name | Type | Default value |", + "| ------------- | ------ | ------------- |", + "| someParameter | string | \\"12\\" |", "", "**Return type**", "", @@ -353,15 +433,15 @@ Array [ "", "**Extends**", "", - "[FooInterface][InterfaceDeclaration-1]<number>", + "[FooInterface][InterfaceDeclaration-1]", "", "[Boo][InterfaceDeclaration-2]", "", "**Properties**", "", - "| Name | Type |", - "| ---------- | --------------------- |", - "| OtherStuff | Array<string> |", + "| Name | Type | Optional |", + "| ---------- | -------- | -------- |", + "| OtherStuff | string[] | false |", "", "----------", "", @@ -383,11 +463,11 @@ Array [ "", "**Properties**", "", - "| Name | Type |", - "| ------- | ------ |", - "| Name | string |", - "| Surname | string |", - "| Type | TType |", + "| Name | Type | Optional |", + "| ------- | ------ | -------- |", + "| Name | string | false |", + "| Surname | string | false |", + "| Type | TType | false |", "", "----------", "", @@ -401,9 +481,9 @@ Array [ "", "**Properties**", "", - "| Name | Type |", - "| ---- | --------------------- |", - "| Boos | Array<string> |", + "| Name | Type | Optional |", + "| ---- | -------- | -------- |", + "| Boos | string[] | false |", "", "----------", "", @@ -414,11 +494,10 @@ Array [ " (param1: TValue, param2: TValue): boolean;", "}", "\`\`\`", - "", "#### Call", "", "\`\`\`typescript", - "(param1: TValue, param2: TValue): boolean", + "(param1: TValue, param2: TValue): boolean;", "\`\`\`", "", "**Type parameters**", @@ -436,7 +515,8 @@ Array [ "", "**Return type**", "", - "true | false", + "boolean", + "", "", "----------", "", @@ -450,9 +530,9 @@ Array [ "", "**Properties**", "", - "| Name | Type |", - "| ---------- | ------ |", - "| myProperty | string |", + "| Name | Type | Optional |", + "| ---------- | ------ | -------- |", + "| myProperty | string | false |", "", "----------", "", @@ -470,9 +550,9 @@ Array [ "", "**Properties**", "", - "| Name | Type |", - "| --------------- | ------ |", - "| anotherProperty | number |", + "| Name | Type | Optional |", + "| --------------- | ------ | -------- |", + "| anotherProperty | number | false |", "", "----------", "", @@ -487,10 +567,10 @@ Array [ "", "**Properties**", "", - "| Name | Type |", - "| --------- | ------ |", - "| objectOne | Object |", - "| objectTwo | Object |", + "| Name | Type | Optional |", + "| --------- | ------ | -------- |", + "| objectOne | Object | false |", + "| objectTwo | Object | false |", "", "----------", "", @@ -501,11 +581,10 @@ Array [ " (): { someProperty: T; };", "}", "\`\`\`", - "", "#### Call", "", "\`\`\`typescript", - "(): { someProperty: T; }", + "(): { someProperty: T; };", "\`\`\`", "", "**Type parameters**", @@ -518,6 +597,7 @@ Array [ "", "{ someProperty: T; }", "", + "", "----------", "", "### InterfaceWithConstraintType", @@ -530,13 +610,13 @@ Array [ "", "**Extends**", "", - "[Dictionary][InterfaceDeclaration-9]<string>", + "[Dictionary][InterfaceDeclaration-9]", "", "**Properties**", "", - "| Name | Type |", - "| ------------ | ------ |", - "| someProperty | string |", + "| Name | Type | Optional |", + "| ------------ | ------ | -------- |", + "| someProperty | string | false |", "", "----------", "", @@ -554,11 +634,10 @@ Array [ "| Name |", "| ---- |", "| T |", - "", - "#### Methods", + "#### Method", "", "\`\`\`typescript", - "someMethodOne(): T", + "someMethodOne(): T;", "\`\`\`", "", "**Return type**", @@ -566,7 +645,7 @@ Array [ "T", "", "\`\`\`typescript", - "someMethodTwo(): TReturn", + "someMethodTwo(): TReturn;", "\`\`\`", "", "**Type parameters**", @@ -579,6 +658,7 @@ Array [ "", "TReturn", "", + "", "----------", "", "### Dictionary", @@ -595,41 +675,40 @@ Array [ "| Name |", "| ------ |", "| TValue |", - "", "#### Construct", "", "\`\`\`typescript", - "new (): Dictionary", + "new (): Dictionary;", "\`\`\`", "", "**Return type**", "", - "[Dictionary][InterfaceDeclaration-9]<TValue>", + "[Dictionary][InterfaceDeclaration-9]", "", - "#### Index signatures", + "#### Index", "", "\`\`\`typescript", - "[key: string]: TValue", + "[key: string]: TValue;", "\`\`\`", "", "* *Parameter* \`key\` - string", "* *Type* TValue", "", + "", "----------", "", "### MethodsInterface", "", "\`\`\`typescript", "interface MethodsInterface {", - " (arg: TValue): void;", " someMethod(): string;", + " (arg: TValue): void;", "}", "\`\`\`", - "", "#### Call", "", "\`\`\`typescript", - "(arg: TValue): void", + "(arg: TValue): void;", "\`\`\`", "", "**Type parameters**", @@ -648,10 +727,10 @@ Array [ "", "void", "", - "#### Methods", + "#### Method", "", "\`\`\`typescript", - "someMethod(): string", + "someMethod(): string;", "\`\`\`", "", "**Type parameters**", @@ -664,13 +743,14 @@ Array [ "", "string", "", + "", "----------", "", "### MonsterInterface", "", - "Warning: Beta!", + "**Warning Beta!**", "", - "Deprecated!", + "Deprecated!", "", "Monster interface", "", @@ -678,10 +758,10 @@ Array [ "interface MonsterInterface extends ObjectsInterface {", " new (): MonsterInterface;", " new (someParameter: string): string;", + " readonly [key: string]: TValue;", " (): { someProperty: T; };", - " (key?: string | undefined): { someProperty: T; };", + " (key?: UnionType): { someProperty: T; };", " (key: number): { someProperty: T; };", - " readonly [key: string]: TValue;", " readonly objectOne: TValue;", " objectTwo: TValue;", "}", @@ -689,18 +769,17 @@ Array [ "", "**Type parameters**", "", - "| Name | Constraint type | Default type |", - "| ------ | --------------- | ------------ |", - "| TValue | Object | {} |", + "| Name | Constraint | Default |", + "| ------ | ---------- | ------- |", + "| TValue | Object | {} |", "", "**Extends**", "", "[ObjectsInterface][InterfaceDeclaration-6]", - "", "#### Construct", "", "\`\`\`typescript", - "new (): MonsterInterface", + "new (): MonsterInterface;", "\`\`\`", "", "**Type parameters**", @@ -711,10 +790,10 @@ Array [ "", "**Return type**", "", - "[MonsterInterface][InterfaceDeclaration-12]<T>", + "[MonsterInterface][InterfaceDeclaration-12]", "", "\`\`\`typescript", - "new (someParameter: string): string", + "new (someParameter: string): string;", "\`\`\`", "", "**Parameters**", @@ -730,7 +809,7 @@ Array [ "#### Call", "", "\`\`\`typescript", - "(): { someProperty: T; }", + "(): { someProperty: T; };", "\`\`\`", "", "**Type parameters**", @@ -744,7 +823,7 @@ Array [ "{ someProperty: T; }", "", "\`\`\`typescript", - "(key?: string | undefined): { someProperty: T; }", + "(key?: UnionType): { someProperty: T; };", "\`\`\`", "", "**Type parameters**", @@ -755,16 +834,16 @@ Array [ "", "**Parameters**", "", - "| Name | Type |", - "| ---- | ----------------------- |", - "| key | undefined | string |", + "| Name | Type |", + "| ---- | --------- |", + "| key | UnionType |", "", "**Return type**", "", "{ someProperty: T; }", "", "\`\`\`typescript", - "(key: number): { someProperty: T; }", + "(key: number): { someProperty: T; };", "\`\`\`", "", "**Type parameters**", @@ -783,21 +862,22 @@ Array [ "", "{ someProperty: T; }", "", - "#### Index signatures", + "#### Index", "", "\`\`\`typescript", - "readonly [key: string]: TValue", + "readonly [key: string]: TValue;", "\`\`\`", "", "* *Parameter* \`key\` - string", "* *Type* TValue", "", + "", "**Properties**", "", - "| Name | Type |", - "| --------- | ------ |", - "| objectOne | TValue |", - "| objectTwo | TValue |", + "| Name | Type | Optional |", + "| --------- | ------ | -------- |", + "| objectOne | TValue | false |", + "| objectTwo | TValue | false |", "", "----------", "", @@ -809,23 +889,23 @@ Array [ " [key: number]: string;", "}", "\`\`\`", - "", - "#### Index signatures", + "#### Index", "", "\`\`\`typescript", - "[key: string]: string | number", + "[key: string]: string | number;", "\`\`\`", "", "* *Parameter* \`key\` - string", "* *Type* string | number", "", "\`\`\`typescript", - "[key: number]: string", + "[key: number]: string;", "\`\`\`", "", "* *Parameter* \`key\` - number", "* *Type* string", "", + "", "----------", "", "### StringsDictionary", @@ -835,16 +915,16 @@ Array [ " [key: string]: string;", "}", "\`\`\`", - "", - "#### Index signatures", + "#### Index", "", "\`\`\`typescript", - "[key: string]: string", + "[key: string]: string;", "\`\`\`", "", "* *Parameter* \`key\` - string", "* *Type* string", "", + "", "----------", "", "### MyInterface", @@ -859,159 +939,943 @@ Array [ "", "**Properties**", "", - "| Name | Type |", - "| --------------- | ------ |", - "| MyPropertyOne | string |", - "| MyPropertyTwo | Object |", - "| MyPropertyThree | number |", + "| Name | Type | Optional |", + "| --------------- | ------ | -------- |", + "| MyPropertyOne | string | false |", + "| MyPropertyTwo | Object | false |", + "| MyPropertyThree | number | false |", "", - "## Enums", + "## Types", "", - "### EnumList", + "### SimpleType", "", - "Simple list.", + "\`\`\`typescript", + "type SimpleType = { + Property1: string; + Property2: string; +};", + "\`\`\`", + "", + "**Type**", "", + "{ Property1: string; Property2: string; }", + "", + "----------", + "", + "### SimpleTypeParameters", "", "\`\`\`typescript", - "enum EnumList {", - " FirstOption = 0,", - " SecondOption = 1,", - " ThirdOption = 2", - "}", + "type SimpleTypeParameters = keyof SimpleType;", "\`\`\`", "", - "**Members**", + "**Type**", "", - "| Name | Value | Description |", - "| ------------ | ----- | ------------------------------ |", - "| FirstOption | 0 | Description for First option. |", - "| SecondOption | 1 | Description for Second option. |", - "| ThirdOption | 2 | Description for Third option. |", + "keyof [SimpleType][TypeAliasDeclaration-0]", "", "----------", "", - "### EnumListWithNumberValues", + "### GenericType", "", - "List with number values with no punctuation at the end of description", + "\`\`\`typescript", + "type GenericType = { + Property: T; +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "{ Property: T; }", "", + "----------", + "", + "### UnionType", + "", + "General comment about UnionType type.", "", "\`\`\`typescript", - "enum EnumListWithNumberValues {", - " FirstOption = 1,", - " SecondOption = 2,", - " ThirdOption = 3", - "}", + "type UnionType = string | undefined;", "\`\`\`", "", - "**Members**", + "**Type**", "", - "| Name | Value |", - "| ------------ | ----- |", - "| FirstOption | 1 |", - "| SecondOption | 2 |", - "| ThirdOption | 3 |", + "string | undefined", "", "----------", "", - "### EnumListWithStringValues", + "### UnionTypeWithLiterals", "", - "Warning: Beta!", + "**Warning Beta!**", "", - "Deprecated!", + "Deprecated!", "", + "General comment about UnionTypeWithLiterals.", "", "\`\`\`typescript", - "enum EnumListWithStringValues {", - " FirstOption = \\"first\\",", - " SecondOption = \\"second\\",", - " ThirdOption = \\"third\\"", - "}", + "type UnionTypeWithLiterals = { Property1: string; } | { Property2: number; };", "\`\`\`", "", - "**Members**", + "**Type**", "", - "| Name | Value |", - "| ------------ | -------- |", - "| FirstOption | \\"first\\" |", - "| SecondOption | \\"second\\" |", - "| ThirdOption | \\"third\\" |", + "{ Property1: string; } | { Property2: number; }", "", - "## Classes", + "----------", "", - "### [Foo][ClassDeclaration-0]", + "### IntersectionType", + "", + "\`\`\`typescript", + "type IntersectionType = SimpleType & GenericType;", + "\`\`\`", + "", + "**Type**", + "", + "[SimpleType][TypeAliasDeclaration-0] & [GenericType][TypeAliasDeclaration-2]", "", "----------", "", - "### [World][ClassDeclaration-1]", + "### IntersectionTypeWithLiterals", + "", + "\`\`\`typescript", + "type IntersectionTypeWithLiterals = { Property1: string; } & { Property2: number; };", + "\`\`\`", + "", + "**Type**", + "", + "{ Property1: string; } & { Property2: number; }", "", "----------", "", - "### [Earth][ClassDeclaration-2]", + "### Easing", "", - "## Variables", + "\`\`\`typescript", + "type Easing = \\"ease-in\\" | \\"ease-out\\" | \\"ease-in-out\\";", + "\`\`\`", "", - "### SampleConst", + "**Type**", + "", + "\\"ease-in\\" | \\"ease-out\\" | \\"ease-in-out\\"", + "", + "----------", + "", + "### Numbers", "", "\`\`\`typescript", - "const SampleConst: string;", + "type Numbers = 1 | 2 | 3 | 4 | 5 | 6;", + "\`\`\`", + "", + "**Type**", + "", + "1 | 2 | 3 | 4 | 5 | 6", + "", + "----------", + "", + "### Name", + "", + "\`\`\`typescript", + "type Name = string;", "\`\`\`", "", "**Type**", "", "string", "", + "----------", "", - ], - }, - Object { - "FileLocation": "index/foo.md", - "Result": Array [ - "# Foo", + "### NameResolver", "", "\`\`\`typescript", - "class Foo", + "type NameResolver = () => string;", "\`\`\`", - "## Methods", "", - "### HandleMessage(message)", + "**Type**", + "", + "() => string", + "", + "----------", + "", + "### NameOrResolver", "", "\`\`\`typescript", - "public HandleMessage(message: string): string", + "type NameOrResolver = string | NameResolver;", "\`\`\`", "", - "**Parameters**", + "**Type**", "", - "| Name | Type |", - "| ------- | ------ |", - "| message | string |", + "string | [NameResolver][TypeAliasDeclaration-10]", "", - "**Return type**", + "----------", "", - "string", + "### Tree", "", + "\`\`\`typescript", + "type Tree = { + value: T; + left: Tree; + right: Tree; +};", + "\`\`\`", "", - ], - }, - Object { - "FileLocation": "index/world.md", - "Result": Array [ - "# World", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "{ value: T; left: [Tree][TypeAliasDeclaration-12]; right: [Tree][TypeAliasDeclaration-12]; }", + "", + "----------", + "", + "### LinkedList", "", "\`\`\`typescript", - "class World", + "type LinkedList = T & { next: LinkedList; };", "\`\`\`", "", - ], - }, - Object { - "FileLocation": "index/earth.md", - "Result": Array [ - "# Earth", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "T & { next: [LinkedList][TypeAliasDeclaration-13]; }", + "", + "----------", + "", + "### Negative", "", "\`\`\`typescript", - "class Earth", + "type Negative = void | never;", + "\`\`\`", + "", + "**Type**", + "", + "void | never", + "", + "----------", + "", + "### IndexType", + "", + "\`\`\`typescript", + "type IndexType = { + [key: string]: number; +};", + "\`\`\`", + "", + "**Type**", + "", + "{ [key: string]: number; }", + "", + "----------", + "", + "### SelectedNumbers", + "", + "\`\`\`typescript", + "type SelectedNumbers = Numbers;", + "\`\`\`", + "", + "**Type**", + "", + "[Numbers][TypeAliasDeclaration-8]<[Numbers][TypeAliasDeclaration-8]>", + "", + "----------", + "", + "### PartialSimpleType", + "", + "\`\`\`typescript", + "type PartialSimpleType = Partial;", + "\`\`\`", + "", + "**Type**", + "", + "[Partial][TypeAliasDeclaration-18]<[SimpleType][TypeAliasDeclaration-0]>", + "", + "----------", + "", + "### Proxy", + "", + "\`\`\`typescript", + "type Proxy = { + get(): T; + set(value: T): void; +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "{ get(): T; set(value: T): void; }", + "", + "----------", + "", + "### TypeWithMultipleTypeParameters", + "", + "\`\`\`typescript", + "type TypeWithMultipleTypeParameters = { + PropertyT: T; + PropertyV: V; + PropertyU: U; +};", "\`\`\`", "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "| V |", + "| U |", + "", + "**Type**", + "", + "{ PropertyT: T; PropertyV: V; PropertyU: U; }", + "", + "----------", + "", + "### Readonly", + "", + "\`\`\`typescript", + "type Readonly = { + readonly [P extends keyof T]: T[P] +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "{ readonly [P extends keyof T]: T[P] }", + "", + "----------", + "", + "### Partial", + "", + "\`\`\`typescript", + "type Partial = { + [P extends keyof T]?: T[P] +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "{ [P extends keyof T]?: T[P] }", + "", + "----------", + "", + "### Nullable", + "", + "\`\`\`typescript", + "type Nullable = { + [P extends keyof T]: T[P] | null +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "{ [P extends keyof T]: T[P] | null }", + "", + "----------", + "", + "### Proxify", + "", + "\`\`\`typescript", + "type Proxify = { + [P extends keyof T]: Proxy +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Type**", + "", + "{ [P extends keyof T]: [Proxy][TypeAliasDeclaration-19] }", + "", + "----------", + "", + "### Pick", + "", + "\`\`\`typescript", + "type Pick = { + [P extends K]: T[P] +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name | Constraint |", + "| ---- | ---------- |", + "| T | |", + "| K | keyof T |", + "", + "**Type**", + "", + "{ [P extends K]: T[P] }", + "", + "----------", + "", + "### Record", + "", + "\`\`\`typescript", + "type Record = { + [P extends K]: T +};", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name | Constraint |", + "| ---- | ---------- |", + "| K | string |", + "| T | |", + "", + "**Type**", + "", + "{ [P extends K]: T }", + "", + "## Enums", + "", + "### EnumList", + "", + "Simple list.", + "", + "", + "\`\`\`typescript", + "enum EnumList {", + " FirstOption = 0,", + " SecondOption = 1,", + " ThirdOption = 2", + "}", + "\`\`\`", + "", + "**Members**", + "", + "| Name | Value | Description |", + "| ------------ | ----- | ------------------------------ |", + "| FirstOption | 0 | Description for First option. |", + "| SecondOption | 1 | Description for Second option. |", + "| ThirdOption | 2 | Description for Third option. |", + "", + "----------", + "", + "### EnumListWithNumberValues", + "", + "List with number values with no punctuation at the end of description", + "", + "", + "\`\`\`typescript", + "enum EnumListWithNumberValues {", + " FirstOption = 1,", + " SecondOption = 2,", + " ThirdOption = 3", + "}", + "\`\`\`", + "", + "**Members**", + "", + "| Name | Value |", + "| ------------ | ----- |", + "| FirstOption | 1 |", + "| SecondOption | 2 |", + "| ThirdOption | 3 |", + "", + "----------", + "", + "### EnumListWithStringValues", + "", + "**Warning Beta!**", + "", + "Deprecated!", + "", + "", + "\`\`\`typescript", + "enum EnumListWithStringValues {", + " FirstOption = \\"first\\",", + " SecondOption = \\"second\\",", + " ThirdOption = \\"third\\"", + "}", + "\`\`\`", + "", + "**Members**", + "", + "| Name | Value |", + "| ------------ | -------- |", + "| FirstOption | \\"first\\" |", + "| SecondOption | \\"second\\" |", + "| ThirdOption | \\"third\\" |", + "", + "## Classes", + "", + "### [Foo][ClassDeclaration-0]", + "", + "", + "----------", + "", + "### [World][ClassDeclaration-1]", + "", + "", + "----------", + "", + "### [Earth][ClassDeclaration-2]", + "", + "", + "## Variables", + "", + "### SampleConst", + "", + "\`\`\`typescript", + "const SampleConst: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### ArrowFunctionConst", + "", + "\`\`\`typescript", + "const ArrowFunctionConst: (a: string) => string;", + "\`\`\`", + "", + "**Type**", + "", + "(a: string) => string", + "", + "----------", + "", + "### letString", + "", + "\`\`\`typescript", + "let letString: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### varString", + "", + "\`\`\`typescript", + "var varString: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### functionVar", + "", + "\`\`\`typescript", + "var functionVar: () => string;", + "\`\`\`", + "", + "**Type**", + "", + "() => string", + "", + "----------", + "", + "### ObjectLiteralConst", + "", + "\`\`\`typescript", + "const ObjectLiteralConst: { Property: string; };", + "\`\`\`", + "", + "**Type**", + "", + "{ Property: string; }", + "", + "----------", + "", + "### SymbolConst", + "", + "\`\`\`typescript", + "const SymbolConst: symbol;", + "\`\`\`", + "", + "**Type**", + "", + "symbol", + "", + "----------", + "", + "### MapConst", + "", + "\`\`\`typescript", + "const MapConst: Map;", + "\`\`\`", + "", + "**Type**", + "", + "Map", + "", + "----------", + "", + "### AnyMap", + "", + "\`\`\`typescript", + "const AnyMap: Map;", + "\`\`\`", + "", + "**Type**", + "", + "Map", + "", + "----------", + "", + "### RegexConst", + "", + "\`\`\`typescript", + "const RegexConst: RegExp;", + "\`\`\`", + "", + "**Type**", + "", + "RegExp", + "", + "----------", + "", + "### NumberLiteralConst", + "", + "\`\`\`typescript", + "const NumberLiteralConst: 120;", + "\`\`\`", + "", + "**Type**", + "", + "120", + "", + "----------", + "", + "### PredefinedArray", + "", + "\`\`\`typescript", + "const PredefinedArray: number[];", + "\`\`\`", + "", + "**Type**", + "", + "number[]", + "", + "----------", + "", + "### Tuple", + "", + "\`\`\`typescript", + "const Tuple: [number, string];", + "\`\`\`", + "", + "**Type**", + "", + "[number, string]", + "", + "----------", + "", + "### TrueConst", + "", + "\`\`\`typescript", + "const TrueConst: true;", + "\`\`\`", + "", + "**Type**", + "", + "true", + "", + "----------", + "", + "### BooleanConst", + "", + "\`\`\`typescript", + "const BooleanConst: boolean;", + "\`\`\`", + "", + "**Type**", + "", + "boolean", + "", + "----------", + "", + "### FooConst", + "", + "\`\`\`typescript", + "const FooConst: Boo & ExtendedBar;", + "\`\`\`", + "", + "**Type**", + "", + "[Boo][InterfaceDeclaration-2] & [ExtendedBar][InterfaceDeclaration-0]", + "", + "----------", + "", + "### FooLet", + "", + "\`\`\`typescript", + "let FooLet: Boo | ExtendedBar;", + "\`\`\`", + "", + "**Type**", + "", + "[Boo][InterfaceDeclaration-2] | [ExtendedBar][InterfaceDeclaration-0]", + "", + "----------", + "", + "### GetFooConst", + "", + "\`\`\`typescript", + "const GetFooConst: GetFoo;", + "\`\`\`", + "", + "**Type**", + "", + "[GetFoo][FunctionDeclaration-0]", + "", + "----------", + "", + "### NameResolverConst", + "", + "\`\`\`typescript", + "const NameResolverConst: NameResolver;", + "\`\`\`", + "", + "**Type**", + "", + "[NameResolver][TypeAliasDeclaration-10]", + "", + "----------", + "", + "### StringOrNull", + "", + "\`\`\`typescript", + "const StringOrNull: string | null;", + "\`\`\`", + "", + "**Type**", + "", + "string | null", + "", + "----------", + "", + "### FunctionConst", + "", + "\`\`\`typescript", + "const FunctionConst: () => NameResolver;", + "\`\`\`", + "", + "**Type**", + "", + "() => [NameResolver][TypeAliasDeclaration-10]", + "", + "[SourceFile-0]: index.md#indexts", + "[FunctionDeclaration-1]: index.md#anotherfoo", + "[FunctionDeclaration-0]: index.md#getfoo", + "[FunctionDeclaration-2]: index.md#functionwithoneparameter", + "[FunctionDeclaration-3]: index.md#functionwithnoparameters", + "[FunctionDeclaration-4]: index.md#functionwithmultipleparameters", + "[FunctionDeclaration-5]: index.md#bar", + "[FunctionDeclaration-6]: index.md#functionwithmultipletypeparameters", + "[FunctionDeclaration-7]: index.md#functionwithtypeparameterdefault", + "[FunctionDeclaration-8]: index.md#functionwithtypeparameterconstraint", + "[FunctionDeclaration-9]: index.md#functionwithoutreturntype", + "[FunctionDeclaration-10]: index.md#functionwithgenericreturntype", + "[FunctionDeclaration-11]: index.md#functionwithprimitivereturntype", + "[FunctionDeclaration-12]: index.md#functionwithunionreturntype", + "[FunctionDeclaration-13]: index.md#functionwithintersectionreturntype", + "[ClassDeclaration-2]: index/earth.md#earth", + "[ClassDeclaration-1]: index/world.md#world", + "[FunctionDeclaration-14]: index.md#myfunction", + "[FunctionDeclaration-15]: index.md#functionwithinitializednumberparameter", + "[FunctionDeclaration-16]: index.md#functionwithinitializedstringparameter", + "[InterfaceDeclaration-0]: index.md#extendedbar", + "[InterfaceDeclaration-1]: index.md#foointerface", + "[InterfaceDeclaration-2]: index.md#boo", + "[InterfaceDeclaration-1]: index.md#foointerface", + "[InterfaceDeclaration-2]: index.md#boo", + "[InterfaceDeclaration-3]: index.md#anotherinterface", + "[InterfaceDeclaration-4]: index.md#myconstrainttype", + "[InterfaceDeclaration-5]: index.md#mydefaulttype", + "[InterfaceDeclaration-4]: index.md#myconstrainttype", + "[InterfaceDeclaration-6]: index.md#objectsinterface", + "[InterfaceDeclaration-7]: index.md#interfacewithcall", + "[InterfaceDeclaration-8]: index.md#interfacewithconstrainttype", + "[InterfaceDeclaration-9]: index.md#dictionary", + "[InterfaceDeclaration-10]: index.md#interfacewithmethod", + "[InterfaceDeclaration-9]: index.md#dictionary", + "[InterfaceDeclaration-9]: index.md#dictionary", + "[InterfaceDeclaration-11]: index.md#methodsinterface", + "[InterfaceDeclaration-12]: index.md#monsterinterface", + "[InterfaceDeclaration-6]: index.md#objectsinterface", + "[InterfaceDeclaration-12]: index.md#monsterinterface", + "[InterfaceDeclaration-13]: index.md#someinterface", + "[InterfaceDeclaration-14]: index.md#stringsdictionary", + "[InterfaceDeclaration-15]: index.md#myinterface", + "[TypeAliasDeclaration-0]: index.md#simpletype", + "[TypeAliasDeclaration-1]: index.md#simpletypeparameters", + "[TypeAliasDeclaration-0]: index.md#simpletype", + "[TypeAliasDeclaration-2]: index.md#generictype", + "[TypeAliasDeclaration-3]: index.md#uniontype", + "[TypeAliasDeclaration-4]: index.md#uniontypewithliterals", + "[TypeAliasDeclaration-5]: index.md#intersectiontype", + "[TypeAliasDeclaration-0]: index.md#simpletype", + "[TypeAliasDeclaration-2]: index.md#generictype", + "[TypeAliasDeclaration-6]: index.md#intersectiontypewithliterals", + "[TypeAliasDeclaration-7]: index.md#easing", + "[TypeAliasDeclaration-8]: index.md#numbers", + "[TypeAliasDeclaration-9]: index.md#name", + "[TypeAliasDeclaration-10]: index.md#nameresolver", + "[TypeAliasDeclaration-11]: index.md#nameorresolver", + "[TypeAliasDeclaration-10]: index.md#nameresolver", + "[TypeAliasDeclaration-12]: index.md#tree", + "[TypeAliasDeclaration-12]: index.md#tree", + "[TypeAliasDeclaration-12]: index.md#tree", + "[TypeAliasDeclaration-13]: index.md#linkedlist", + "[TypeAliasDeclaration-13]: index.md#linkedlist", + "[TypeAliasDeclaration-14]: index.md#negative", + "[TypeAliasDeclaration-15]: index.md#indextype", + "[TypeAliasDeclaration-16]: index.md#selectednumbers", + "[TypeAliasDeclaration-8]: index.md#numbers", + "[TypeAliasDeclaration-8]: index.md#numbers", + "[TypeAliasDeclaration-17]: index.md#partialsimpletype", + "[TypeAliasDeclaration-0]: index.md#simpletype", + "[TypeAliasDeclaration-18]: index.md#partial", + "[TypeAliasDeclaration-19]: index.md#proxy", + "[TypeAliasDeclaration-20]: index.md#typewithmultipletypeparameters", + "[TypeAliasDeclaration-21]: index.md#readonly", + "[TypeAliasDeclaration-18]: index.md#partial", + "[TypeAliasDeclaration-22]: index.md#nullable", + "[TypeAliasDeclaration-23]: index.md#proxify", + "[TypeAliasDeclaration-19]: index.md#proxy", + "[TypeAliasDeclaration-24]: index.md#pick", + "[TypeAliasDeclaration-25]: index.md#record", + "[EnumDeclaration-0]: index.md#enumlist", + "[EnumDeclaration-1]: index.md#enumlistwithnumbervalues", + "[EnumDeclaration-2]: index.md#enumlistwithstringvalues", + "[ClassDeclaration-0]: index/foo.md#foo", + "[ClassDeclaration-1]: index/world.md#world", + "[ClassDeclaration-2]: index/earth.md#earth", + "[VariableDeclaration-0]: index.md#sampleconst", + "[VariableDeclaration-1]: index.md#arrowfunctionconst", + "[VariableDeclaration-2]: index.md#letstring", + "[VariableDeclaration-3]: index.md#varstring", + "[VariableDeclaration-4]: index.md#functionvar", + "[VariableDeclaration-5]: index.md#objectliteralconst", + "[VariableDeclaration-6]: index.md#symbolconst", + "[VariableDeclaration-7]: index.md#mapconst", + "[VariableDeclaration-8]: index.md#anymap", + "[VariableDeclaration-9]: index.md#regexconst", + "[VariableDeclaration-10]: index.md#numberliteralconst", + "[VariableDeclaration-11]: index.md#predefinedarray", + "[VariableDeclaration-12]: index.md#tuple", + "[VariableDeclaration-13]: index.md#trueconst", + "[VariableDeclaration-14]: index.md#booleanconst", + "[VariableDeclaration-15]: index.md#fooconst", + "[InterfaceDeclaration-2]: index.md#boo", + "[InterfaceDeclaration-0]: index.md#extendedbar", + "[VariableDeclaration-16]: index.md#foolet", + "[InterfaceDeclaration-2]: index.md#boo", + "[InterfaceDeclaration-0]: index.md#extendedbar", + "[VariableDeclaration-17]: index.md#getfooconst", + "[FunctionDeclaration-0]: index.md#getfoo", + "[VariableDeclaration-18]: index.md#nameresolverconst", + "[TypeAliasDeclaration-10]: index.md#nameresolver", + "[VariableDeclaration-19]: index.md#stringornull", + "[VariableDeclaration-20]: index.md#functionconst", + "[TypeAliasDeclaration-10]: index.md#nameresolver", + ], + }, + Object { + "FileLocation": "index/foo.md", + "Result": Array [ + "# Table of contents", + "", + "* [Foo][ClassDeclaration-0]", + " * Methods", + " * [HandleMessage(message)][MethodDeclaration-0]", + "", + "# Foo", + "", + "\`\`\`typescript", + "class Foo", + "\`\`\`", + "## Methods", + "", + "### HandleMessage(message)", + "", + "\`\`\`typescript", + "public HandleMessage(message: string): string;", + "\`\`\`", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ------- | ------ |", + "| message | string |", + "", + "**Return type**", + "", + "string", + "", + "[ClassDeclaration-0]: foo.md#foo", + "[MethodDeclaration-0]: foo.md#handlemessagemessage", + ], + }, + Object { + "FileLocation": "index/world.md", + "Result": Array [ + "# World", + "", + "\`\`\`typescript", + "class World", + "\`\`\`", + "[ClassDeclaration-1]: world.md#world", + ], + }, + Object { + "FileLocation": "index/earth.md", + "Result": Array [ + "# Earth", + "", + "\`\`\`typescript", + "class Earth", + "\`\`\`", + "[ClassDeclaration-2]: earth.md#earth", ], }, ] diff --git a/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-2.test.ts.snap b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-2.test.ts.snap index 376c2325..fa897125 100644 --- a/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-2.test.ts.snap +++ b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-2.test.ts.snap @@ -5,51 +5,268 @@ Array [ Object { "FileLocation": "index.md", "Result": Array [ - "[ClassDeclaration-0]: index/foo.md#foo", - "[ClassDeclaration-1]: index/foostart.md#foostart", - "# index", + "# Table of contents", + "", + "* [index.ts][SourceFile-0]", + " * Interfaces", + " * [Start][InterfaceDeclaration-1]", + "", + "# index.ts", + "", + "## Interfaces", + "", + "### Start", + "", + "\`\`\`typescript", + "interface Start {", + " HandleMessage(message: string): string;", + "}", + "\`\`\`", + "#### Method", + "", + "\`\`\`typescript", + "HandleMessage(message: string): string;", + "\`\`\`", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ------- | ------ |", + "| message | string |", + "", + "**Return type**", + "", + "string", + "", "", "## Classes", "", "### [Foo][ClassDeclaration-0]", "", + "General comment about class Foo.", + "", + "", "----------", "", "### [FooStart][ClassDeclaration-1]", "", "", + "----------", + "", + "### [BooStart][ClassDeclaration-2]", + "", + "", + "[SourceFile-0]: index.md#indexts", + "[InterfaceDeclaration-1]: index.md#start", + "[ClassDeclaration-0]: index/foo.md#foo", + "[ClassDeclaration-1]: index/foostart.md#foostart", + "[ClassDeclaration-2]: index/boostart.md#boostart", ], }, Object { "FileLocation": "index/foo.md", "Result": Array [ + "# Table of contents", + "", + "* [Foo][ClassDeclaration-0]", + " * Constructor", + " * [constructor(suffix)][Constructor-0]", + " * Methods", + " * [getTimeString()][MethodDeclaration-0]", + " * [DefaultMessageTypeString()][MethodDeclaration-1]", + " * [resolveMessageDto(message, time)][MethodDeclaration-2]", + " * [GetMessage(message)][MethodDeclaration-3]", + " * [PrintMessage(messageDto)][MethodDeclaration-4]", + " * [ResolveSimpleMessageObject(message)][MethodDeclaration-5]", + " * Properties", + " * [Name][PropertyDeclaration-0]", + " * [internalName][PropertyDeclaration-1]", + " * [defaultMessage][PropertyDeclaration-2]", + " * [messageSuffix][PropertyDeclaration-3]", + " * [IsSuffixSet][PropertyDeclaration-4]", + " * [DefaultMessage][GetAccessor-0]", + " * [getMessageSuffix][GetAccessor-1]", + " * [setMessageSuffix][SetAccessor-0]", + " * [SetDefaultSuffix][SetAccessor-1]", + "", "# Foo", "", + "General comment about class Foo.", + "", "\`\`\`typescript", "class Foo", "\`\`\`", + "## Constructor", + "", + "### constructor(suffix)", + "", + "Some constructor.", + "", + "\`\`\`typescript", + "public constructor(suffix: string | undefined);", + "\`\`\`", + "", + "**Parameters**", + "", + "| Name | Type | Description |", + "| ------ | ----------------------- | ------------------ |", + "| suffix | string | undefined | Suffix of message. |", + "", "## Methods", "", + "### getTimeString()", + "", + "private static method \`getTimeString\` comment.", + "", + "\`\`\`typescript", + "private static getTimeString(): string;", + "\`\`\`", + "", + "**Return type**", + "", + "string", + "", + "----------", + "", + "### DefaultMessageTypeString()", + "", + "public static method \`DefaultMessageTypeString\` comment.", + "", + "\`\`\`typescript", + "public static DefaultMessageTypeString(): string;", + "\`\`\`", + "", + "**Return type**", + "", + "string", + "", + "----------", + "", + "### resolveMessageDto(message, time)", + "", + "\`\`\`typescript", + "private resolveMessageDto(message: T, time?: string | undefined): MessageDto;", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name | Default |", + "| ---- | ------- |", + "| T | {} |", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ------- | ----------------------- |", + "| message | T |", + "| time | string | undefined |", + "", + "**Return type**", + "", + "[MessageDto][InterfaceDeclaration-0]", + "", + "----------", + "", "### GetMessage(message)", "", "\`\`\`typescript", - "public GetMessage(message: string): string", + "public GetMessage(message: string): string;", "\`\`\`", "", "**Parameters**", "", - "| Name | Type |", - "| ------- | ------ |", - "| message | string |", + "| Name | Type | Description |", + "| ------- | ------ | ------------- |", + "| message | string | Message text. |", "", "**Return type**", "", "string", "", + "----------", + "", + "### PrintMessage(messageDto)", + "", + "\`\`\`typescript", + "public PrintMessage(messageDto: MessageDto): void;", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name | Constraint |", + "| ---- | ---------- |", + "| T | Object |", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ---------- | --------------------------------------- |", + "| messageDto | [MessageDto][InterfaceDeclaration-0] |", + "", + "**Return type**", + "", + "void", + "", + "----------", + "", + "### ResolveSimpleMessageObject(message)", + "", + "\`\`\`typescript", + "public ResolveSimpleMessageObject(message: T): { Message: T; };", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ------- | ---- |", + "| message | T |", + "", + "**Return type**", + "", + "{ Message: T; }", + "", "## Properties", "", + "### Name", + "", + "**Warning Beta!**", + "", + "Deprecated!", + "", + "public static property \`Name\` comment.", + "", + "\`\`\`typescript", + "public static Name: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### internalName", + "", + "\`\`\`typescript", + "private static internalName: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", "### defaultMessage", "", + "private readonly method \`defaultMessage\` comment.", + "", "\`\`\`typescript", "private readonly defaultMessage: string;", "\`\`\`", @@ -58,23 +275,119 @@ Array [ "", "string", "", + "----------", + "", + "### messageSuffix", + "", + "\`\`\`typescript", + "private messageSuffix: string | undefined;", + "\`\`\`", + "", + "**Type**", + "", + "string | undefined", + "", + "----------", + "", + "### IsSuffixSet", + "", + "\`\`\`typescript", + "public IsSuffixSet?: boolean | undefined;", + "\`\`\`", + "", + "**Type**", + "", + "boolean | undefined", + "", + "----------", + "", + "### DefaultMessage", + "", + "\`\`\`typescript", + "public get DefaultMessage: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### getMessageSuffix", + "", + "\`\`\`typescript", + "private get getMessageSuffix: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### setMessageSuffix", + "", + "\`\`\`typescript", + "private set setMessageSuffix: string | undefined;", + "\`\`\`", + "", + "**Type**", + "", + "string | undefined", + "", + "----------", + "", + "### SetDefaultSuffix", + "", + "\`\`\`typescript", + "public set SetDefaultSuffix: string;", + "\`\`\`", + "", + "**Type**", "", + "string", + "", + "[ClassDeclaration-0]: foo.md#foo", + "[Constructor-0]: foo.md#constructorsuffix", + "[MethodDeclaration-0]: foo.md#gettimestring", + "[MethodDeclaration-1]: foo.md#defaultmessagetypestring", + "[MethodDeclaration-2]: foo.md#resolvemessagedtomessage-time", + "[InterfaceDeclaration-0]: ../foo.md#messagedto", + "[MethodDeclaration-3]: foo.md#getmessagemessage", + "[MethodDeclaration-4]: foo.md#printmessagemessagedto", + "[InterfaceDeclaration-0]: ../foo.md#messagedto", + "[MethodDeclaration-5]: foo.md#resolvesimplemessageobjectmessage", + "[PropertyDeclaration-0]: foo.md#name", + "[PropertyDeclaration-1]: foo.md#internalname", + "[PropertyDeclaration-2]: foo.md#defaultmessage", + "[PropertyDeclaration-3]: foo.md#messagesuffix", + "[PropertyDeclaration-4]: foo.md#issuffixset", + "[GetAccessor-0]: foo.md#defaultmessage", + "[GetAccessor-1]: foo.md#getmessagesuffix", + "[SetAccessor-0]: foo.md#setmessagesuffix", + "[SetAccessor-1]: foo.md#setdefaultsuffix", ], }, Object { "FileLocation": "index/foostart.md", "Result": Array [ + "# Table of contents", + "", + "* [FooStart][ClassDeclaration-1]", + " * Methods", + " * [HandleMessage(message)][MethodDeclaration-6]", + "", "# FooStart", "", "\`\`\`typescript", - "class FooStart", + "class FooStart implements Start", "\`\`\`", "## Methods", "", "### HandleMessage(message)", "", "\`\`\`typescript", - "public HandleMessage(message: string): string", + "public HandleMessage(message: string): string;", "\`\`\`", "", "**Parameters**", @@ -87,20 +400,269 @@ Array [ "", "string", "", + "[ClassDeclaration-1]: foostart.md#foostart", + "[MethodDeclaration-6]: foostart.md#handlemessagemessage", + ], + }, + Object { + "FileLocation": "index/boostart.md", + "Result": Array [ + "# Table of contents", + "", + "* [BooStart][ClassDeclaration-2]", + " * Properties", + " * [defaultMessage][PropertyDeclaration-5]", + "", + "# BooStart", + "", + "\`\`\`typescript", + "class BooStart", + "\`\`\`", + "## Properties", + "", + "### defaultMessage", "", + "\`\`\`typescript", + "private defaultMessage: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "[ClassDeclaration-2]: boostart.md#boostart", + "[PropertyDeclaration-5]: boostart.md#defaultmessage", ], }, Object { "FileLocation": "foo.md", "Result": Array [ - "[ClassDeclaration-0]: index/foo.md#foo", - "# foo", + "# Table of contents", + "", + "* [foo.ts][SourceFile-1]", + " * Interfaces", + " * [MessageDto][InterfaceDeclaration-0]", + "", + "# foo.ts", + "", + "## Interfaces", + "", + "### MessageDto", + "", + "\`\`\`typescript", + "interface MessageDto {", + " Message: T;", + " Time: string;", + "}", + "\`\`\`", + "", + "**Type parameters**", + "", + "| Name |", + "| ---- |", + "| T |", + "", + "**Properties**", + "", + "| Name | Type | Optional |", + "| ------- | ------ | -------- |", + "| Message | T | false |", + "| Time | string | false |", "", "## Classes", "", "### [Foo][ClassDeclaration-0]", "", + "[SourceFile-1]: foo.md#foots", + "[InterfaceDeclaration-0]: foo.md#messagedto", + ], + }, + Object { + "FileLocation": "boo.md", + "Result": Array [ + "# boo.ts", + "", + "## Classes", + "", + "### [AbstractBoo][ClassDeclaration-3]", + "", + "", + "----------", + "", + "### [Boo][ClassDeclaration-4]", + "", + "", + "[SourceFile-2]: boo.md#boots", + "[ClassDeclaration-3]: boo/abstractboo.md#abstractboo", + "[ClassDeclaration-4]: boo/boo.md#boo", + ], + }, + Object { + "FileLocation": "boo/abstractboo.md", + "Result": Array [ + "# Table of contents", + "", + "* [AbstractBoo][ClassDeclaration-3]", + " * Constructor", + " * [constructor()][Constructor-1]", + " * Methods", + " * [BooTheMessage()][MethodDeclaration-7]", + " * Properties", + " * [DefaultBooMessage][PropertyDeclaration-6]", + " * [BooMessage][PropertyDeclaration-7]", + " * [AbstractBooMember][PropertyDeclaration-8]", + "", + "# AbstractBoo", + "", + "\`\`\`typescript", + "abstract class AbstractBoo", + "\`\`\`", + "## Constructor", + "", + "### constructor()", + "", + "\`\`\`typescript", + "public constructor();", + "\`\`\`", + "", + "## Methods", + "", + "### BooTheMessage()", + "", + "\`\`\`typescript", + "public abstract BooTheMessage(): string;", + "\`\`\`", + "", + "**Return type**", + "", + "string", + "", + "## Properties", + "", + "### DefaultBooMessage", + "", + "\`\`\`typescript", + "public abstract readonly DefaultBooMessage: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### BooMessage", + "", + "\`\`\`typescript", + "public abstract BooMessage: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### AbstractBooMember", + "", + "\`\`\`typescript", + "public abstract AbstractBooMember?: string | undefined;", + "\`\`\`", + "", + "**Type**", + "", + "string | undefined", + "", + "[ClassDeclaration-3]: abstractboo.md#abstractboo", + "[Constructor-1]: abstractboo.md#constructor", + "[MethodDeclaration-7]: abstractboo.md#boothemessage", + "[PropertyDeclaration-6]: abstractboo.md#defaultboomessage", + "[PropertyDeclaration-7]: abstractboo.md#boomessage", + "[PropertyDeclaration-8]: abstractboo.md#abstractboomember", + ], + }, + Object { + "FileLocation": "boo/boo.md", + "Result": Array [ + "# Table of contents", + "", + "* [Boo][ClassDeclaration-4]", + " * Constructor", + " * [constructor()][Constructor-2]", + " * Methods", + " * [BooTheMessage()][MethodDeclaration-8]", + " * Properties", + " * [DefaultBooMessage][PropertyDeclaration-9]", + " * [BooMessage][PropertyDeclaration-10]", + " * [AbstractBooMember][PropertyDeclaration-11]", + "", + "# Boo", + "", + "\`\`\`typescript", + "class Boo", + "\`\`\`", + "## Constructor", + "", + "### constructor()", + "", + "\`\`\`typescript", + "public constructor();", + "\`\`\`", + "", + "## Methods", + "", + "### BooTheMessage()", + "", + "\`\`\`typescript", + "public BooTheMessage(): string;", + "\`\`\`", + "", + "**Return type**", + "", + "string", + "", + "## Properties", + "", + "### DefaultBooMessage", + "", + "\`\`\`typescript", + "public DefaultBooMessage: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### BooMessage", + "", + "\`\`\`typescript", + "public BooMessage: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "----------", + "", + "### AbstractBooMember", + "", + "\`\`\`typescript", + "public AbstractBooMember?: string | undefined;", + "\`\`\`", + "", + "**Type**", + "", + "string | undefined", "", + "[ClassDeclaration-4]: boo.md#boo", + "[Constructor-2]: boo.md#constructor", + "[MethodDeclaration-8]: boo.md#boothemessage", + "[PropertyDeclaration-9]: boo.md#defaultboomessage", + "[PropertyDeclaration-10]: boo.md#boomessage", + "[PropertyDeclaration-11]: boo.md#abstractboomember", ], }, ] diff --git a/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-3.test.ts.snap b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-3.test.ts.snap new file mode 100644 index 00000000..df4e3344 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-3.test.ts.snap @@ -0,0 +1,363 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`simple-project-3 1`] = ` +Array [ + Object { + "FileLocation": "index.md", + "Result": Array [ + "# index.ts", + "", + "## Namespaces", + "", + "### [SimpleNamespace][ModuleDeclaration-0]", + "", + "General comment about SimpleNamespace.", + "", + "", + "----------", + "", + "### [AnotherSimpleNamespace][ModuleDeclaration-1]", + "", + "", + "----------", + "", + "### [Validation][ModuleDeclaration-2]", + "", + "", + "----------", + "", + "### [NamespaceOne][ModuleDeclaration-3]", + "", + "", + "[SourceFile-0]: index.md#indexts", + "[ModuleDeclaration-0]: index/simplenamespace.md#simplenamespace", + "[ModuleDeclaration-1]: index/anothersimplenamespace.md#anothersimplenamespace", + "[ModuleDeclaration-2]: index/validation.md#validation", + "[ModuleDeclaration-3]: index/namespaceone.md#namespaceone", + ], + }, + Object { + "FileLocation": "index/simplenamespace.md", + "Result": Array [ + "# Table of contents", + "", + "* [SimpleNamespace][ModuleDeclaration-0]", + " * Interfaces", + " * [SimpleInterface][InterfaceDeclaration-0]", + " * Variables", + " * [SimpleObject][VariableDeclaration-0]", + "", + "# SimpleNamespace", + "", + "General comment about SimpleNamespace.", + "", + "## Interfaces", + "", + "### SimpleInterface", + "", + "\`\`\`typescript", + "interface SimpleInterface {", + " Property1: string;", + " Property2: string;", + "}", + "\`\`\`", + "", + "**Properties**", + "", + "| Name | Type | Optional |", + "| --------- | ------ | -------- |", + "| Property1 | string | false |", + "| Property2 | string | false |", + "", + "## Variables", + "", + "### SimpleObject", + "", + "\`\`\`typescript", + "const SimpleObject: SimpleInterface;", + "\`\`\`", + "", + "**Type**", + "", + "[SimpleInterface][InterfaceDeclaration-1]", + "", + "[ModuleDeclaration-0]: simplenamespace.md#simplenamespace", + "[InterfaceDeclaration-0]: simplenamespace.md#simpleinterface", + "[VariableDeclaration-0]: simplenamespace.md#simpleobject", + "[InterfaceDeclaration-1]: anothersimplenamespace.md#simpleinterface", + ], + }, + Object { + "FileLocation": "index/anothersimplenamespace.md", + "Result": Array [ + "# Table of contents", + "", + "* [AnotherSimpleNamespace][ModuleDeclaration-1]", + " * Interfaces", + " * [SimpleInterface][InterfaceDeclaration-1]", + "", + "# AnotherSimpleNamespace", + "", + "## Interfaces", + "", + "### SimpleInterface", + "", + "\`\`\`typescript", + "interface SimpleInterface extends SimpleInterface {", + " Property3: string;", + "}", + "\`\`\`", + "", + "**Extends**", + "", + "[SimpleInterface][InterfaceDeclaration-0]", + "", + "**Properties**", + "", + "| Name | Type | Optional |", + "| --------- | ------ | -------- |", + "| Property3 | string | false |", + "", + "[ModuleDeclaration-1]: anothersimplenamespace.md#anothersimplenamespace", + "[InterfaceDeclaration-1]: anothersimplenamespace.md#simpleinterface", + "[InterfaceDeclaration-0]: simplenamespace.md#simpleinterface", + ], + }, + Object { + "FileLocation": "index/validation.md", + "Result": Array [ + "# Table of contents", + "", + "* [Validation][ModuleDeclaration-2]", + " * Interfaces", + " * [StringValidator][InterfaceDeclaration-2]", + "", + "# Validation", + "", + "## Interfaces", + "", + "### StringValidator", + "", + "\`\`\`typescript", + "interface StringValidator {", + " isAcceptable(s: string): boolean;", + "}", + "\`\`\`", + "#### Method", + "", + "\`\`\`typescript", + "isAcceptable(s: string): boolean;", + "\`\`\`", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ---- | ------ |", + "| s | string |", + "", + "**Return type**", + "", + "boolean", + "", + "", + "## Classes", + "", + "### [LettersOnlyValidator][ClassDeclaration-0]", + "", + "", + "----------", + "", + "### [ZipCodeValidator][ClassDeclaration-1]", + "", + "", + "[ModuleDeclaration-2]: validation.md#validation", + "[InterfaceDeclaration-2]: validation.md#stringvalidator", + "[ClassDeclaration-0]: validation/lettersonlyvalidator.md#lettersonlyvalidator", + "[ClassDeclaration-1]: validation/zipcodevalidator.md#zipcodevalidator", + ], + }, + Object { + "FileLocation": "index/validation/lettersonlyvalidator.md", + "Result": Array [ + "# Table of contents", + "", + "* [LettersOnlyValidator][ClassDeclaration-0]", + " * Methods", + " * [isAcceptable(s)][MethodDeclaration-0]", + "", + "# LettersOnlyValidator", + "", + "\`\`\`typescript", + "class LettersOnlyValidator implements StringValidator", + "\`\`\`", + "## Methods", + "", + "### isAcceptable(s)", + "", + "\`\`\`typescript", + "public isAcceptable(s: string): boolean;", + "\`\`\`", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ---- | ------ |", + "| s | string |", + "", + "**Return type**", + "", + "boolean", + "", + "[ClassDeclaration-0]: lettersonlyvalidator.md#lettersonlyvalidator", + "[MethodDeclaration-0]: lettersonlyvalidator.md#isacceptables", + ], + }, + Object { + "FileLocation": "index/validation/zipcodevalidator.md", + "Result": Array [ + "# Table of contents", + "", + "* [ZipCodeValidator][ClassDeclaration-1]", + " * Methods", + " * [isAcceptable(s)][MethodDeclaration-1]", + "", + "# ZipCodeValidator", + "", + "\`\`\`typescript", + "class ZipCodeValidator implements StringValidator", + "\`\`\`", + "## Methods", + "", + "### isAcceptable(s)", + "", + "\`\`\`typescript", + "public isAcceptable(s: string): boolean;", + "\`\`\`", + "", + "**Parameters**", + "", + "| Name | Type |", + "| ---- | ------ |", + "| s | string |", + "", + "**Return type**", + "", + "boolean", + "", + "[ClassDeclaration-1]: zipcodevalidator.md#zipcodevalidator", + "[MethodDeclaration-1]: zipcodevalidator.md#isacceptables", + ], + }, + Object { + "FileLocation": "index/namespaceone.md", + "Result": Array [ + "# NamespaceOne", + "", + "## Namespaces", + "", + "### [NamespaceTwo][ModuleDeclaration-4]", + "", + "", + "----------", + "", + "### [NamespaceThree][ModuleDeclaration-5]", + "", + "", + "[ModuleDeclaration-3]: namespaceone.md#namespaceone", + "[ModuleDeclaration-4]: namespaceone/namespacetwo.md#namespacetwo", + "[ModuleDeclaration-5]: namespaceone/namespacethree.md#namespacethree", + ], + }, + Object { + "FileLocation": "index/namespaceone/namespacetwo.md", + "Result": Array [ + "# NamespaceTwo", + "", + "## Classes", + "", + "### [SomeClass][ClassDeclaration-2]", + "", + "", + "[ModuleDeclaration-4]: namespacetwo.md#namespacetwo", + "[ClassDeclaration-2]: namespacetwo/someclass.md#someclass", + ], + }, + Object { + "FileLocation": "index/namespaceone/namespacetwo/someclass.md", + "Result": Array [ + "# Table of contents", + "", + "* [SomeClass][ClassDeclaration-2]", + " * Properties", + " * [Name][PropertyDeclaration-0]", + "", + "# SomeClass", + "", + "\`\`\`typescript", + "class SomeClass", + "\`\`\`", + "## Properties", + "", + "### Name", + "", + "\`\`\`typescript", + "public static Name: string;", + "\`\`\`", + "", + "**Type**", + "", + "string", + "", + "[ClassDeclaration-2]: someclass.md#someclass", + "[PropertyDeclaration-0]: someclass.md#name", + ], + }, + Object { + "FileLocation": "index/namespaceone/namespacethree.md", + "Result": Array [ + "# NamespaceThree", + "", + "## Namespaces", + "", + "### [NamespaceFour][ModuleDeclaration-6]", + "", + "", + "[ModuleDeclaration-5]: namespacethree.md#namespacethree", + "[ModuleDeclaration-6]: namespacethree/namespacefour.md#namespacefour", + ], + }, + Object { + "FileLocation": "index/namespaceone/namespacethree/namespacefour.md", + "Result": Array [ + "# Table of contents", + "", + "* [NamespaceFour][ModuleDeclaration-6]", + " * Interfaces", + " * [InterfaceInFour][InterfaceDeclaration-3]", + "", + "# NamespaceFour", + "", + "## Interfaces", + "", + "### InterfaceInFour", + "", + "\`\`\`typescript", + "interface InterfaceInFour {", + " Property1: string;", + " Property2: string;", + "}", + "\`\`\`", + "", + "**Properties**", + "", + "| Name | Type | Optional |", + "| --------- | ------ | -------- |", + "| Property1 | string | false |", + "| Property2 | string | false |", + "", + "[ModuleDeclaration-6]: namespacefour.md#namespacefour", + "[InterfaceDeclaration-3]: namespacefour.md#interfaceinfour", + ], + }, +] +`; diff --git a/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-4.test.ts.snap b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-4.test.ts.snap new file mode 100644 index 00000000..fe2410a8 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/__tests__/__snapshots__/simple-project-4.test.ts.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`simple-project-4 1`] = ` +Array [ + Object { + "FileLocation": "custom.md", + "Result": Array [ + "# Table of contents", + "", + "* [custom.ts][SourceFile-0]", + " * Variables", + " * [My variable CustomSecretRandomNumber][VariableDeclaration-0]", + "", + "# custom.ts", + "", + "## Variables", + "", + "### My variable CustomSecretRandomNumber", + "", + "Variable plugin result.", + "", + "[SourceFile-0]: custom.md#customts", + "[VariableDeclaration-0]: custom.md#my-variable-customsecretrandomnumber", + ], + }, + Object { + "FileLocation": "to-exclude.md", + "Result": Array [ + "# to-exclude.ts", + "", + "[SourceFile-1]: to-exclude.md#to-excludets", + ], + }, +] +`; diff --git a/packages/ts-docs-gen/tests/cases/simple-project-1/index.ts b/packages/ts-docs-gen/tests/cases/simple-project-1/src/index.ts similarity index 59% rename from packages/ts-docs-gen/tests/cases/simple-project-1/index.ts rename to packages/ts-docs-gen/tests/cases/simple-project-1/src/index.ts index 4d7dd18d..062f3812 100644 --- a/packages/ts-docs-gen/tests/cases/simple-project-1/index.ts +++ b/packages/ts-docs-gen/tests/cases/simple-project-1/src/index.ts @@ -1,3 +1,93 @@ +// #region Types +export type SimpleType = { Property1: string; Property2: string; }; + +export type SimpleTypeParameters = keyof SimpleType; + +export type GenericType = { Property: T; }; + +/** + * General comment about UnionType type. + */ +export type UnionType = string | undefined; + +/** + * General comment about UnionTypeWithLiterals. + * @deprecated + * @beta + */ +export type UnionTypeWithLiterals = { Property1: string; } | { Property2: number; }; + +export type IntersectionType = SimpleType & GenericType; + +export type IntersectionTypeWithLiterals = { Property1: string; } & { Property2: number; }; + +export type Easing = "ease-in" | "ease-out" | "ease-in-out"; + +export type Numbers = 1 | 2 | 3 | 4 | 5 | 6; + +export type Name = string; + +export type NameResolver = () => string; + +export type NameOrResolver = Name | NameResolver; + +export type Tree = { + value: T; + left: Tree; + right: Tree; +}; + +export type LinkedList = T & { next: LinkedList }; + +export type Negative = void | never; + +export type IndexType = { [key: string]: number; }; + +export type SelectedNumbers = Readonly; + +export type PartialSimpleType = Partial; + +export type Proxy = { + get(): T; + set(value: T): void; +}; + +export type TypeWithMultipleTypeParameters = { + PropertyT: T; + PropertyV: V; + PropertyU: U; +}; + +// #region Integrated types + +export type Readonly = { + readonly [P in keyof T]: T[P]; +}; + +export type Partial = { + [P in keyof T]?: T[P]; +}; + +export type Nullable = { + [P in keyof T]: T[P] | null; +}; + +export type Proxify = { + [P in keyof T]: Proxy; +}; + +export type Pick = { + [P in K]: T[P]; +}; + +export type Record = { + [P in K]: T; +}; + +// #endregion Integrated types + +// #endregion Types + // #region Interfaces export interface ExtendedBar extends FooInterface, Boo { OtherStuff: string[]; @@ -128,8 +218,64 @@ export enum EnumListWithStringValues { // #endregion Enums +// #region Variables + export const SampleConst: string = "sample-const"; +export const ArrowFunctionConst = (a: string) => `return-${a}`; + +export let letString = "let"; + +// tslint:disable-next-line:no-var-keyword +export var varString = "var"; + +// tslint:disable-next-line:no-var-keyword only-arrow-functions +export var functionVar = function(): string { + return "functionVar"; +}; + +export const ObjectLiteralConst = { Property: "value" }; + +export const SymbolConst = Symbol("Some description"); + +export const MapConst = new Map(); + +export const AnyMap = new Map(); + +export const RegexConst = /^[A-Za-z]+$/; + +export const NumberLiteralConst = 120; + +export const PredefinedArray = [1, 2]; + +export const Tuple: [number, string] = [10, "ten"]; + +export const TrueConst = true; + +export const BooleanConst: boolean = false; + +export const FooConst: Boo & ExtendedBar = { + Boos: [], + Name: "Name", + OtherStuff: [], + Surname: "Surname", + Type: 12 +}; + +export let FooLet: Boo | ExtendedBar = { + Boos: [] +}; + +export const GetFooConst = GetFoo; + +export const NameResolverConst: NameResolver = () => "resolved"; + +export const StringOrNull: string | null = null; + +export const FunctionConst: () => NameResolver = () => () => "string"; + +// #endregion Variables + export class Foo { public HandleMessage(message: string): string { return message; diff --git a/packages/ts-docs-gen/tests/cases/simple-project-1/test-config.json b/packages/ts-docs-gen/tests/cases/simple-project-1/test-config.json index a058bc3b..4341f70b 100644 --- a/packages/ts-docs-gen/tests/cases/simple-project-1/test-config.json +++ b/packages/ts-docs-gen/tests/cases/simple-project-1/test-config.json @@ -1,5 +1,5 @@ { "EntryFiles": [ - "./index.ts" + "./src/index.ts" ] } diff --git a/packages/ts-docs-gen/tests/cases/simple-project-1/tsconfig.json b/packages/ts-docs-gen/tests/cases/simple-project-1/tsconfig.json index 433fcc04..f37d29d2 100644 --- a/packages/ts-docs-gen/tests/cases/simple-project-1/tsconfig.json +++ b/packages/ts-docs-gen/tests/cases/simple-project-1/tsconfig.json @@ -1,32 +1,29 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "removeComments": false, - "outDir": "dist", - "rootDir": "src", - "inlineSourceMap": true, - "inlineSources": true, - "skipDefaultLibCheck": true, - "declaration": true, - "pretty": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "lib": [ - "es6" - ], - "types": [ - "node" - ], - "typeRoots": [ - "./node_modules/@types" - ] - }, - "exclude": [ - "node_modules", - "dist", - "@types", - "tests", - "examples" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "removeComments": false, + "outDir": "dist", + "rootDir": "src", + "inlineSourceMap": true, + "inlineSources": true, + "skipDefaultLibCheck": true, + "declaration": true, + "pretty": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "lib": [ + "es6" + ], + "typeRoots": [ + "./node_modules/@types" + ] + }, + "exclude": [ + "node_modules", + "dist", + "@types", + "tests", + "examples" + ] } diff --git a/packages/ts-docs-gen/tests/cases/simple-project-2/foo.ts b/packages/ts-docs-gen/tests/cases/simple-project-2/foo.ts deleted file mode 100644 index 58ed1b72..00000000 --- a/packages/ts-docs-gen/tests/cases/simple-project-2/foo.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class Foo { - public GetMessage(message: string): string { - return this.defaultMessage; - } - - private readonly defaultMessage: string = "It's a default message."; -} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-2/index.ts b/packages/ts-docs-gen/tests/cases/simple-project-2/index.ts deleted file mode 100644 index 1c5e60c1..00000000 --- a/packages/ts-docs-gen/tests/cases/simple-project-2/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export { Foo } from "./foo"; - -export class FooStart { - public HandleMessage(message: string): string { - return message; - } -} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-2/src/boo.ts b/packages/ts-docs-gen/tests/cases/simple-project-2/src/boo.ts new file mode 100644 index 00000000..4008cbca --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-2/src/boo.ts @@ -0,0 +1,29 @@ +export abstract class AbstractBoo { + public readonly abstract DefaultBooMessage: string = "Some string with a BooMessage..."; + + constructor() { + this.BooMessage = this.DefaultBooMessage; + } + + public abstract BooMessage: string; + + public abstract BooTheMessage(): string; + + public abstract AbstractBooMember?: string; +} + +export class Boo extends AbstractBoo { + public DefaultBooMessage: string; + + constructor() { + super(); + this.BooMessage += " And more..."; + } + + public BooMessage: string; + public BooTheMessage(): string { + return this.BooMessage; + } + + public AbstractBooMember?: string | undefined; +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-2/src/foo.ts b/packages/ts-docs-gen/tests/cases/simple-project-2/src/foo.ts new file mode 100644 index 00000000..aef689c5 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-2/src/foo.ts @@ -0,0 +1,116 @@ +export interface MessageDto { + Message: T; + Time: string; +} + +// TODO: type parameters description. +/** + * General comment about class Foo. + * + * @template T Message type + */ +export class Foo { + // TODO: check comments on suffix. + /** + * Some constructor. + * + * @param suffix Suffix of message. + */ + constructor(suffix: string | undefined) { + if (suffix == null) { + return; + } + + this.messageSuffix = suffix; + this.IsSuffixSet = true; + } + + // #region Methods + + /** + * private static method `getTimeString` comment. + */ + private static getTimeString(): string { + return new Date().toISOString(); + } + + /** + * public static method `DefaultMessageTypeString` comment. + */ + public static DefaultMessageTypeString(): string { + return "string"; + } + + private resolveMessageDto(message: T, time?: string): MessageDto { + return { + Message: message, + Time: time || Foo.getTimeString() + }; + } + + /** + * @param message Message text. + */ + public GetMessage(message: string): string { + return this.defaultMessage; + } + + // TODO: fix falsy escaped characters in complex types links. + // tslint:disable-next-line:no-empty + public PrintMessage(messageDto: MessageDto): void { } + + public ResolveSimpleMessageObject(message: T): { Message: T } { + return { + Message: message + }; + } + // #endregion Methods + + // #region Properties + + /** + * public static property `Name` comment. + * @deprecated + */ + public static Name: string = "Foo class"; + + private static internalName: string = "Foo class"; + + /** + * private readonly method `defaultMessage` comment. + */ + private readonly defaultMessage: string = "It's a default message."; + + /** + * @beta v0.0.0-beta + */ + private messageSuffix: string | undefined; + + public IsSuffixSet?: boolean = false; + + // #endregion Properties + + // #region Getters + public get DefaultMessage(): string { + return `<${Foo.DefaultMessageTypeString()}> ${this.defaultMessage} - ${this.getMessageSuffix}`; + } + + private get getMessageSuffix(): string { + return "Is a suffix."; + } + // #endregion Getters + + // #region Setters + private set setMessageSuffix(value: string | undefined) { + this.messageSuffix = value; + } + + /** + * @param suffix Message suffix. + */ + public set SetDefaultSuffix(suffix: string) { + this.messageSuffix = suffix; + } + // #endregion Setters + +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-2/src/index.ts b/packages/ts-docs-gen/tests/cases/simple-project-2/src/index.ts new file mode 100644 index 00000000..e5b6cd6e --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-2/src/index.ts @@ -0,0 +1,15 @@ +export { Foo } from "./foo"; + +export interface Start { + HandleMessage(message: string): string; +} + +export class FooStart implements Start { + public HandleMessage(message: string): string { + return message; + } +} + +export class BooStart extends FooStart { + private defaultMessage: string = "This is a default message."; +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-2/test-config.json b/packages/ts-docs-gen/tests/cases/simple-project-2/test-config.json index 182bf979..1e6a16b9 100644 --- a/packages/ts-docs-gen/tests/cases/simple-project-2/test-config.json +++ b/packages/ts-docs-gen/tests/cases/simple-project-2/test-config.json @@ -1,6 +1,7 @@ { "EntryFiles": [ - "./index.ts", - "./foo.ts" + "./src/index.ts", + "./src/foo.ts", + "./src/boo.ts" ] } diff --git a/packages/ts-docs-gen/tests/cases/simple-project-2/tsconfig.json b/packages/ts-docs-gen/tests/cases/simple-project-2/tsconfig.json index 433fcc04..f37d29d2 100644 --- a/packages/ts-docs-gen/tests/cases/simple-project-2/tsconfig.json +++ b/packages/ts-docs-gen/tests/cases/simple-project-2/tsconfig.json @@ -1,32 +1,29 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "removeComments": false, - "outDir": "dist", - "rootDir": "src", - "inlineSourceMap": true, - "inlineSources": true, - "skipDefaultLibCheck": true, - "declaration": true, - "pretty": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "lib": [ - "es6" - ], - "types": [ - "node" - ], - "typeRoots": [ - "./node_modules/@types" - ] - }, - "exclude": [ - "node_modules", - "dist", - "@types", - "tests", - "examples" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "removeComments": false, + "outDir": "dist", + "rootDir": "src", + "inlineSourceMap": true, + "inlineSources": true, + "skipDefaultLibCheck": true, + "declaration": true, + "pretty": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "lib": [ + "es6" + ], + "typeRoots": [ + "./node_modules/@types" + ] + }, + "exclude": [ + "node_modules", + "dist", + "@types", + "tests", + "examples" + ] } diff --git a/packages/ts-docs-gen/tests/cases/simple-project-3/package.json b/packages/ts-docs-gen/tests/cases/simple-project-3/package.json new file mode 100644 index 00000000..5c0ca75c --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-3/package.json @@ -0,0 +1,13 @@ +{ + "name": "simple-project-3", + "private": true, + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-3/src/index.ts b/packages/ts-docs-gen/tests/cases/simple-project-3/src/index.ts new file mode 100644 index 00000000..f8777a4b --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-3/src/index.ts @@ -0,0 +1,3 @@ +export * from "./simple-namespaces"; +export * from "./split-namespace"; +export * from "./namespace-in-namespace"; diff --git a/packages/ts-docs-gen/tests/cases/simple-project-3/src/namespace-in-namespace.ts b/packages/ts-docs-gen/tests/cases/simple-project-3/src/namespace-in-namespace.ts new file mode 100644 index 00000000..1169931e --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-3/src/namespace-in-namespace.ts @@ -0,0 +1,16 @@ +export namespace NamespaceOne { + export namespace NamespaceTwo { + export class SomeClass { + public static Name: string = "_some_class"; + } + } + + export namespace NamespaceThree { + export namespace NamespaceFour { + export interface InterfaceInFour { + Property1: string; + Property2: string; + } + } + } +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-3/src/simple-namespaces.ts b/packages/ts-docs-gen/tests/cases/simple-project-3/src/simple-namespaces.ts new file mode 100644 index 00000000..b2a4bdd1 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-3/src/simple-namespaces.ts @@ -0,0 +1,21 @@ +/** + * General comment about SimpleNamespace. + */ +export namespace SimpleNamespace { + export interface SimpleInterface { + Property1: string; + Property2: string; + } + + export const SimpleObject: AnotherSimpleNamespace.SimpleInterface = { + Property1: "1", + Property2: "2", + Property3: "3" + }; +} + +export namespace AnotherSimpleNamespace { + export interface SimpleInterface extends SimpleNamespace.SimpleInterface { + Property3: string; + } +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-3/src/split-namespace.ts b/packages/ts-docs-gen/tests/cases/simple-project-3/src/split-namespace.ts new file mode 100644 index 00000000..c5d9b5fc --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-3/src/split-namespace.ts @@ -0,0 +1,24 @@ +// https://www.typescriptlang.org/docs/handbook/declaration-merging.html +export namespace Validation { + export interface StringValidator { + isAcceptable(s: string): boolean; + } +} + +export namespace Validation { + const lettersRegexp = /^[A-Za-z]+$/; + export class LettersOnlyValidator implements StringValidator { + public isAcceptable(s: string): boolean { + return lettersRegexp.test(s); + } + } +} + +export namespace Validation { + const numberRegexp = /^[0-9]+$/; + export class ZipCodeValidator implements StringValidator { + public isAcceptable(s: string): boolean { + return s.length === 5 && numberRegexp.test(s); + } + } +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-3/test-config.json b/packages/ts-docs-gen/tests/cases/simple-project-3/test-config.json new file mode 100644 index 00000000..4341f70b --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-3/test-config.json @@ -0,0 +1,5 @@ +{ + "EntryFiles": [ + "./src/index.ts" + ] +} diff --git a/tools/test-generator-cli/tsconfig.json b/packages/ts-docs-gen/tests/cases/simple-project-3/tsconfig.json similarity index 73% rename from tools/test-generator-cli/tsconfig.json rename to packages/ts-docs-gen/tests/cases/simple-project-3/tsconfig.json index 2fe54924..f37d29d2 100644 --- a/tools/test-generator-cli/tsconfig.json +++ b/packages/ts-docs-gen/tests/cases/simple-project-3/tsconfig.json @@ -12,14 +12,8 @@ "pretty": true, "strict": true, "forceConsistentCasingInFileNames": true, - "noUnusedLocals": true, - "skipLibCheck": true, "lib": [ - "es6", - "es2017.object" - ], - "types": [ - "node" + "es6" ], "typeRoots": [ "./node_modules/@types" @@ -28,6 +22,8 @@ "exclude": [ "node_modules", "dist", - "@types" + "@types", + "tests", + "examples" ] } diff --git a/packages/ts-docs-gen/tests/cases/simple-project-4/case.test.tpl b/packages/ts-docs-gen/tests/cases/simple-project-4/case.test.tpl new file mode 100644 index 00000000..d5dbb4bc --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-4/case.test.tpl @@ -0,0 +1,52 @@ +import * as path from "path"; +import { ModuleKind, ScriptTarget } from "typescript"; +import { Generator } from "@src/generator"; +import { GeneratorConfigurationBuilder } from "@src/builders/generator-configuration-builder"; +import { VariablePlugin } from "../simple-project-4/src/variable-plugin"; + +test("{{caseName}}", async done => { + const projectDirectory = "{{projectDirectory}}"; + const testConfig = {{{json testConfig}}}; + const entryFiles = testConfig.EntryFiles; + + try { + const myCompilerOptions = { + module: ModuleKind.CommonJS, + target: ScriptTarget.ES2015, + removeComments: false, + outDir: "dist", + rootDir: "src", + inlineSourceMap: true, + inlineSources: true, + skipDefaultLibCheck: true, + declaration: true, + pretty: true, + strict: false, + forceConsistentCasingInFileNames: true, + lib: [ + "es6", + "dom" + ], + typeRoots: [ + "../../../../node_modules/@types" + ] + }; + + const configuration = await new GeneratorConfigurationBuilder(projectDirectory) + .AddPlugins([new VariablePlugin]) + .OverrideCompilerOptions(myCompilerOptions) + .OverrideConfiguration({ + projectDirectory: path.join(projectDirectory, "src/project-to-doc/custom"), + exclude: ["./to-exclude.ts"] + }) + .SetOutputDirectory("./docs") + .Build(entryFiles); + + const generator = new Generator(configuration); + + expect(generator.OutputData).toMatchSnapshot(); + done(); + } catch (error) { + done.fail(error); + } +}); diff --git a/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/custom/custom.ts b/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/custom/custom.ts new file mode 100644 index 00000000..03f36286 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/custom/custom.ts @@ -0,0 +1 @@ +export const CustomSecretRandomNumber = "5"; diff --git a/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/custom/to-exclude.ts b/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/custom/to-exclude.ts new file mode 100644 index 00000000..d97075b7 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/custom/to-exclude.ts @@ -0,0 +1 @@ +export const ExcludedFileValue = "13"; diff --git a/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/index.ts b/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/index.ts new file mode 100644 index 00000000..465a81bf --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-4/src/project-to-doc/index.ts @@ -0,0 +1 @@ +export const SecretRandomNumber = "4"; diff --git a/packages/ts-docs-gen/tests/cases/simple-project-4/src/variable-plugin.ts b/packages/ts-docs-gen/tests/cases/simple-project-4/src/variable-plugin.ts new file mode 100644 index 00000000..f7338405 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-4/src/variable-plugin.ts @@ -0,0 +1,36 @@ +import { Contracts } from "ts-extractor"; +import { BasePlugin } from "@src/abstractions/base-plugin"; +import { SupportedApiItemKindType, PluginResult, PluginOptions } from "@src/contracts/plugin"; +import { GeneratorHelpers } from "@src/generator-helpers"; +import { MarkdownBuilder } from "@simplrjs/markdown"; + +export class VariablePlugin extends BasePlugin { + public SupportedApiDefinitionKind(): SupportedApiItemKindType[] { + return [GeneratorHelpers.ApiDefinitionKind.Variable]; + } + + public Render(options: PluginOptions, apiItem: Contracts.ApiVariableDto): PluginResult { + const heading: string = `My variable ${options.Reference.Alias}`; + + const pluginResult: PluginResult = { + ...GeneratorHelpers.GetDefaultPluginResultData(), + ApiItem: apiItem, + Reference: options.Reference, + Headings: [ + { + ApiItemId: options.Reference.Id, + Heading: heading + } + ], + UsedReferences: [options.Reference.Id] + }; + + pluginResult.Result = new MarkdownBuilder() + .Header(heading, 3) + .EmptyLine() + .Text("Variable plugin result.") + .GetOutput(); + + return pluginResult; + } +} diff --git a/packages/ts-docs-gen/tests/cases/simple-project-4/test-config.json b/packages/ts-docs-gen/tests/cases/simple-project-4/test-config.json new file mode 100644 index 00000000..1572ab38 --- /dev/null +++ b/packages/ts-docs-gen/tests/cases/simple-project-4/test-config.json @@ -0,0 +1,6 @@ +{ + "EntryFiles": [ + "./custom.ts", + "./to-exclude.ts" + ] +} diff --git a/packages/ts-docs-gen/tests/tsconfig.json b/packages/ts-docs-gen/tests/tsconfig.json index 48e57492..071d945f 100644 --- a/packages/ts-docs-gen/tests/tsconfig.json +++ b/packages/ts-docs-gen/tests/tsconfig.json @@ -19,6 +19,7 @@ ], "lib": [ "es6", + "es2017.object", "dom" ], "paths": { diff --git a/rush.json b/rush.json index 2b0a59a5..6d249e89 100644 --- a/rush.json +++ b/rush.json @@ -7,11 +7,6 @@ "packageName": "ts-docs-gen", "projectFolder": "packages/ts-docs-gen", "shouldPublish": false - }, - { - "packageName": "test-generator-cli", - "projectFolder": "tools/test-generator-cli", - "shouldPublish": false } ] } diff --git a/tools/test-generator-cli/package.json b/tools/test-generator-cli/package.json deleted file mode 100644 index 80e24bc6..00000000 --- a/tools/test-generator-cli/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "test-generator-cli", - "private": true, - "version": "0.1.0", - "description": "Generating tests.", - "main": "index.js", - "scripts": { - "build": "tsc -p .", - "watch": "tsc -w", - "pretest": "npm run build -- --noEmit", - "test": "npm run tslint", - "test-ci": "npm test", - "tslint": "tslint --project . --config ./tslint.json && echo Successfully passed tslint test." - }, - "keywords": [], - "author": "simplrjs (https://github.com/simplrjs)", - "dependencies": { - "@types/fs-extra": "^4.0.5", - "@types/handlebars": "^4.0.36", - "@types/yargs": "^10.0.0", - "fast-glob": "^1.0.1", - "fs-extra": "^4.0.2", - "handlebars": "^4.0.11", - "simplr-logger": "^1.0.0", - "typescript": "^2.6.2", - "yargs": "^10.0.3" - }, - "devDependencies": { - "simplr-tslint": "0.0.1", - "tslint": "^5.8.0" - } -} diff --git a/tools/test-generator-cli/src/cli-arguments.ts b/tools/test-generator-cli/src/cli-arguments.ts deleted file mode 100644 index b37ea4b2..00000000 --- a/tools/test-generator-cli/src/cli-arguments.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as yargs from "yargs"; - -import { GetVersion } from "./cli-helpers"; -import { CLIArgumentsObject } from "./cli-contracts"; - -/** - * Handles all CLI commands and arguments. - */ -export const CLIHandler = yargs - .showHelpOnFail(true) - .help("h", "Show help") - .alias("h", "help") - .version(`Current version: ${GetVersion()}`) - .alias("v", "version") - // CLI options - .option("project", { - describe: "Project directory path.", - type: "string" - }) - .alias("p", "project") - .argv as CLIArgumentsObject; diff --git a/tools/test-generator-cli/src/cli-contracts.ts b/tools/test-generator-cli/src/cli-contracts.ts deleted file mode 100644 index 7b33725c..00000000 --- a/tools/test-generator-cli/src/cli-contracts.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Arguments } from "yargs"; - -/** - * Base properties of `package.json`. - */ -export interface BasePackage { - name: string; - version: string; - description?: string; - main: string; - author?: string; - license?: string; -} - -/** - * Argument of CLI. - */ -export interface CLIArgumentsObject extends Arguments { - path?: string; -} diff --git a/tools/test-generator-cli/src/cli-helpers.ts b/tools/test-generator-cli/src/cli-helpers.ts deleted file mode 100644 index cf825bb4..00000000 --- a/tools/test-generator-cli/src/cli-helpers.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as fs from "fs-extra"; -import * as path from "path"; - -import { BasePackage } from "./cli-contracts"; - -/** - * Path from current file to a `package.json`. - */ -const PACKAGE_JSON_PATH = "../package.json"; - -/** - * Object of `package.json`. - */ -export const PACKAGE_JSON = fs.readJSONSync(path.join(__dirname, PACKAGE_JSON_PATH)) as BasePackage; - -/** - * Get version string from `package.json`. - */ -export function GetVersion(): string { - return PACKAGE_JSON.version; -} diff --git a/tools/test-generator-cli/src/index.ts b/tools/test-generator-cli/src/index.ts deleted file mode 100644 index 73d24417..00000000 --- a/tools/test-generator-cli/src/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -import * as fs from "fs-extra"; -import * as path from "path"; - -import { Logger } from "./utils/logger"; -import { TestsGenerator } from "./tests-generator"; -import { FixSep, TESTS_DIR_NAME, CASES_DIR_NAME } from "./tests-helpers"; -import { TestsCleanup } from "./tests-cleanup"; -import { CLIHandler } from "./cli-arguments"; -import { CLIArgumentsObject } from "./cli-contracts"; - -async function StartWatcher(testsCasesPath: string): Promise { - return fs.watch(`${testsCasesPath}/`, async (event, fileName) => { - if (fileName.indexOf(TESTS_DIR_NAME) === -1) { - Logger.Info(`Test file was changed in "${testsCasesPath}/${fileName}".`); - const startBuild = Logger.Info(`Generating tests for "${testsCasesPath}"...`); - await TestsGenerator(testsCasesPath); - Logger.Debug(`Generated tests after ${(Date.now() - startBuild)}ms`); - } - }); -} - -(async (argumentsObject: CLIArgumentsObject) => { - const cwd = argumentsObject.path || process.cwd(); - const testsCasesPath = FixSep(path.join(cwd, TESTS_DIR_NAME, CASES_DIR_NAME)); - - Logger.Info("Starting test generator..."); - const startRemove = Logger.Info(`Removing old tests from "${testsCasesPath}"...`); - await TestsCleanup(testsCasesPath); - Logger.Debug(`Removed old tests after ${(Date.now() - startRemove)}ms`); - - const startBuild = Logger.Info(`Generating tests for "${testsCasesPath}"...`); - await TestsGenerator(testsCasesPath); - Logger.Debug(`Generated tests after ${(Date.now() - startBuild)}ms`); - - if (process.argv.indexOf("--watchAll") !== -1) { - Logger.Info(`Started watching "${testsCasesPath}" tests.`); - StartWatcher(testsCasesPath); - } -})(CLIHandler); diff --git a/tools/test-generator-cli/src/tests-cleanup.ts b/tools/test-generator-cli/src/tests-cleanup.ts deleted file mode 100644 index 1fde9c3a..00000000 --- a/tools/test-generator-cli/src/tests-cleanup.ts +++ /dev/null @@ -1,22 +0,0 @@ -import * as fs from "fs-extra"; -import * as path from "path"; -import fastGlob from "fast-glob"; - -import { - GENERATED_TESTS_DIR_NAME, - TESTS_SNAPSHOTS_DIR_NAME, - FixSep -} from "./tests-helpers"; - -export async function TestsCleanup(testsCasesPath: string): Promise { - const generatedTestsDirPath = FixSep(path.join(testsCasesPath, GENERATED_TESTS_DIR_NAME)); - - const oldTestFiles = await fastGlob(`${generatedTestsDirPath}/**/*`, { - onlyFiles: true, - ignore: [`**/${TESTS_SNAPSHOTS_DIR_NAME}/**`] - }); - - for (const pathname of oldTestFiles) { - await fs.remove(pathname); - } -} diff --git a/tools/test-generator-cli/src/tests-generator.ts b/tools/test-generator-cli/src/tests-generator.ts deleted file mode 100644 index 1eaa752e..00000000 --- a/tools/test-generator-cli/src/tests-generator.ts +++ /dev/null @@ -1,67 +0,0 @@ -import * as path from "path"; -import * as fs from "fs-extra"; -import fastGlob from "fast-glob"; -import * as handlebars from "handlebars"; - -import { - FixSep, - GENERATED_TESTS_DIR_NAME, - TESTS_CONFIG_FILE_NAME, - DEFAULT_TEMPLATE_FILE_NAME, - CASE_TEMPLATE_FILE_NAME, - RegisterJSONStringifyHandlebarHelper -} from "./tests-helpers"; -import { Logger } from "./utils/logger"; - -export interface Configuration { - EntryFiles: string[]; -} - -export async function TestsGenerator(testsCasesPath: string): Promise { - const defaultTemplatePath = FixSep(path.join(testsCasesPath, "..", DEFAULT_TEMPLATE_FILE_NAME)); - if (!await fs.pathExists(defaultTemplatePath)) { - Logger.Error(`Not found package default template. Expected file location: "${defaultTemplatePath}"`); - return; - } - - const casesDirPaths = await fastGlob( - [ - `${testsCasesPath}/*` - ], - { - onlyDirs: true, - ignore: [`**/${GENERATED_TESTS_DIR_NAME}/**`] - }); - - const targetDirectory = path.join(testsCasesPath, GENERATED_TESTS_DIR_NAME); - await fs.ensureDir(targetDirectory); - - RegisterJSONStringifyHandlebarHelper(); - - for (const caseDirPath of casesDirPaths) { - const { name } = path.parse(caseDirPath); - - const caseTemplatePath = FixSep(path.join(caseDirPath, CASE_TEMPLATE_FILE_NAME)); - let templatePath: string; - if (await fs.pathExists(caseTemplatePath)) { - templatePath = caseTemplatePath; - } else { - templatePath = defaultTemplatePath; - } - - const testConfigPath = FixSep(path.join(caseDirPath, TESTS_CONFIG_FILE_NAME)); - const testConfig = await fs.readJSON(testConfigPath) as Configuration; - - const source = await fs.readFile(templatePath, "utf8"); - const template = handlebars.compile(source); - const data = { - "caseName": name, - "projectDirectory": caseDirPath, - "testConfig": testConfig - }; - const testDescribe = template(data); - - const targetFilePathName = path.join(targetDirectory, `${name}.test.ts`); - await fs.writeFile(targetFilePathName, testDescribe); - } -} diff --git a/tools/test-generator-cli/src/tests-helpers.ts b/tools/test-generator-cli/src/tests-helpers.ts deleted file mode 100644 index 500b2a71..00000000 --- a/tools/test-generator-cli/src/tests-helpers.ts +++ /dev/null @@ -1,23 +0,0 @@ -import * as path from "path"; -import * as handlebars from "handlebars"; - -export function FixSep(pathname: string): string { - return pathname.split(path.sep).join("/"); -} - -export function RegisterJSONStringifyHandlebarHelper(): void { - handlebars.registerHelper("json", (value: any) => - new handlebars.SafeString( - JSON.stringify(value) - )); -} - -export const TESTS_DIR_NAME = "tests"; -export const CASES_DIR_NAME = "cases"; - -export const GENERATED_TESTS_DIR_NAME = "__tests__"; -export const TESTS_SNAPSHOTS_DIR_NAME = "__snapshots__"; - -export const TESTS_CONFIG_FILE_NAME = "test-config.json"; -export const DEFAULT_TEMPLATE_FILE_NAME = "default.test.tpl"; -export const CASE_TEMPLATE_FILE_NAME = "case.test.tpl"; diff --git a/tools/test-generator-cli/src/utils/logger.ts b/tools/test-generator-cli/src/utils/logger.ts deleted file mode 100644 index 55b1a36d..00000000 --- a/tools/test-generator-cli/src/utils/logger.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { LoggerBuilder, LoggerConfigurationBuilder, LogLevel } from "simplr-logger"; - -const LoggerConfiguration = new LoggerConfigurationBuilder() - .SetDefaultLogLevel(LogLevel.Trace) - .Build(); - -export const Logger = new LoggerBuilder(LoggerConfiguration); diff --git a/tools/test-generator-cli/tslint.json b/tools/test-generator-cli/tslint.json deleted file mode 100644 index 3385cef2..00000000 --- a/tools/test-generator-cli/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "simplr-tslint" -}