UNPKG

conventional-changelog-ghostwriter

Version:
71 lines (70 loc) 2.76 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 = (context) => { var _a, _b; 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()); if (!((_a = config.types) === null || _a === void 0 ? void 0 : _a.length)) { throw new Error('You must provide types'); } if (!config.issueReferencesPrefix) { config.issueReferencesPrefix = 'for'; } if (config.omitVersionSpacing === undefined || config.omitVersionSpacing === null) { config.omitVersionSpacing = false; } if (config.preset === 'github') { cachedConfig = { commitUrlFormat: `${context.host}/${context.owner}/${context.repository}/commit/{{LONG_HASH}}`, compareUrlFormat: `${context.host}/${context.owner}/${context.repository}/compare/{{PREVIOUS_TAG}}...{{CURRENT_TAG}}`, issuePrefixes: ['#'], issueReferencesPrefix: config.issueReferencesPrefix, issueUrlFormat: `${context.host}/${context.owner}/${context.repository}/issues/{{ISSUE_NUMBER}}`, omitVersionSpacing: config.omitVersionSpacing, types: config.types, }; return cachedConfig; } if (!config.commitUrlFormat) { throw new Error('You must provide a commitUrlFormat'); } if (!config.compareUrlFormat) { throw new Error('You must provide a compareUrlFormat'); } if (!((_b = config.issuePrefixes) === null || _b === void 0 ? void 0 : _b.length)) { throw new Error('You must provide issuePrefixes'); } config.issuePrefixes = config.issuePrefixes.map((issuePrefix) => { const sanitizedIssuePrefix = issuePrefix.trim(); if (!sanitizedIssuePrefix) { throw new Error('You provided an empty issue prefix'); } return sanitizedIssuePrefix; }); if (!config.issueUrlFormat) { throw new Error('You must provide a issueUrlFormat'); } cachedConfig = config; return cachedConfig; }; exports.getConfiguration = getConfiguration;