"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLowercaseExtension = exports.buildAbsoluteFixturePath = exports.buildPath = exports.root = void 0;
const path_1 = require("path");
let rootPath;
function root() {
    if (rootPath)
        return rootPath;
    rootPath = __dirname;
    if ((0, path_1.basename)(rootPath) === 'tools')
        rootPath = (0, path_1.resolve)(rootPath, '..');
    if ((0, path_1.basename)(rootPath) === 'scripts')
        rootPath = (0, path_1.resolve)(rootPath, '..');
    if ((0, path_1.basename)(rootPath) === 'common')
        rootPath = (0, path_1.resolve)(rootPath, '..');
    if ((0, path_1.basename)(rootPath) === 'core-utils')
        rootPath = (0, path_1.resolve)(rootPath, '..');
    if ((0, path_1.basename)(rootPath) === 'shared')
        rootPath = (0, path_1.resolve)(rootPath, '..');
    if ((0, path_1.basename)(rootPath) === 'server')
        rootPath = (0, path_1.resolve)(rootPath, '..');
    if ((0, path_1.basename)(rootPath) === 'dist')
        rootPath = (0, path_1.resolve)(rootPath, '..');
    return rootPath;
}
exports.root = root;
function buildPath(path) {
    if ((0, path_1.isAbsolute)(path))
        return path;
    return (0, path_1.join)(root(), path);
}
exports.buildPath = buildPath;
function getLowercaseExtension(filename) {
    const ext = (0, path_1.extname)(filename) || '';
    return ext.toLowerCase();
}
exports.getLowercaseExtension = getLowercaseExtension;
function buildAbsoluteFixturePath(path, customCIPath = false) {
    if ((0, path_1.isAbsolute)(path))
        return path;
    if (customCIPath && process.env.GITHUB_WORKSPACE) {
        return (0, path_1.join)(process.env.GITHUB_WORKSPACE, 'fixtures', path);
    }
    return (0, path_1.join)(root(), 'server', 'tests', 'fixtures', path);
}
exports.buildAbsoluteFixturePath = buildAbsoluteFixturePath;
//# sourceMappingURL=path.js.map