"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    getEnvOrDefault: function() {
        return getEnvOrDefault;
    },
    isDevelopmentEnvironment: function() {
        return isDevelopmentEnvironment;
    },
    isNode: function() {
        return isNode;
    },
    isNodemon: function() {
        return isNodemon;
    },
    isPm2: function() {
        return isPm2;
    },
    isProductionEnvironment: function() {
        return isProductionEnvironment;
    },
    isTestEnvironment: function() {
        return isTestEnvironment;
    },
    verifyPackageJsonRequirements: function() {
        return verifyPackageJsonRequirements;
    }
});
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
const _logger = require("../handlers/logger");
const _serverconstants = require("../server.constants");
const _path = require("path");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const logger = new _logger.LoggerService("Utils-Env", false);
function getEnvOrDefault(key, defaultVal) {
    const val = process.env[key];
    if (!val?.length) return defaultVal;
    return val;
}
function isDevelopmentEnvironment() {
    return process.env.NODE_ENV === _serverconstants.AppConstants.defaultDevelopmentEnv;
}
function isTestEnvironment() {
    return process.env.NODE_ENV === _serverconstants.AppConstants.defaultTestEnv;
}
function isProductionEnvironment() {
    return process.env.NODE_ENV === _serverconstants.AppConstants.defaultProductionEnv;
}
function isPm2() {
    return "PM2_HOME" in process.env || "PM2_JSON_PROCESSING" in process.env || "PM2_CLI" in process.env;
}
function isNodemon() {
    return "npm_lifecycle_script" in process.env && process.env.npm_lifecycle_script.includes("nodemon");
}
function isNode() {
    return "NODE" in process.env;
}
function verifyPackageJsonRequirements(rootPath) {
    const dirConts = _fs.default.readdirSync(rootPath);
    const hasPackageJson = dirConts.includes("package.json");
    if (!hasPackageJson) {
        logger.error(`FAILURE. Could not find 'package.json' in root folder ${rootPath}`);
        return false;
    }
    logger.debug("✓ found 'package.json'");
    const packageName = require((0, _path.join)(rootPath, "package.json")).name;
    if (!packageName) {
        logger.error("X Could not find 'name' property in package.json file. Aborting FDM Server.");
        return false;
    }
    if (packageName.toLowerCase() !== _serverconstants.AppConstants.serverPackageName) {
        logger.error(`X property 'name' in package.json file didnt equal 'fdm-monster' (found: ${packageName.toLowerCase()}). Aborting FDM Server.`);
        return false;
    }
    logger.debug("✓ Correctly validated FDM package.json file!");
    return true;
}

//# sourceMappingURL=env.utils.js.map