documentation icon indicating copy to clipboard operation
documentation copied to clipboard

How to exclude directories?

Open gauntface opened this issue 6 years ago • 9 comments

  • What version of documentation.js are you using?: 5.3.2
  • How are you running documentation.js (on the CLI, Node.js API, Grunt, other?): CLI

On a project, we have fairly gnarly setup of multiple modules in a monorepo each can contain a node_modules and build directory.

By default I'd like to include all .mjs files in the docs and exclude node_modules and build directories.

What is the best approach for including / excluding files for a package structure like?

- packages/
    - module-one/
        - index.mjs
        - build/
            - build.js
        - node_modules/
            - module-two/
                - index.mjs
        - other-dir/
            - example.mjs

At the moment I just got mjs building with:

documentation serve packages/**/* --require-extension mjs --parse-extension mjs

Which is obviously including build and node_modules

gauntface avatar Sep 15 '17 02:09 gauntface

Could you do

documentation serve packages/*/index.mjs --require-extension mjs --parse-extension mjs

The gist of the answer is that documentation.js - at least so far - just uses the glob completion already available on your system, so including and excluding files follows whatever glob syntax is supported in bash/zsh/fish/ or whatever shell you're using.

tmcw avatar Sep 17 '17 22:09 tmcw

@tmcw in your example, would I need to add multiple entries, one for packages/module-one/index.mjs and one for packages/other-dir/example.mjs?

To be honest I'm used to most tools like this having a JSON config file and supporting a glob pattern and set of ignore glob patterns.

gauntface avatar Sep 25 '17 15:09 gauntface

So..is this not possible? I have all of my files in different folders at the root of the repo. When I run documentation on **/**/*.js it fails because I believe its searching through node_modules too. Any way to exclude node_modules?

I've tried running it on sp-**/*.js since all of my directories are prefixed with sp- but this doesn't work either.

green3g avatar Jan 27 '18 17:01 green3g

+1

In particular, I'm interested in excluding any node_modules folders.

I've done this in the past, with jsdoc, in a .jsdoc file, like so:

"source": {
    "include" : ["../projects"],
    "includePattern": ".*src\\\\.+\\.js(doc|x)?$",
    "excludePattern": "(node_modules|docs)"
}

kmiklas avatar Feb 06 '18 17:02 kmiklas

The current solution for anyone looking into this from Google, is to use glob patterns. documentation.js uses the glob npm package whose syntax can be found at https://github.com/isaacs/node-glob#glob-primer so in order to ignore for example node_modules, you'd write something like:

npx documentation build '!(node_modules)/**/*.js' ...

Note that the pattern must be quoted to avoid any shell's native expansions and globbing

The relevant options passed to the glob function by documentation.js are:

{
    nodir: true,
    dot: true,
    // ...
}

Hope this helps the people coming here from a Google search

References: https://github.com/documentationjs/documentation/blob/78c6a5a72882e3ad7766a72a78a113d5a2980d4a/src/smart_glob.js#L120

https://github.com/documentationjs/documentation/blob/78c6a5a72882e3ad7766a72a78a113d5a2980d4a/src/smart_glob.js#L114

mig8447 avatar Dec 02 '20 23:12 mig8447

can we have a config file for ex:

{
    "plugins": [],
    "recurseDepth": 10,
    "source": {
        "include": [".src/features/*"],
        "includePattern": ".+\\.js(doc|x)?$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    "sourceType": "module",
    "tags": {
        "allowUnknownTags": true,
        "dictionaries": ["jsdoc","closure"]
    },
    "templates": {
        "cleverLinks": true,
        "monospaceLinks": true
    }
}

and that run as: documentation build -c jsdoc.config.json -f html -o docs, this does not work for me! it just generates some empty docs

lfaz avatar Jan 20 '21 09:01 lfaz

documentation.js doesn't use or support jsdoc configuration files - if you want to use them, you should use the jsdoc tool instead.

tmcw avatar Jan 20 '21 16:01 tmcw

Our documentation is broken because we added moment.min.js in our libs and we can't exclude the file from the scan, even using the yml config file, there's no option for that.

kopax-polyconseil avatar Jun 23 '23 15:06 kopax-polyconseil

 '!(node_modules)/**/*.js' 

Is this a guide ?

I have tried to exclude with glob pattern and it didn't help, despite the single quote.

kopax-polyconseil avatar Jun 25 '23 08:06 kopax-polyconseil