@becklyn/contentful-adapter
Version:
[](https://github.com/Becklyn-Studios/contentful-adapter/actions/workflows/ci.yml)
76 lines (75 loc) • 3.11 kB
JavaScript
;
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigFromFile = exports.loadConfig = exports.CONFIG_FILE_NAME = exports.TSCONFIG_FILE_NAME = void 0;
const find_up_1 = __importDefault(require("../../compiled/find-up"));
const ts_node_1 = require("ts-node");
const dotenv_1 = require("dotenv");
const components_1 = require("./components");
const generator_1 = require("../migrations/generator");
exports.TSCONFIG_FILE_NAME = "tsconfig.becklyn-contentful.json";
exports.CONFIG_FILE_NAME = "becklyn-contentful.config.ts";
const loadConfig = async () => {
var _a;
const path = await (0, find_up_1.default)(exports.CONFIG_FILE_NAME);
if (!path) {
throw new Error(`Couldn't find ${exports.CONFIG_FILE_NAME}`);
}
(0, dotenv_1.config)();
(0, ts_node_1.register)({
transpileOnly: true,
project: exports.TSCONFIG_FILE_NAME,
});
let configModule;
try {
const { default: module } = await (_a = path, Promise.resolve().then(() => __importStar(require(_a))));
configModule = module;
}
catch (error) {
console.log(error);
throw new Error(`Failed to load ${exports.CONFIG_FILE_NAME}`);
}
return await (0, exports.getConfigFromFile)(configModule);
};
exports.loadConfig = loadConfig;
const getConfigFromFile = async (file) => {
var _a;
const backendLanguage = (_a = file.backendLanguage) !== null && _a !== void 0 ? _a : "en";
return {
backendLanguage,
components: (0, components_1.getComponentDataConfig)(file.components),
migrations: await (0, generator_1.getMigrationsFromGenerators)(backendLanguage, file.migrations),
clientConfig: {
spaceId: file.spaceId,
management: file.management,
delivery: file.delivery,
environmentId: file.environmentId,
},
};
};
exports.getConfigFromFile = getConfigFromFile;