UNPKG

@constructor-io/constructorio-connect-cli

Version:

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

42 lines (41 loc) 1.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getJSONataTemplate = exports.getExternalFixture = exports.getCatalogFixture = void 0; exports.createFileLoader = createFileLoader; const path_1 = __importDefault(require("path")); const errors_1 = require("@oclif/core/errors"); const fs_extra_1 = __importDefault(require("fs-extra")); const path_2 = require("../customer/path"); exports.getCatalogFixture = createFileLoader({ prefix: path_1.default.join("src", "fixtures"), fileLoader: fs_extra_1.default.readJSONSync, suggestions: ["Ensure the file is a valid JSON file"], }); exports.getExternalFixture = createFileLoader({ prefix: path_1.default.join("src", "fixtures", "external_data"), fileLoader: fs_extra_1.default.readJSONSync, suggestions: ["Ensure the file is a valid JSON file"], }); exports.getJSONataTemplate = createFileLoader({ prefix: path_1.default.join("src", "templates"), fileLoader: fs_extra_1.default.readFileSync, }); function createFileLoader({ prefix, fileLoader, suggestions = [], }) { return function (filename, ...args) { const absolutePath = (0, path_2.getCustomerOSSpecificPath)(path_1.default.join(prefix, filename)); try { return fileLoader(absolutePath, ...args); } catch (error) { throw new errors_1.CLIError(`Error while loading ${absolutePath}: ${error.message}`, { suggestions: [ "Ensure the file exists and is named correctly", ...suggestions, ], }); } }; }