UNPKG

@constructor-io/constructorio-connect-cli

Version:

CLI tool to enable users to interface with the Constructor Connect Ecosystem

60 lines (59 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCustomerOSSpecificPath = getCustomerOSSpecificPath; exports.cleanupPath = cleanupPath; const path_1 = require("path"); /** * @returns The provided path prepended with the root directory - in the user's OS path pattern. * * E.g. Unix: /path/to/file * E.g. Windows: C:\path\to\file */ function getCustomerOSSpecificPath(path) { return (0, path_1.join)(process.cwd(), process.env.REPOSITORY_ROOT_DIRECTORY || "", path); } /** * Receives either a relative or absolute path for a given template file. * * Unix * - src/templates/variation/variation.jsonata * - ./src/templates/variation/variation.jsonata * - /usr/username/templates-folder/src/templates/variation/variation.jsonata * * Windows * - src\templates\variation\variation.jsonata * - .\src\templates\variation\variation.jsonata * - C:\users\username\templates-folder\src\templates\variation\variation.jsonata * * And returns a relative unix path WITHOUT its type prefix (e.g "src/templates"), like so: * - variation/variation.jsonata */ function cleanupPath(filePath) { if (!filePath) { return ""; } /** * E.g /src/templates/variation/variation.jsonata * E.g ./src/templates/variation/variation.jsonata * E.g src/templates/variation/variation.jsonata */ const relativePath = filePath .replace(process.cwd(), "") // .replace(/\\/g, "/"); /** * E.g variation/variation.jsonata * E.g /variation/variation.jsonata * E.g ./variation/variation.jsonata */ let replacedPath = relativePath .replace("src/templates/", "") .replace("src/fixtures/", "") .replace("src/external-data/", ""); if (replacedPath.startsWith("/")) { replacedPath = replacedPath.slice(1); } if (replacedPath.startsWith("./")) { replacedPath = replacedPath.slice(2); } return replacedPath; }