@constructor-io/constructorio-connect-cli
Version:
CLI tool to enable users to interface with the Constructor Connect Ecosystem
31 lines (30 loc) • 1.28 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildFixture = void 0;
const path_1 = __importDefault(require("path"));
const remeda_1 = require("remeda");
const file_loaders_1 = require("../helpers/file-loaders");
/**
* This will build a fixture with the given template type and name.
*
* You can also pass in any object in the third argument to override the fixture data,
* similarly to how a factory pattern works. It'll deep merge into the fixture itself.
*
* @param type string The type of fixture
* @param name string The name/path of the fixture
* @param dataOverride string The data to override in the fixture
* @returns Record<string, unknown> or Array<Record<string, unknown>> The fixture data
*/
const buildFixture = (type, name, dataOverride = {}) => {
const data = (0, file_loaders_1.getCatalogFixture)(path_1.default.join(type, name));
if (Array.isArray(data)) {
return data.map((item) => {
return (0, remeda_1.mergeDeep)(item, dataOverride);
});
}
return (0, remeda_1.mergeDeep)(data, dataOverride);
};
exports.buildFixture = buildFixture;