{"id":462,"date":"2013-07-19T18:00:36","date_gmt":"2013-07-19T16:00:36","guid":{"rendered":"http:\/\/www.speich.net\/articles\/?p=462"},"modified":"2019-10-06T12:22:39","modified_gmt":"2019-10-06T10:22:39","slug":"generate-javascript-documentation-with-jsdoc-3-and-phpstorm","status":"publish","type":"post","link":"https:\/\/www.speich.net\/articles\/en\/2013\/07\/19\/generate-javascript-documentation-with-jsdoc-3-and-phpstorm\/","title":{"rendered":"How to Generate JavaScript Documentation with JSDoc 3 and PhpStorm"},"content":{"rendered":"\n<p><strong>This guide is outdated<\/strong>. I wrote the new tutorial <a href=\"https:\/\/www.speich.net\/articles\/en\/2016\/04\/10\/use-jsdoc-3-and-phpstorm-to-generate-javascript-documentation\/\" target=\"_blank\" rel=\"noopener noreferrer\">Use JSDoc 3 and PhpStorm to generate JavaScript documentation<\/a><\/p>\n\n\n\n<p>This is an update to my previous article <a title=\"Generate JavaScript documentation\" href=\"http:\/\/www.speich.net\/articles\/2010\/07\/27\/how-to-create-javascript-documentation-in-phpstorm\/\">How to create JavaScript documentation in PhpStorm<\/a>, since the JsDoc Toolkit is no longer under active development. It got replaced by JSDoc 3, with better support for current coding practices, particularly the <a href=\"http:\/\/wiki.commonjs.org\/wiki\/Modules\/1.1\" target=\"_blank\" rel=\"noopener noreferrer\">CommonJS Modules<\/a> standard and also its improved format, <a title=\"Asynchronous Module Definition\" href=\"https:\/\/github.com\/amdjs\/amdjs-api\/wiki\/AMD\" target=\"_blank\" rel=\"noopener noreferrer\">Asynchronous Module Definition<\/a> (AMD).<\/p>\n\n\n\n<p>This guide should not only work for Jetbrains&#8217; PhpStorm, but any IDE, such as Eclipse or Aptana, that lets you call an external tool with parameters. It is written for Windows 7, but should also work for Mac\/Unix users with minor modifications. It assumes you have installed Java Runtime JRE 1.7 and added it to the Window system path.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>We will set up JSDoc 3 as an external tool to PhpStorm in such a way that it will work for any project by using PhpStorm macro variables and the configuration file conf.json for JSDoc 3. Furthermore, we use a template called DocStrap instead of the default template.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step by Step Instructions<\/h2>\n\n\n\n<p><strong>1.<\/strong> Start PhpStorm and clone <a title=\"JSDoc 3\" href=\"https:\/\/github.com\/jsdoc3\/jsdoc\" target=\"_blank\" rel=\"noopener noreferrer\">JSDoc 3<\/a> from GitHub.<br>If you put it somewhere under C:\\Users\\Public you don&#8217;t have to worry about permissions. I put it to C:\\Users\\Public\\Website\\Tools\\jsdoc3<\/p>\n\n\n\n<p><strong>2<\/strong>. [optional]. If you want to use the default template you can skip this step, otherwise clone <a title=\"DocStrap a JSDoc 3 template\" href=\"https:\/\/github.com\/terryweiss\/docstrap\" target=\"_blank\" rel=\"noopener noreferrer\">DocStrap<\/a> from GitHub into the templates directory of JSDoc 3, e.g. C:\\Users\\Public\\Website\\Tools\\jsdoc3\\templates<\/p>\n\n\n\n<p><strong>3.<\/strong> Open the project containing the JavaScript files you want to document and create a file named conf.json which is going to be the <a title=\"JSDoc 3 config file\" href=\"http:\/\/usejsdoc.org\/about-configuring-jsdoc.html\">configuration file for JSDoc 3<\/a>. Then add the following json object to it:<\/p>\n\n\n\n<pre><code class=\"language-json\">{\n&nbsp;&nbsp; &nbsp;\"tags\": {\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"allowUnknownTags\": true\n&nbsp;&nbsp; &nbsp;},\n&nbsp;&nbsp; &nbsp;\"source\": {\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"include\": [\".\/\"],\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"includePattern\": \".+\\.js(doc)?$\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"excludePattern\": \"docs\"\n&nbsp;&nbsp; &nbsp;},\n&nbsp;&nbsp; &nbsp;\"plugins\": [],\n&nbsp;&nbsp; &nbsp;\"templates\": {\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"cleverLinks\": false,\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"monospaceLinks\": true,\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"systemName\": \"remoteFileExplorer\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"footer\": \"Created by Simon Speich\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"copyright\": \"2013\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"navType\": \"vertical\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"theme\": \"spacelab\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"linenums\": true,\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"collapseSymbols\": true,\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"inverseNav\": false\n&nbsp;&nbsp; &nbsp;},\n&nbsp;&nbsp; &nbsp;\"opts\": {\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"template\": \"C:\\\\Users\\\\Public\\\\WebsiteTools\\\\jsdoc3\\\\templates\\\\docstrap\\\\template\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"encoding\": \"utf8\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"destination\": \"docs\/js\",\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"recurse\": true,\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\"private\": true\n&nbsp;&nbsp; &nbsp;}\n}<\/code><\/pre>\n\n\n\n<p><strong>include<\/strong>: &#8220;.\/&#8221; references the working directory we will set up in PhpStorm External Tools, so don&#8217;t change that.<br><strong>includePattern<\/strong>: Only files ending in &#8220;.js&#8221; and &#8220;.jsdoc&#8221; will be processed.<br><strong>excludePattern<\/strong>: Don&#8217;t document the documentation!<br><strong>destination<\/strong>: &#8220;&lt;Path to where to generate the docs&gt;&#8221; 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. C:\\\\Users\\\\Public\\\\Websites\\\\remoteFileExplorer\\\\docs\\\\js<br><strong>recurse<\/strong>: true. Process all subfolders recursively.<\/p>\n\n\n\n<p>Note: All quotation marks are required and all path settings are always relative to the working directory (e.g. your project) we will set up in PhpStorm below.<\/p>\n\n\n\n<p><strong>4.<\/strong> Open the Settings Window (Ctrl + Alt + S) in PhpStorm, select External Tools<br>and click the add button +.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2013\/07\/PhpStorm-JSDoc3-01.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"717\" height=\"470\" src=\"https:\/\/speich.net\/wp\/wp-content\/uploads\/2013\/07\/PhpStorm-JSDoc3-01.gif\" alt=\"Screenshot PhpStorm\" class=\"wp-image-709\"\/><\/a><\/figure><\/div>\n\n\n\n<p>Then provide the following information in the Edit Tools Window:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2013\/07\/PhpStorm-JSDoc3-021.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"450\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2013\/07\/PhpStorm-JSDoc3-021.gif\" alt=\"Screenshot PhpStorm\" class=\"wp-image-718\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Name<\/strong>: JSDoc 3<br>This name will show up in your Tools Menu.<\/p>\n\n\n\n<p><strong>Group<\/strong>: Documentation<br>If you fill in a group name, then this will be shown in the Tools menu and the name JSDoc 3 will become a submenu of it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/speich.net\/wp\/wp-content\/uploads\/2013\/07\/PhpStorm-JSDoc3-031.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"450\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2013\/07\/PhpStorm-JSDoc3-031.gif\" alt=\"Screenshot PhpStorm\" class=\"wp-image-719\"\/><\/a><\/figure><\/div>\n\n\n\n<p><strong>Program<\/strong>: &lt;Path to JSDoc 3jsdoc.cmd&gt;<br>Fill in the path to the jsdoc.cmd, e.g.: C:\\Users\\Public\\Website\\Tools\\jsdoc3\\jsdoc.cmd Important on Windows: Do not use the jsdoc file directly, instead use the provided command file jsdoc.cmd, which sets up all the correct paths for you. For Mac and Unix users, the jsdoc file will probably do fine (not tested).<\/p>\n\n\n\n<p><strong>Parameters<\/strong>: -c &#8220;&lt;Path to the conf.json file&gt;&#8221;<br>Instead of hardcode the path to the configuration file we&#8217;ve created in step 2, we use the PhpStorm macro variable $FilePrompt$. This macro variable will open a file picker dialog to select the config file every time we run the JSDoc 3 Tool (did I already mention that I love PhpStorm?!).<\/p>\n\n\n\n<p>Note: Enclose the macro variable in quotes if your path contains spaces!<\/p>\n\n\n\n<p><strong>Working directory<\/strong>: &lt;Path to the project you want to document&gt;<br>Also instead of hard wiring the path to the project you want to document such as C:\\Users\\Public\\Websites\\remoteFileExplorer, we use the macro variable $ProjectFileDir$ so JSDoc will always document the project currently open in PhpStorm.<\/p>\n\n\n\n<p>That&#8217;s all. Happy documenting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide is outdated. I wrote the new tutorial Use JSDoc 3 and PhpStorm to generate JavaScript documentation This is an update to my previous article How to create JavaScript documentation in PhpStorm, since the JsDoc Toolkit is no longer under active development. It got replaced by JSDoc 3, with better support for current coding &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.speich.net\/articles\/en\/2013\/07\/19\/generate-javascript-documentation-with-jsdoc-3-and-phpstorm\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Generate JavaScript Documentation with JSDoc 3 and PhpStorm&#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":[9,18,48,75],"class_list":["post-462","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-amd","tag-commonjs","tag-jsdoc-3","tag-phpstorm","entry"],"_links":{"self":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/462","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=462"}],"version-history":[{"count":6,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":1686,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/462\/revisions\/1686"}],"wp:attachment":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}