{"id":1252,"date":"2016-04-10T21:06:38","date_gmt":"2016-04-10T19:06:38","guid":{"rendered":"https:\/\/www.speich.net\/articles\/?p=1252"},"modified":"2019-12-29T12:47:21","modified_gmt":"2019-12-29T11:47:21","slug":"use-jsdoc-3-and-phpstorm-to-generate-javascript-documentation","status":"publish","type":"post","link":"https:\/\/www.speich.net\/articles\/en\/2016\/04\/10\/use-jsdoc-3-and-phpstorm-to-generate-javascript-documentation\/","title":{"rendered":"Use JSDoc 3 and PhpStorm to generate JavaScript documentation"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This is an update to my former installation guide <a href=\"https:\/\/www.speich.net\/articles\/en\/2013\/07\/19\/generate-javascript-documentation-with-jsdoc-3-and-phpstorm\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Generate JavaScript Documentation with JSDoc 3 and PhpStorm<\/a>, which was written in 2013. Since then, JSDoc 3 moved from Mozilla&#8217;s Rhino to Node.js to generate the documentation, which is why that guide no longer works (unless you use an older version of JSDoc 3). This installation guide is written for Windows, but should also work on Linux and Mac.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install and integrate Node.js<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Download and install <a href=\"https:\/\/nodejs.org\/en\/\" target=\"_blank\" rel=\"noopener noreferrer\">Node.js<\/a>.<\/li><li>Integrate Node.js into PhpStorm:<br>Open Settings (Ctrl+Alt+S) -&gt; Plugins -&gt; Install JetBrains Plugins -&gt; Search for Node.js -&gt; Install the Plugin<br><figure><img loading=\"lazy\" decoding=\"async\" class=\"inline\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2016\/04\/step01.gif\" alt=\"Install NodeJS in PhpStorm\" width=\"773\" height=\"640\"><\/figure>Open Settings&nbsp;(Ctrl+Alt+S)&nbsp; again and go to Languages &amp; Frameworks -&gt; Node.js and NPM. In the <span class=\"control\">Node interpreter<\/span> field, specify the local Node.js interpreter to use. Also press the Enable Node.js core button to enable code assist. For more details about Node.js in PhpStorm read <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/2016.1\/node-js.html\" target=\"_blank\" rel=\"noopener noreferrer\">IntelliJ IDEA 2016.1 Help | Node.js<\/a><\/li><li>Install the node package manager npm from within PhpStorm:<br>Install the npm package manager by clicking on the green add button <figure><img loading=\"lazy\" decoding=\"async\" class=\"inlineIcon alignnone\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2016\/04\/addbutton.gif\" alt=\"icon add button\" width=\"19\" height=\"19\"><\/figure>. Beware to make the installation global by setting Options to <em>-g<\/em>, otherwise you end up with npm in your project folder. The <em>-g<\/em> option will install npm into your folder <em>%AppData%\/npm\/<\/em><figure><img loading=\"lazy\" decoding=\"async\" class=\"inline\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2016\/04\/step02-1.gif\" alt=\"step02\" width=\"772\" height=\"698\"><\/figure>For more details about using the package manager in PhpStorm read <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/2016.1\/installing-and-removing-external-software-using-node-package-manager.html\" target=\"_blank\" rel=\"noopener noreferrer\">Installing and Removing External Software Using Node Package Manager<\/a>.<\/li><\/ol>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Install and integrate JSDoc<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Install JSDoc with the npm package manager directly from within PhpStrom:<br>Open Settings&nbsp;(Ctrl+Alt+S) -&gt; Languages &amp; Frameworks -&gt; Node.js and NPM. Click on the green add button <figure><img loading=\"lazy\" decoding=\"async\" class=\"inlineIcon\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2016\/04\/addbutton.gif\" alt=\"addbutton\" width=\"19\" height=\"19\"><\/figure> to install a new package and search for JSDoc. Install the package. Again, use the Options checkbox and specify which folder JSDoc should be installed into or type <em>-g<\/em> to install globally, e.g. <em>%AppData%\/npm\/node_modules\/jsdoc\/<\/em>.<br><figure><img loading=\"lazy\" decoding=\"async\" class=\"inline\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2016\/04\/step02.gif\" alt=\"Screenshot of PhpStorm\" width=\"774\" height=\"641\"><\/figure><\/li><li>Optional: Install a different template such as <a href=\"https:\/\/github.com\/docstrap\/docstrap\" target=\"_blank\" rel=\"noopener noreferrer\">DocStrap<\/a>. You can do this also directly from within PhpStorm the same way you just installed JSDoc above by using the npm package manager. Just search for <em>ink-docstrap<\/em>. Remember: Don&#8217;t forget the global switch!Note: I have to document a lot of dojo AMD modules, which return a class created with dojo\/_base\/declare(). I tested several templates, so far the standard JsDoc template is the only one that documents both the module and the class.<\/li><li>Integrate JSDoc into PhpStorm by creating an external tool and custom menu:<br>Open the Settings Window again (Ctrl+Alt+S), select <em>External Tools<\/em> and click the green add button <figure><img loading=\"lazy\" decoding=\"async\" class=\"inlineIcon alignnone\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2016\/04\/addbutton.gif\" alt=\"icon add button\" width=\"19\" height=\"19\"><\/figure>.<figure><img loading=\"lazy\" decoding=\"async\" class=\"inline\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2016\/04\/step04.gif\" alt=\"step04\" width=\"772\" height=\"684\"><\/figure><br>Then provide the following information in the Edit Tool Window:<br><strong>Name<\/strong>: JSDoc<br>This name will show up in your Tools Menu.<br><strong>Group<\/strong>: Documentation<br>If you fill in a group name, this will be shown in Tools menu and the name JSDoc will become a submenu of it.<figure><img loading=\"lazy\" decoding=\"async\" class=\"inline aligncenter\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2013\/07\/PhpStorm-JSDoc3-031.gif\" alt=\"Screenshot PhpStorm\" width=\"592\" height=\"450\"><\/figure><br><strong>Program<\/strong>: &lt;Path to node.exe&gt;<br>Fill in the path to node.exe, e.g. <em>C:\\Program Files (x86)\\tools\\nodejs\\node.exe<br><\/em><strong>Parameters<\/strong>: &lt;Path to jsdoc.js&gt; -c \u201c&lt;Path to the conf.json file&gt;\u201d<br>Fill in the path to jsdoc.js, e.g. <em>C:\\Users\\Simon\\AppData\\Roaming\\npm\\node_modules\\jsdoc\\jsdoc.js<br><\/em>Instead of passing all the <a href=\"http:\/\/usejsdoc.org\/about-commandline.html\" target=\"_blank\" rel=\"noopener noreferrer\">command-line arguments<\/a> to JSDoc, we will use a configuration file by using the <em>-c<\/em> parameter. Also, we use the PhpStorm macro variable <em>$FilePrompt$<\/em> instead of hard coding the path to the configuration file that we will create below. This macro variable will open a file picker dialog to select the config file every time we run the JSDoc Tool (I love PhpStorm!).<br>Important: If any of your paths contain spaces, you have to enclose them in quotes. This is also true for the <em>$FilePrompt$<\/em> macro!!!<br><strong>Working directory<\/strong>: &lt;Path to the project you want to document&gt;<br>Also, instead of hard coding the path to the project you want to document such as <em>C:\\Users\\Public\\Websites\\remoteFileExplorer<\/em>, we use the macro variable <em>$ProjectFileDir$,<\/em> so JSDoc will always document the project currently open in PhpStorm.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Configure JSDoc<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The easiest way of configuring JSDoc, is to use the configuration file <em>conf.json<\/em> (rename the <em>conf.json.example<\/em> in the JsDoc directory) instead of the command-line arguments:<\/p>\n\n\n\n<pre class=\"language-json\"><code>{\n    \"tags\": {\n        \"allowUnknownTags\": true,\n        \"dictionaries\": [\"jsdoc\"]\n    },\n    \"source\": {\n        \"include\": [\".\/\"],\n        \"includePattern\": \".+\\\\.js$\",\n        \"excludePattern\": \"(docs)\"\n    },\n    \"plugins\": [],\n    \"templates\": {\n        \"cleverLinks\": false,\n        \"monospaceLinks\": true,\n        \"systemName\": \"NAFIDAS\",\n        \"footer\": \"Created by Simon Speich\",\n        \"copyright\": \"2013\",\n        \"navType\": \"vertical\",\n        \"theme\": \"spacelab\",\n        \"linenums\": true,\n        \"collapseSymbols\": true,\n        \"inverseNav\": false\n    },\n    \"opts\": {\n        \"template\": \"..\/ink-docstrap\/template\",\n        \"encoding\": \"utf8\",\n        \"destination\": \"docs\/js\",\n        \"recurse\": true,\n        \"private\": true\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>include<\/strong>: \u201c.\/\u201d references the current working directory, so don\u2019t change that.<br><strong>includePattern<\/strong>: Only files ending in \u201c.js\u201d will be processed.<br><strong>excludePattern<\/strong>: Don\u2019t document the documentation!<br><strong>destination<\/strong>: \u201c&lt;Path to where to generate the docs&gt;\u201d If the path to where you want the documentation generated is outside of your project, you can also use Windows absolute paths with backslashes, but you need to escape them, e.g. <em>C:\\\\Users\\\\Public\\\\Websites\\\\remoteFileExplorer\\\\docs\\\\js<\/em><br><strong>recurse<\/strong>: true. Process all subfolders recursively.<br><strong>template<\/strong>: Optional. &#8220;&lt;path to the docstrap template&gt;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all. Happy documenting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an update to my former installation guide How to Generate JavaScript Documentation with JSDoc 3 and PhpStorm, which was written in 2013. Since then, JSDoc 3 moved from Mozilla&#8217;s Rhino to Node.js to generate the documentation, which is why that guide no longer works (unless you use an older version of JSDoc 3). &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.speich.net\/articles\/en\/2016\/04\/10\/use-jsdoc-3-and-phpstorm-to-generate-javascript-documentation\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Use JSDoc 3 and PhpStorm to generate JavaScript documentation&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[48,228,75],"class_list":["post-1252","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-jsdoc-3","tag-node-js","tag-phpstorm","entry"],"_links":{"self":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/comments?post=1252"}],"version-history":[{"count":29,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1252\/revisions"}],"predecessor-version":[{"id":1749,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1252\/revisions\/1749"}],"wp:attachment":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/media?parent=1252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/categories?post=1252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/tags?post=1252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}