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

New feature: require_glob() (similar to require() but supports globs) (#804)

* Initial implementation of findFiles/globe/glob

* Fixed path, some small improvements

* filepath.Dir() calls Clean() automatically anyway

* Relative path support (like require()), renamed func

* Check file ext prefix, further comments, var renaming

* Updated static.go after merge

* Added doc for glob()

* Tiny adjustment of description of glob()

* Updated docs for possible pattern

* Reworked glob, added public-facing require_glob()

* Updated docs with examples

* Updated static.go

* go generate
This commit is contained in:
Patrik Kernstock
2020-08-19 19:00:40 +01:00
committed by GitHub
parent b01b278d18
commit 576c2bd582
4 changed files with 262 additions and 117 deletions

View File

@ -887,3 +887,15 @@ function DKIM(arr) {
R.push(arr.slice(i, i + chunkSize));
return R;
}
// Function wrapper for glob() for recursively loading files.
// As the main function (in Go) is in our control anyway, all the values here are already sanity-checked.
// Note: glob() is only an internal undocumented helper function. So use it on your own risk.
function require_glob() {
arguments[2] = "js"; // force to only include .js files.
var files = glob.apply(null, arguments);
for (i = 0; i < files.length; i++) {
require(files[i]);
}
return files
}