UNPKG

@netlify/content-engine

Version:
61 lines 2.88 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConnectorConfigurationOptionsString = getConnectorConfigurationOptionsString; const path = __importStar(require("path")); async function getConnectorConfigurationOptionsString(dataLayerDirectory) { const { store: reduxStore } = require(require.resolve(`@netlify/content-engine/dist/redux/index`, { paths: [dataLayerDirectory], })); let plugins; const { flattenedPlugins } = reduxStore.getState(); if (flattenedPlugins.length) { plugins = flattenedPlugins; } else { throw new Error(`No plugins found. Ensure computeSourcingConfigurationId() is called in a node process which has already ran "content-engine"'s initialization step. Sourcing configuration hash ID's can only be generated after loadPlugins() runs and in the same process it ran in.`); } let normalizedDirectory; try { normalizedDirectory = path.dirname(require.resolve(path.join(dataLayerDirectory, `package.json`))); } catch (e) { console.error(e); throw new Error(`Error normalizing data layer directory path by resolving site package.json in ${dataLayerDirectory}`); } const options = plugins .map((plugin) => `${plugin.name}-v${ // plugin.version will be the version of the plugin // or if it's the default-site-plugin it will be a hash of the site's gatsby-node.js and gatsby-browser.js files plugin.version}--${JSON.stringify(plugin.pluginOptions)},`) .join(" "); const normalizedOptionsString = options // replace unique server paths .replace(new RegExp(normalizedDirectory, `g`), ``) // and whitespace .replace(new RegExp(/\s/, `g`), ``); return normalizedOptionsString; } //# sourceMappingURL=get-plugin-options-string.js.map