"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.walkRecursive = void 0;
const fs = require("fs");
const path = require("path");
const thenify = require("thenify");
const readdir = thenify(fs.readdir);
const stat = thenify(fs.stat);
/** Walk a directory recursively and call a callback function for each file or directory found. */
function walkRecursive(rootDirPath, callback) {
    return __awaiter(this, void 0, void 0, function* () {
        return new Promise(function (resolve, reject) {
            return __awaiter(this, void 0, void 0, function* () {
                try {
                    const files = yield readdir(rootDirPath);
                    for (let file of files) {
                        try {
                            const fileFullPath = path.join(rootDirPath, file);
                            const fileStats = yield stat(fileFullPath);
                            yield callback(rootDirPath, file, fileStats);
                            if (fileStats.isDirectory()) {
                                yield walkRecursive(fileFullPath, callback);
                            }
                        }
                        catch (_a) { }
                    }
                    resolve();
                }
                catch (err) {
                    reject(err);
                }
            });
        });
    });
}
exports.walkRecursive = walkRecursive;
//# sourceMappingURL=file-walker.js.map