UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

53 lines (52 loc) 2.21 kB
"use strict"; var fs = require("node:fs"), path = require("node:path"), rxjs = require("rxjs"), sanity = require("sanity"), mockBrowserEnvironment = require("./mockBrowserEnvironment.js"); function _interopDefaultCompat(e) { return e && typeof e == "object" && "default" in e ? e : { default: e }; } var fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), path__default = /* @__PURE__ */ _interopDefaultCompat(path); const candidates = ["sanity.config.js", "sanity.config.jsx", "sanity.config.ts", "sanity.config.tsx"]; function getStudioConfig({ basePath, configPath: cfgPath }) { let cleanup; try { cleanup = mockBrowserEnvironment.mockBrowserEnvironment(basePath); let configPath = cfgPath; if (configPath && !fs__default.default.existsSync(configPath)) throw new Error(`Failed to find config at "${cfgPath}"`); if (configPath || (configPath = candidates.map((candidate) => path__default.default.join(basePath, candidate)).find((candidate) => fs__default.default.existsSync(candidate))), !configPath) throw new Error(`Failed to resolve sanity.config.(js|ts) for base path "${basePath}"`); let config; try { const mod = require(configPath); config = mod.__esModule && mod.default ? mod.default : mod; } catch (err) { throw new Error(`Failed to load configuration file "${configPath}"`, { cause: err }); } if (!config) throw new Error("Configuration did not export expected config shape"); return Array.isArray(config) ? config : [{ ...config, name: config.name || "default", basePath: config.basePath || "/" }]; } finally { cleanup?.(); } } async function getStudioWorkspaces(options) { let cleanup; try { cleanup = mockBrowserEnvironment.mockBrowserEnvironment(options.basePath); const config = getStudioConfig(options), workspaces = await rxjs.firstValueFrom(sanity.resolveConfig(config)); if (!workspaces) throw new Error("Failed to resolve configuration"); return workspaces; } finally { cleanup?.(); } } exports.getStudioConfig = getStudioConfig; exports.getStudioWorkspaces = getStudioWorkspaces; //# sourceMappingURL=getStudioWorkspaces.js.map