UNPKG

apiveritas

Version:

Lightweight CLI tool for consumer-driven API contract testing via JSON schema and payload comparisons.

58 lines (57 loc) 2.07 kB
"use strict"; /** * @file PathResolver.ts * @author Mario Galea * @description Utility class to resolve paths from the project root or other locations. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PathResolver = void 0; const path_1 = __importDefault(require("path")); class PathResolver { constructor() { // Assumes this file is at dist/core/utils after transpilation this.rootDir = path_1.default.resolve(__dirname, '..', '..', '..'); } /** * Resolve a path relative to the project root. * @param segments Path segments to append to the root. */ fromRoot(...segments) { return path_1.default.resolve(this.rootDir, ...segments); } /** * Resolve a path relative to the `dist` directory (for runtime assets like templates). * @param segments Path segments under dist */ fromDist(...segments) { return path_1.default.resolve(this.rootDir, 'dist', ...segments); } /** * Resolve path to the templates directory inside dist. */ templatesDir() { return this.fromDist('templates'); } /** * Resolve path to the templates directory relative to the *runtime* location, * based on the __dirname of this file. This is important for global installed package usage. */ templatesDirRuntime() { // __dirname here is dist/core/utils after compilation, // so templates folder is typically located at dist/templates, // so we go up two levels and into templates: return path_1.default.resolve(__dirname, '..', '..', 'templates'); } /** * Resolve a path relative to a custom base directory. * @param baseDir The base directory. * @param segments Additional path segments. */ from(baseDir, ...segments) { return path_1.default.resolve(baseDir, ...segments); } } exports.PathResolver = PathResolver;