UNPKG

commitlint-config-ghostwriter

Version:
45 lines (44 loc) 1.58 kB
"use strict"; /* eslint-disable global-require */ /* eslint-disable import/no-dynamic-require */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getConfiguration = void 0; const find_up_1 = require("find-up"); const fs_1 = require("fs"); const SUPPORTED_FILES = [ '.changelogrc.cjs', '.changelogrc.js', '.changelogrc.json', '.changelogrc', ]; let cachedConfig; const getConfiguration = () => { var _a, _b, _c; if (cachedConfig) { return cachedConfig; } const configPath = (0, find_up_1.sync)(SUPPORTED_FILES); if (!configPath) { throw new Error(`You must provide one of the configuration files: ${SUPPORTED_FILES.join(', ')}`); } const config = configPath.endsWith('.cjs') || configPath.endsWith('.js') ? require(configPath) : JSON.parse((0, fs_1.readFileSync)(configPath).toString()); config.scopes = (_b = (_a = config.scopes) === null || _a === void 0 ? void 0 : _a.map((scope) => { const sanitizedScopeType = scope.type.trim(); if (!sanitizedScopeType) { throw new Error('You provided an empty scope'); } return { description: scope.description, type: sanitizedScopeType, }; })) !== null && _b !== void 0 ? _b : []; if (!((_c = config.types) === null || _c === void 0 ? void 0 : _c.length)) { throw new Error('You must provide types'); } cachedConfig = config; return cachedConfig; }; exports.getConfiguration = getConfiguration;