@constructor-io/constructorio-connect-cli
Version:
CLI tool to enable users to interface with the Constructor Connect Ecosystem
29 lines (28 loc) • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterConnectionsByTemplate = filterConnectionsByTemplate;
const config_1 = require("../customer/config");
const path_1 = require("../customer/path");
/**
* Returns all connections that are associated with a template by checking
* the config file.
*/
async function filterConnectionsByTemplate(templatePath, connections) {
const config = await (0, config_1.getRepositoryConfigFile)();
// All connection ids that references this template
const configConnectionIds = config.environments.reduce((connectionIds, environment) => {
for (const templateConfig of environment.templates) {
const templatePaths = Object.values(templateConfig.paths).map((filePath) => (0, path_1.cleanupPath)(filePath));
// environment doesn't even target this template
if (!templatePaths.includes(templatePath)) {
continue;
}
for (const id of templateConfig.connection_ids) {
connectionIds.add(id);
}
}
return connectionIds;
}, new Set());
const filteredConnections = connections.filter((connection) => configConnectionIds.has(connection.id));
return filteredConnections;
}