1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Improve require() docs (#2553)

This commit is contained in:
Tom Limoncelli
2023-09-14 10:25:45 -04:00
committed by GitHub
parent af91e37043
commit 5b95f29082
2 changed files with 41 additions and 19 deletions

View File

@@ -8,7 +8,7 @@ parameter_types:
recursive: boolean
---
`require_glob()` can recursively load `.js` files, optionally non-recursive as well.
`require_glob()` recursively loads `.js` files that match a glob (wildcard). The recursion can be disabled.
Possible parameters are:
@@ -31,8 +31,13 @@ require_glob("./domains/", false);
```
{% endcode %}
One more important thing to note: `require_glob()` is as smart as `require()` is. It loads files always relative to the JavaScript
file where it's being executed in. Let's go with an example, as it describes it better:
# Comparison to require()
`require_glob()` and `require()` both use the same rules for determining which directory path is
relative to.
This will load files being present underneath `./domains/user1/` and **NOT** at below `./domains/`, as `require_glob()`
is called in the subfolder `domains/`.
{% code title="dnsconfig.js" %}
```javascript
@@ -45,6 +50,3 @@ require("domains/index.js");
require_glob("./user1/");
```
{% endcode %}
This will now load files being present underneath `./domains/user1/` and **NOT** at below `./domains/`, as `require_glob()`
is called in the subfolder `domains/`.