UNPKG

@constructor-io/constructorio-connect-cli

Version:

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

47 lines (46 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTemplatesSourceCode = getTemplatesSourceCode; exports.getHelpersSourceCode = getHelpersSourceCode; const promises_1 = require("fs/promises"); const errors_1 = require("@oclif/core/errors"); const path_1 = require("./path"); /** * Loads the source code of a template from the file system. */ async function loadSourceCode(path) { if (!path) { return undefined; } try { return await (0, promises_1.readFile)((0, path_1.getCustomerOSSpecificPath)(path), "utf-8"); } catch { throw new errors_1.CLIError(`Could not load "${path}" file. Please check your connectrc.js file.`); } } /** * Replaces the paths of the templates with their source code. */ async function getTemplatesSourceCode(templates) { return await Promise.all(templates.map(async ({ connection_ids: connectionIds, paths }) => { return { connectionIds, sourceCode: { item: await loadSourceCode(paths.item), variation: await loadSourceCode(paths.variation), item_group: await loadSourceCode(paths.item_group), grouping: await loadSourceCode(paths.grouping), mapping: await loadSourceCode(paths.mapping), }, }; })); } /** * Loads the helpers source code from the file system. * @param helpers The path to the helpers file. * @returns The source code. */ async function getHelpersSourceCode(helpers) { return await loadSourceCode(helpers); }