haraka-config
Advanced tools
Comparing version 1.2.4 to 1.3.0
@@ -7,2 +7,6 @@ # Changelog | ||
### [1.3.0] - 2024-05-02 | ||
- feat: getDir is now recursive | ||
### [1.2.4] - 2024-04-26 | ||
@@ -138,1 +142,2 @@ | ||
[1.2.4]: https://github.com/haraka/haraka-config/releases/tag/v1.2.4 | ||
[1.3.0]: https://github.com/haraka/haraka-config/releases/tag/v1.3.0 |
@@ -57,4 +57,9 @@ 'use strict' | ||
getDir(name, opts, done) { | ||
const dir = path.resolve(this.root_path, name) | ||
// no callback, return promise | ||
if (arguments.length < 3) return reader.read_dir(dir, opts) | ||
reader | ||
.read_dir(path.resolve(this.root_path, name), opts) | ||
.read_dir(dir, opts) | ||
.then((files) => { | ||
@@ -61,0 +66,0 @@ done(null, files) // keep the API consistent |
@@ -140,26 +140,28 @@ 'use strict' | ||
read_dir(name, opts = {}) { | ||
return new Promise((resolve, reject) => { | ||
this._read_args[name] = { opts } | ||
async read_dir(name, opts = {}) { | ||
this._read_args[name] = { opts } | ||
fsp | ||
.stat(name) | ||
.then((stat) => stat.isDirectory()) | ||
.then(() => fsp.readdir(name)) | ||
.then(async (fileList) => { | ||
const contents = [] | ||
for (const file of fileList) { | ||
const type = opts.type ?? this.getType(file) | ||
contents.push({ | ||
path: file, | ||
data: this.load_config(path.resolve(name, file), type, opts), | ||
}) | ||
} | ||
return contents | ||
}) | ||
.then(resolve) | ||
.catch(reject) | ||
const contents = [] | ||
const dirs = [] | ||
if (opts.watchCb) watch.dir2(this, name) | ||
}) | ||
const stat = await fsp.stat(name) | ||
if (stat.isDirectory()) dirs.push(name) | ||
for (const dir of dirs) { | ||
for (const entry of await fsp.readdir(dir)) { | ||
const entryPath = path.join(dir, entry) | ||
const stat = await fsp.stat(entryPath) | ||
if (stat.isDirectory()) dirs.push(entryPath) // recursion | ||
if (stat.isFile()) { | ||
const type = opts.type ?? this.getType(entry) | ||
contents.push({ | ||
path: entryPath, | ||
data: this.load_config(entryPath, type, opts), | ||
}) | ||
} | ||
} | ||
} | ||
if (opts.watchCb) watch.dir2(this, name) | ||
return contents | ||
} | ||
@@ -166,0 +168,0 @@ |
@@ -92,3 +92,3 @@ const fs = require('node:fs') | ||
// recursive is only supported on Windows (win32, win64) and macOS (darwin) | ||
if (!/win/.test(process.platform)) watchOpts.recursive = false | ||
if (!/win|darwin/.test(process.platform)) watchOpts.recursive = false | ||
@@ -109,2 +109,3 @@ watchers[dirPath] = fs.watch(dirPath, watchOpts, (fse, filename) => { | ||
}) | ||
watchers[dirPath].unref() | ||
} | ||
@@ -111,0 +112,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"description": "Haraka's config file loader", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"homepage": "http://haraka.github.io", | ||
@@ -9,0 +9,0 @@ "repository": { |
36997
721