1 | # vuepress-jsdoc
|
2 |
|
3 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/9ec565a85a134df2a0f6bdf905e438d4)](https://app.codacy.com/app/ph1p/vuepress-jsdoc?utm_source=github.com&utm_medium=referral&utm_content=ph1p/vuepress-jsdoc&utm_campaign=Badge_Grade_Settings)
|
4 | [![npm](https://img.shields.io/npm/v/vuepress-jsdoc.svg)](https://www.npmjs.com/package/vuepress-jsdoc)
|
5 | [![vercel](https://img.shields.io/badge/vercel-demo-black)](https://vuepress-jsdoc-example.vercel.app)
|
6 |
|
7 | This npm package is a command line script, which scans your JavaScript, Vue or Typescript source code and generates markdown files for vuepress with the help of [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown) and [vue-docgen-cli](https://github.com/vue-styleguidist/vue-styleguidist/tree/dev/packages/vue-docgen-cli).
|
8 |
|
9 | ![CLI ./example](/example/img/cli.gif)
|
10 |
|
11 | ## How to
|
12 |
|
13 | ```bash
|
14 | yarn global add vuepress-jsdoc
|
15 | npm i vuepress-jsdoc -g
|
16 | ```
|
17 |
|
18 | **Example:**
|
19 |
|
20 | ```bash
|
21 | # search code in src and move it to code (./documentation/code) in your vuepress folder (./documentation)
|
22 | vuepress-jsdoc --source ./src --dist ./documentation --folder code --title API --exclude=**/*/*.test.js
|
23 | ```
|
24 |
|
25 | ### Commands
|
26 |
|
27 | If no command passed it will run `generate` as default
|
28 |
|
29 | | Name | Alias | Description |
|
30 | | -------- | ------ | ------------------------------------------------------------------------------------------------------- |
|
31 | | generate | gen, g | search code in src and move it to code (./documentation/code) in your vuepress folder (./documentation) |
|
32 |
|
33 | ### Options
|
34 |
|
35 | | Name | Alias | Default | Description |
|
36 | | ----------------- | ----- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
37 | | --source | -s | ./src | Source folder with .js or .ts files |
|
38 | | --dist | -d | ./documentation | Destination folder |
|
39 | | --folder | -f | ./code | Folder inside destination folder. Gets overwritten everytime |
|
40 | | --title | -t | API | Title of your documentation |
|
41 | | --help | -h | | Show help |
|
42 | | --version | -v | | Show current version |
|
43 | | --readme | -r | | Path to custom readme file |
|
44 | | --exclude | -e | | Pattern to exclude files/folders (Comma seperated) - \*.test.js,exclude.js [more information](https://github.com/micromatch/micromatch#ismatch) |
|
45 | | --rmPattern | -rm | | Pattern when removing files. You can ex- and include files. (glob pattern) |
|
46 | | --partials | -p | | jsdoc2markdown partial templates (overwrites default ones) |
|
47 | | --jsDocConfigPath | -c | | Path to [JsDoc Config](http://usejsdoc.org/about-configuring-jsdoc.html) (experimental) |
|
48 |
|
49 | ### config.js
|
50 |
|
51 | Inside your generated folder, you can find a `config.js`.
|
52 | This file includes a complete filetree and an vuepress sidebar tree.
|
53 |
|
54 | ## How to configure vuepress
|
55 |
|
56 | [Vuepress](https://vuepress.vuejs.org/) is a static site generator by Evan You.
|
57 | You can add all generated documentation files to your existing vuepress project or create a new one.
|
58 |
|
59 | ```bash
|
60 | # First install vuepress
|
61 | yarn global add vuepress
|
62 |
|
63 | # Run the CLI
|
64 | vuepress-jsdoc
|
65 |
|
66 | # Run vuepress dev server
|
67 | vuepress dev ./documentation
|
68 |
|
69 | # Run vuepress build, if you want to ship it
|
70 | vuepress build ./documentation
|
71 | ```
|
72 |
|
73 | **Access it via:** [http://localhost:8080/code/](http://localhost:8080/code/)
|
74 |
|
75 | Now you need the sidebar.
|
76 | Create a `.vuepress` folder inside the `documentation` folder and add the following `config.js`.
|
77 |
|
78 | **config.js:**
|
79 |
|
80 | ```javascript
|
81 | // auto generated sidebar
|
82 | const { sidebarTree } = require('../code/config');
|
83 |
|
84 | module.exports = {
|
85 | dest: 'dist',
|
86 | locales: {
|
87 | '/': {
|
88 | title: 'vuepress-jsdoc',
|
89 | description: 'Generate jsdoc markdown files for vuepress'
|
90 | }
|
91 | },
|
92 | themeConfig: {
|
93 | editLinks: true,
|
94 | sidebarDepth: 4,
|
95 | docsDir: 'code',
|
96 | locales: {
|
97 | '/': {
|
98 | nav: [
|
99 | {
|
100 | text: 'Home',
|
101 | link: '/'
|
102 | }
|
103 | ],
|
104 | // Add the generated sidebar
|
105 | sidebar: Object.assign({}, sidebarTree('Mainpage title'))
|
106 | }
|
107 | }
|
108 | }
|
109 | };
|
110 | ```
|
111 |
|
112 | ## Custom readme
|
113 |
|
114 | You can easily add a custom path to your readme by using the `--readme ./path/to/file.md` parameter. If you move a `README.md` inside your source folder, it should resolve it automatically.
|
115 | You can set the title by passing it to the `sidebarTree('Mainpage title')` function inside your `./.vuepress/config.js`.
|
116 |
|
117 | Once the README.md has been added, it is no longer overwritten!
|
118 | If you want it to be overwritten, set `--rmPattern=./documentation/code/README.md`.
|
119 |
|
120 | ## @vuepress comment block
|
121 |
|
122 | You can add custom meta data to your pages by using the `@vuepress` block:
|
123 |
|
124 | ```javascript
|
125 | /*
|
126 | * @vuepress
|
127 | * ---
|
128 | * title: Your custom title
|
129 | * headline: You custom headline
|
130 | * ---
|
131 | */
|
132 | ```
|
133 |
|
134 | Use `headline` to add a custom `h1` title.
|
135 |
|
136 | [More information](https://vuepress.vuejs.org/guide/markdown.html#front-matter)
|
137 |
|
138 | ## Typescript
|
139 |
|
140 | To use typescript, you have to install these dev-dependencies:
|
141 |
|
142 | ```bash
|
143 | yarn add -D typescript jsdoc-babel @babel/cli @babel/core @babel/preset-env @babel/preset-typescript jsdoc-to-markdown
|
144 | ```
|
145 |
|
146 | Next, you have to add a `jsdoc.json` to your project with some settings and add it with the `-c` parameter.
|
147 | You can find a full working example with all settings inside the `./example` folder.
|
148 | The example shows also how to use babel-`plugins`.
|
149 |
|
150 | ## Example
|
151 |
|
152 | The `./example` folder includes a full working vuepress-jsdoc example.
|
153 |
|
154 | ```bash
|
155 | # Install dependencies
|
156 | npm install
|
157 |
|
158 | # Run the CLI
|
159 | vuepress-jsdoc
|
160 |
|
161 | # Generate docs
|
162 | npm run docs
|
163 |
|
164 | # Run dev server
|
165 | npm run dev
|
166 |
|
167 | # Generate dist folder
|
168 | npm run build
|
169 | ```
|
170 |
|
171 | ## Contribute
|
172 |
|
173 | PRs are always welcome (:
|