diff --git a/README.md b/README.md index 0f3aa1288..3505e29e5 100644 --- a/README.md +++ b/README.md @@ -14,28 +14,28 @@ [:date: Current maintenance status](https://github.com/documentationjs/documentation/wiki/Current-maintenance-status) -* Supports modern JavaScript: ES5, ES2017, JSX, Vue and [Flow](https://flow.org/) type annotations. -* Infers parameters, types, membership, and more. Write less documentation: let the computer write it for you. -* Integrates with GitHub to link directly from documentation to the code it refers to. -* Customizable output: HTML, JSON, Markdown, and more +- Supports modern JavaScript: ES5, ES2017, JSX, Vue and [Flow](https://flow.org/) type annotations. +- Infers parameters, types, membership, and more. Write less documentation: let the computer write it for you. +- Integrates with GitHub to link directly from documentation to the code it refers to. +- Customizable output: HTML, JSON, Markdown, and more ## Examples -- [HTML output with default template](https://documentation.js.org/html-example/) -- [Markdown](https://github.com/documentationjs/documentation/blob/master/docs/NODE_API.md) -- [JSON](https://documentation.js.org/html-example/index.json) +- [HTML output with default template](https://documentation.js.org/html-example/) +- [Markdown](https://github.com/documentationjs/documentation/blob/master/docs/NODE_API.md) +- [JSON](https://documentation.js.org/html-example/index.json) ## Documentation -- [Getting Started](docs/GETTING_STARTED.md): start here -- [Usage](docs/USAGE.md): how to use documentation.js -- [Recipes](docs/RECIPES.md): tricks for writing effective JSDoc docs -- [Node API](docs/NODE_API.md): documentation.js's self-generated documentation -- [Configuring documentation.js](docs/CONFIG.md) -- [FAQ](docs/FAQ.md) -- [Troubleshooting](docs/TROUBLESHOOTING.md) -- [Theming](docs/THEMING.md): tips for theming documentation output in HTML -- [See also](https://github.com/documentationjs/documentation/wiki/See-also): a list of projects similar to documentation.js +- [Getting Started](docs/GETTING_STARTED.md): start here +- [Usage](docs/USAGE.md): how to use documentation.js +- [Recipes](docs/RECIPES.md): tricks for writing effective JSDoc docs +- [Node API](docs/NODE_API.md): documentation.js's self-generated documentation +- [Configuring documentation.js](docs/CONFIG.md) +- [FAQ](docs/FAQ.md) +- [Troubleshooting](docs/TROUBLESHOOTING.md) +- [Theming](docs/THEMING.md): tips for theming documentation output in HTML +- [See also](https://github.com/documentationjs/documentation/wiki/See-also): a list of projects similar to documentation.js ## User Guide @@ -62,12 +62,6 @@ documentation build src/** -f html --github -o docs # document index.js, ignoring any files it requires or imports documentation build index.js -f md --shallow -# build and serve HTML docs for app.js -documentation serve app.js - -# build, serve, and live-update HTML docs for app.js -documentation serve --watch app.js - # validate JSDoc syntax in util.js documentation lint util.js @@ -81,7 +75,6 @@ documentation build --document-exported index.js documentation build index.ts --parse-extension ts -f html -o docs Commands: - serve [input..] generate, update, and display HTML documentation build [input..] build documentation lint [input..] check for common style and uniformity mistakes readme [input..] inject documentation into your README.md @@ -97,9 +90,9 @@ _We have plenty of [issues](https://github.com/documentationjs/documentation/issues) that we'd love help with._ -- Robust and complete `JSDoc` support, including typedefs. -- Strong support for HTML and Markdown output -- Documentation coverage, statistics, and validation +- Robust and complete `JSDoc` support, including typedefs. +- Strong support for HTML and Markdown output +- Documentation coverage, statistics, and validation documentation is an OPEN Open Source Project. This means that: diff --git a/__tests__/lib/__snapshots__/server.js.snap b/__tests__/lib/__snapshots__/server.js.snap deleted file mode 100644 index 102e52d2f..000000000 --- a/__tests__/lib/__snapshots__/server.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`server 1`] = `"test = 123"`; - -exports[`server 2`] = `"var test = 123;"`; - -exports[`server 3`] = `""`; diff --git a/__tests__/lib/server.js b/__tests__/lib/server.js deleted file mode 100644 index ae33e2b64..000000000 --- a/__tests__/lib/server.js +++ /dev/null @@ -1,59 +0,0 @@ -import { get } from '../utils'; -import File from 'vinyl'; -import getPort from 'get-port'; -import Server from '../../src/serve/server.js'; - -const jsFile = new File({ - cwd: '/', - base: '/test/', - path: '/test/file.js', - contents: Buffer.from('var test = 123;') -}); - -const coffeeFile = new File({ - cwd: '/', - base: '/test/', - path: '/test/file.coffee', - contents: Buffer.from('test = 123') -}); - -const indexFile = new File({ - cwd: '/', - base: '/test/', - path: '/test/index.html', - contents: Buffer.from('') -}); - -test('server - throws on bad port', function () { - expect(function () { - const server = new Server('${port}'); - }).toThrow(); - expect(function () { - const server = new Server(); - }).toThrow(); -}); - -test('server', async function () { - const port = await getPort(); - const server = new Server(port, true); - expect(server).toBeTruthy(); - await server.start(); - try { - await get(`http://localhost:${port}/file.coffee`); - } catch (code) { - expect(code).toEqual(404); - } - - server.setFiles([coffeeFile]); - let text; - - text = await get(`http://localhost:${port}/file.coffee`); - expect(text).toMatchSnapshot(); - server.setFiles([coffeeFile, jsFile]); - text = await get(`http://localhost:${port}/file.js`); - expect(text).toMatchSnapshot(); - server.setFiles([coffeeFile, indexFile, jsFile]); - text = await get(`http://localhost:${port}/`); - expect(text).toMatchSnapshot(); - await server.stop(); -}); diff --git a/bin/documentation.js b/bin/documentation.js index a32d7750a..057d3949e 100755 --- a/bin/documentation.js +++ b/bin/documentation.js @@ -8,7 +8,6 @@ import commands from '../src/commands/index.js'; yargs(hideBin(process.argv)) .strict() - .command(commands.serve) .command(commands.build) .command(commands.lint) .command(commands.readme) diff --git a/package-lock.json b/package-lock.json index c29bc179b..2c3f799d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1172,11 +1172,6 @@ "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true }, - "ansi-html": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/ansi-html/-/ansi-html-0.0.7.tgz", - "integrity": "sha1-gTWEAhliqenm/QOflA0S9WynhZ4=" - }, "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -1324,17 +1319,6 @@ "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==" }, - "body": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/body/-/body-5.1.0.tgz", - "integrity": "sha1-5LoM5BCkaTYyM2dgnstOZVMSUGk=", - "requires": { - "continuable-cache": "^0.3.1", - "error": "^7.0.0", - "raw-body": "~1.1.0", - "safe-json-parse": "~1.0.1" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1404,11 +1388,6 @@ "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", "integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E=" }, - "bytes": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-1.0.0.tgz", - "integrity": "sha1-NWnt6Lo0MV+rmcPpLLBMciDeH6g=" - }, "cached-path-relative": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/cached-path-relative/-/cached-path-relative-1.0.2.tgz", @@ -1648,60 +1627,6 @@ "wrap-ansi": "^7.0.0" } }, - "clone": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", - "integrity": "sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=" - }, - "clone-buffer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/clone-buffer/-/clone-buffer-1.0.0.tgz", - "integrity": "sha1-4+JbIHrE5wGvch4staFnksrD3Fg=" - }, - "clone-stats": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-1.0.0.tgz", - "integrity": "sha1-s3gt/4u1R04Yuba/D9/ngvh3doA=" - }, - "cloneable-readable": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/cloneable-readable/-/cloneable-readable-1.1.3.tgz", - "integrity": "sha512-2EF8zTQOxYq70Y4XKtorQupqF0m49MBz2/yf5Bj+MHjvpG3Hy7sImifnqD6UA+TKYxeSV+u6qqQPawN5UvnpKQ==", - "requires": { - "inherits": "^2.0.1", - "process-nextick-args": "^2.0.0", - "readable-stream": "^2.3.5" - }, - "dependencies": { - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" - }, - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "requires": { - "safe-buffer": "~5.1.0" - } - } - } - }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -1877,11 +1802,6 @@ "typedarray": "^0.0.6" } }, - "continuable-cache": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/continuable-cache/-/continuable-cache-0.3.1.tgz", - "integrity": "sha1-vXJ6f67XfnH/OYWskzUakSczrQ8=" - }, "conventional-changelog": { "version": "3.1.24", "resolved": "https://registry.npmjs.org/conventional-changelog/-/conventional-changelog-3.1.24.tgz", @@ -2551,14 +2471,6 @@ "ansi-colors": "^4.1.1" } }, - "error": { - "version": "7.2.1", - "resolved": "https://registry.npmjs.org/error/-/error-7.2.1.tgz", - "integrity": "sha512-fo9HBvWnx3NGUKMvMwB/CBCMMrfEJgbDTVDEkPygA3Bdd3lM1OyCd+rbQ8BwnpF6GdVeOLDNmyL4N5Bg80ZvdA==", - "requires": { - "string-template": "~0.2.1" - } - }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -2952,14 +2864,6 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, - "faye-websocket": { - "version": "0.11.4", - "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.11.4.tgz", - "integrity": "sha512-CzbClwlXAuiRQAlUyfqPgvPoNKTckTPGfwZV4ZdAhVcP2lh9KUxJg2b5GkE7XbjKQ3YJnQ9z6D9ntLAlB+tP8g==", - "requires": { - "websocket-driver": ">=0.5.1" - } - }, "fb-watchman": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.1.tgz", @@ -3216,11 +3120,6 @@ } } }, - "get-port": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-5.1.1.tgz", - "integrity": "sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==" - }, "get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", @@ -3534,11 +3433,6 @@ "resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-2.0.0.tgz", "integrity": "sha512-4OYzQQsBt0G9bJ/nM9/DDsjm4+fVdzAaPJJcWk5QwA3GIAPxQEeOR0rsI8HbDHQz5Gta8pVvGnnTNSbZVEVvkQ==" }, - "http-parser-js": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.3.tgz", - "integrity": "sha512-t7hjvef/5HEK7RWTdUzVUhl8zkEu+LlaE0IYzdMuvbSDipxBRpOn4Uhw8ZyECEa808iVT8XCjzo6xmYt4CiLZg==" - }, "http-proxy-agent": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", @@ -4796,11 +4690,6 @@ "wrap-ansi": "^7.0.0" } }, - "livereload-js": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/livereload-js/-/livereload-js-3.3.2.tgz", - "integrity": "sha512-w677WnINxFkuixAoUEXOStewzLYGI76XVag+0JWMMEyjJQKs0ibWZMxkTlB96Lm3EjZ7IeOxVziBEbtxVQqQZA==" - }, "load-json-file": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", @@ -5806,11 +5695,6 @@ "picomatch": "^2.2.3" } }, - "mime": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.5.2.tgz", - "integrity": "sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg==" - }, "mime-db": { "version": "1.50.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.50.0.tgz", @@ -6056,11 +5940,6 @@ "integrity": "sha512-h2AatdwYH+JHiZpv7pt/gSX1XoRGb7L/qSIeuqA6GwYoF9w1vP1cw42TO0aI2pNyshRK5893hNSl+1//vHK7hQ==", "dev": true }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" - }, "object-inspect": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz", @@ -6458,22 +6337,6 @@ "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", "integrity": "sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g==" }, - "raw-body": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-1.1.7.tgz", - "integrity": "sha1-HQJ8K/oRasxmI7yo8AAWVyqH1CU=", - "requires": { - "bytes": "1", - "string_decoder": "0.10" - }, - "dependencies": { - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" - } - } - }, "react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", @@ -6746,16 +6609,6 @@ "unified": "^10.0.0" } }, - "remove-trailing-separator": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", - "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=" - }, - "replace-ext": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.1.tgz", - "integrity": "sha512-yD5BHCe7quCgBph4rMQ+0KkIRKwWCrHDOX1p1Gp6HwjPM5kVoCdKGNhN7ydqqsX6lJEnQDKZ/tFMiEdQ1dvPEw==" - }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -6860,11 +6713,6 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, - "safe-json-parse": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/safe-json-parse/-/safe-json-parse-1.0.1.tgz", - "integrity": "sha1-PnZyPjjf3aE8mx0poeB//uSzC1c=" - }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -7233,11 +7081,6 @@ "strip-ansi": "^6.0.0" } }, - "string-template": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/string-template/-/string-template-0.2.1.tgz", - "integrity": "sha1-QpMuWYo1LQH8IuwzZ9nYTuxsmt0=" - }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -7475,29 +7318,6 @@ } } }, - "tiny-lr": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/tiny-lr/-/tiny-lr-2.0.0.tgz", - "integrity": "sha512-f6nh0VMRvhGx4KCeK1lQ/jaL0Zdb5WdR+Jk8q9OSUQnaSDxAEGH1fgqLZ+cMl5EW3F2MGnCsalBO1IsnnogW1Q==", - "requires": { - "body": "^5.1.0", - "debug": "^3.1.0", - "faye-websocket": "^0.11.3", - "livereload-js": "^3.3.1", - "object-assign": "^4.1.0", - "qs": "^6.4.0" - }, - "dependencies": { - "debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", - "requires": { - "ms": "^2.1.1" - } - } - } - }, "tmp": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", @@ -7938,19 +7758,6 @@ } } }, - "vinyl": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.2.1.tgz", - "integrity": "sha512-LII3bXRFBZLlezoG5FfZVcXflZgWP/4dCwKtxd5ky9+LOtM4CS3bIRQsmR1KMnMW07jpE8fqR2lcxPZ+8sJIcw==", - "requires": { - "clone": "^2.1.1", - "clone-buffer": "^1.0.0", - "clone-stats": "^1.0.0", - "cloneable-readable": "^1.0.0", - "remove-trailing-separator": "^1.0.1", - "replace-ext": "^1.0.0" - } - }, "vue-template-compiler": { "version": "2.6.14", "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.6.14.tgz", @@ -7994,21 +7801,6 @@ "integrity": "sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==", "dev": true }, - "websocket-driver": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz", - "integrity": "sha512-b17KeDIQVjvb0ssuSDF2cYXSg2iztliJ4B9WdsuB6J952qCPKmnVq4DyW5motImXHDC1cBT/1UezrJVsKw5zjg==", - "requires": { - "http-parser-js": ">=0.5.1", - "safe-buffer": ">=5.1.0", - "websocket-extensions": ">=0.1.1" - } - }, - "websocket-extensions": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.4.tgz", - "integrity": "sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==" - }, "whatwg-encoding": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz", diff --git a/package.json b/package.json index dc1be9959..c5fa845bc 100644 --- a/package.json +++ b/package.json @@ -14,14 +14,12 @@ "@babel/parser": "^7.15.4", "@babel/traverse": "^7.15.4", "@babel/types": "^7.14.1", - "ansi-html": "^0.0.7", "babelify": "^10.0.0", "chalk": "^4.1.2", "chokidar": "^3.4.0", "concat-stream": "^2.0.0", "diff": "^5.0.0", "doctrine-temporary-fork": "2.1.0", - "get-port": "^5.0.0", "git-url-parse": "^11.1.2", "github-slugger": "1.4.0", "glob": "^7.1.2", @@ -34,7 +32,6 @@ "mdast-util-inject": "^1.1.0", "micromark-util-character": "^1.1.0", "micromatch": "^4.0.4", - "mime": "^2.2.0", "module-deps-sortable": "^5.0.3", "parse-filepath": "^1.0.2", "pify": "^5.0.0", @@ -47,13 +44,11 @@ "resolve": "^1.8.1", "stream-array": "^1.1.2", "strip-json-comments": "^4.0.0", - "tiny-lr": "^2.0.0", "unist-builder": "^2.0.3", "unist-util-visit": "^2.0.3", "vfile": "^5.1.1", "vfile-reporter": "^7.0.2", "vfile-sort": "^3.0.0", - "vinyl": "^2.1.0", "yargs": "^17.2.1" }, "optionalDependencies": { diff --git a/src/commands/index.js b/src/commands/index.js index 1d6544509..8af23945d 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -9,8 +9,7 @@ * to parse additional arguments. */ import build from './build.js'; -import serve from './serve.js'; import lint from './lint.js'; import readme from './readme.js'; -export default { build, serve, lint, readme }; +export default { build, lint, readme }; diff --git a/src/commands/serve.js b/src/commands/serve.js deleted file mode 100644 index 452d71f8f..000000000 --- a/src/commands/serve.js +++ /dev/null @@ -1,96 +0,0 @@ -import errorPage from '../serve/error_page.js'; -import fs from 'fs'; -import path from 'path'; -import chokidar from 'chokidar'; -import { sharedOutputOptions, sharedInputOptions } from './shared_options.js'; -import Server from '../serve/server.js'; -import _ from 'lodash'; -import getPort from 'get-port'; -import * as documentation from '../index.js'; - -const command = 'serve [input..]'; -const description = 'generate, update, and display HTML documentation'; -/** - * Add yargs parsing for the serve command - * @param {Object} yargs module instance - * @returns {Object} yargs with options - * @private - */ -const builder = Object.assign({}, sharedOutputOptions, sharedInputOptions, { - port: { - describe: 'preferred port for the local server', - type: 'number', - default: 4001 - } -}); - -/** - * Wrap the documentation build command along with a server, making it possible - * to preview changes live - * @private - * @param {Object} argv cli input - * @returns {undefined} has side effects - */ -const handler = function serve(argv) { - argv._handled = true; - - if (!argv.input.length) { - try { - argv.input = [ - JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8')) - .main || 'index.js' - ]; - } catch (e) { - throw new Error( - 'documentation was given no files and was not run in a module directory' - ); - } - } - - getPort({ port: argv.port }).then(port => { - const server = new Server(port); - let watcher; - - server.on('listening', function () { - process.stdout.write(`documentation.js serving on port ${port}\n`); - }); - - function updateWatcher() { - if (!watcher) { - watcher = chokidar.watch(argv.input); - watcher.on('all', _.debounce(updateServer, 300)); - } - - documentation - .expandInputs(argv.input, argv) - .then(files => { - watcher.add( - files.map(data => (typeof data === 'string' ? data : data.file)) - ); - }) - .catch(err => { - /* eslint no-console: 0 */ - return server.setFiles([errorPage(err)]).start(); - }); - } - - function updateServer() { - documentation - .build(argv.input, argv) - .then(comments => documentation.formats.html(comments, argv)) - .then(files => { - if (argv.watch) { - updateWatcher(); - } - server.setFiles(files).start(); - }) - .catch(err => { - return server.setFiles([errorPage(err)]).start(); - }); - } - - updateServer(); - }); -}; - -export default { command, description, builder, handler }; diff --git a/src/serve/error_page.js b/src/serve/error_page.js deleted file mode 100644 index d55b0f62a..000000000 --- a/src/serve/error_page.js +++ /dev/null @@ -1,38 +0,0 @@ -/* eslint no-console: 0 */ -import File from 'vinyl'; -import ansiHTML from 'ansi-html'; - -const template = - ''; - -ansiHTML.setColors({ - reset: ['fff', '800'], - black: 'aaa', // String - red: '9ff', - green: 'f9f', - yellow: '99f', - blue: 'ff9', - magenta: 'f99', - cyan: '9f9', - lightgrey: 'ccc', - darkgrey: 'aaa' -}); - -/** - * Given an error, generate an HTML page that represents the error. - * @param error parse or generation error - * @returns {Object} vinyl file object - */ -export default function errorPage(error) { - let errorText = error.toString(); - console.error(error); - if (error.codeFrame) { - errorText += '
' + ansiHTML(error.codeFrame) + '
'; - } - return new File({ - path: 'index.html', - contents: Buffer.from(template + errorText) - }); -} diff --git a/src/serve/server.js b/src/serve/server.js deleted file mode 100644 index 2f1fdfaae..000000000 --- a/src/serve/server.js +++ /dev/null @@ -1,117 +0,0 @@ -// This file triggers https://github.com/prettier/prettier/issues/1151 - -import http from 'http'; -import mime from 'mime'; -import pify from 'pify'; -import events from 'events'; -const EventEmitter = events.EventEmitter; -import liveReload from 'tiny-lr'; -import { sep } from 'path'; - -/** - * A static file server designed to support documentation.js's --serve - * option. It serves from an array of Vinyl File objects (virtual files in - * memory) and exposes a `setFiles` method that both replaces the set - * of files and notifies any browsers using LiveReload to reload - * and display the new content. - * @class - * @param port server port to serve on. - */ -export default class Server extends EventEmitter { - constructor(port, disableLiveReload) { - super(); - if (typeof port !== 'number') { - throw new Error('port argument required to initialize a server'); - } - this._port = port; - this._files = []; - this._disableLiveReload = !!disableLiveReload; - } - - /** - * Update the set of files exposed by this server and notify LiveReload - * clients - * - * @param files new content. replaces any previously-set content. - * @returns {Server} self - */ - setFiles(files) { - this._files = files; - if (this._lr) { - this._lr.changed({ body: { files: '*' } }); - } - return this; - } - - /** - * Internal handler for server requests. The server serves - * very few types of things: html, images, and so on, and it - * only handles GET requests. - * - * @param {http.Request} request content wanted - * @param {http.Response} response content returned - * @returns {undefined} nothing - * @private - */ - handler(request, response) { - let path = request.url.substring(1); - if (path === '') { - path = 'index.html'; - } - - for (let i = 0; i < this._files.length; i++) { - const file = this._files[i]; - const filePath = file.relative.split(sep).join('/'); - if (filePath === path) { - response.writeHead(200, { 'Content-Type': mime.getType(path) }); - response.end(file.contents); - return; - } - } - response.writeHead(404, { 'Content-Type': 'text/plain' }); - response.end('Not found'); - } - - start() { - /* - * Boot up the server's HTTP & LiveReload endpoints. This method - * can be called multiple times. - * - * @returns {Promise} resolved when server starts - */ - return new Promise(resolve => { - // idempotent - if (this._http) { - return resolve(this); - } - - if (!this._disableLiveReload) { - this._lr = liveReload(); - } - this._http = http.createServer(this.handler.bind(this)); - - return Promise.all([ - this._lr && pify(this._lr.listen.bind(this._lr))(35729), - pify(this._http.listen.bind(this._http))(this._port) - ]).then(() => { - this.emit('listening'); - return resolve(this); - }); - }); - } - - stop() { - /* - * Shut down the server's HTTP & LiveReload endpoints. This method - * can be called multiple times. - */ - return Promise.all([ - this._http && this._http.close(), - this._lr && this._lr.close() - ]).then(() => { - delete this._http; - delete this._lr; - return this; - }); - } -}