"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chokidar = require("chokidar");
const console_1 = require("./console");
const debounce = require("debounce");
exports.default = (path, reloadSocket) => new Promise((resolve /* , reject */) => {
    console_1.default.debug("PATH:", path);
    const watcher = chokidar.watch(path, {
        // TODO: This watcher is not ready yet
        // ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
        ignored: /\.pyc$/,
        ignoreInitial: true,
    });
    const onChange = (eventname, _filename) => {
        // Console.info(`Event ${eventname} detected. in file: ${_filename}`)
        resolve(_filename);
        reloadSocket(_filename);
    };
    watcher.on("all", debounce(onChange, 500, true));
    // watcher.on('all', onChange)
    process.on("SIGINT", function () {
        watcher.close();
        process.exit();
    });
});
