"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const os = require("os");
const path = require("path");
function createDirectory(directory) {
    const parentDirectory = path.dirname(directory);
    if (!fs.existsSync(parentDirectory)) {
        createDirectory(parentDirectory);
    }
    if (fs.existsSync(parentDirectory) && !fs.existsSync(directory)) {
        fs.mkdirSync(directory);
    }
}
exports.createDirectory = createDirectory;
function deleteAllFilesInDirectory(directory) {
    fs.readdirSync(directory).forEach((file) => {
        fs.unlinkSync(path.join(directory, file));
    });
}
exports.deleteAllFilesInDirectory = deleteAllFilesInDirectory;
function removeDirectory(directory) {
    walkThrough(directory, () => { }, (dir) => {
        deleteAllFilesInDirectory(dir);
        fs.rmdirSync(dir);
    });
}
exports.removeDirectory = removeDirectory;
function writeObjectAsJson(pathToSave, object, options = {}) {
    const indent = 4;
    const data = JSON.stringify(object, null, indent)
        .replace(/(\r)?\n/g, os.EOL);
    fs.writeFileSync(pathToSave, data, options);
}
exports.writeObjectAsJson = writeObjectAsJson;
function walkThrough(directory, callback, recursiveCallback) {
    if (!fs.statSync(directory).isDirectory()) {
        return;
    }
    fs.readdirSync(directory).forEach(file => {
        callback(directory, file);
        const nextDir = path.join(directory, file);
        if (fs.existsSync(nextDir)) {
            walkThrough(nextDir, callback, recursiveCallback);
        }
    });
    if (recursiveCallback) {
        recursiveCallback(directory);
    }
}
exports.walkThrough = walkThrough;
//# sourceMappingURL=common.js.map