documentationjs / documentation

:book: documentation for modern JavaScript
http://documentation.js.org/
Other
5.79k stars 482 forks source link

How to exclude directories? #918

Open gauntface opened 7 years ago

gauntface commented 7 years ago

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

tmcw commented 7 years ago

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.

gauntface commented 7 years ago

@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.

green3g commented 6 years ago

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.

kmiklas commented 6 years ago

+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)"
}
mig8447 commented 3 years ago

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

lfaz commented 3 years ago

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

tmcw commented 3 years ago

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

kopax-polyconseil commented 1 year ago

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 commented 1 year ago
 '!(node_modules)/**/*.js' 

Is this a guide ?

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