"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.workingDir = exports.setWorkingDir = exports.screenshotDir = exports.logsDir = exports.appRootDir = void 0;
const helpers = require("./helpers");
const path = require("path");
const yargs = require("yargs");
let appRootDirPath = path.resolve(path.join(__dirname, '..', '..'));
let workingDirPath = process.cwd();
yargs.alias('w', 'workdir');
if (yargs.argv.workdir) {
    setWorkingDir(path.resolve(yargs.argv.workdir));
}
/** Returns the root directory of the Node application. */
function appRootDir() {
    return appRootDirPath;
}
exports.appRootDir = appRootDir;
/** Returns the logs directory. */
function logsDir() {
    return path.join(appRootDirPath, 'logs');
}
exports.logsDir = logsDir;
/** Returns the screenshots directory. */
function screenshotDir() {
    return path.join(appRootDirPath, 'uploads', 'screenshots');
}
exports.screenshotDir = screenshotDir;
/** Sets the working directory where the DB files and the log files are
 * stored and where the configuration file is read from. */
function setWorkingDir(newWorkingDir) {
    let normalizedPath = path.normalize(newWorkingDir);
    if (!path.isAbsolute(normalizedPath)) {
        normalizedPath = path.resolve(normalizedPath);
    }
    if (helpers.directoryExists(normalizedPath)) {
        workingDirPath = normalizedPath;
    }
    else {
        throw new Error(`Can't set working dir to "${normalizedPath}". Path does not exist.`);
    }
}
exports.setWorkingDir = setWorkingDir;
/** Returns the working directory where the DB files and the log files are
 * stored and where the configuration file is read from. */
function workingDir() {
    return workingDirPath;
}
exports.workingDir = workingDir;
//# sourceMappingURL=dirs.js.map