1 | import { dirname } from "node:path";
|
2 | import { fileURLToPath } from "node:url";
|
3 | import importFrom from "import-from-esm";
|
4 | import conventionalChangelogAngular from "conventional-changelog-angular";
|
5 |
|
6 | /**
|
7 | * Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
|
8 | *
|
9 | * @param {Object} pluginConfig The plugin configuration.
|
10 | * @param {Object} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
|
11 | * @param {string} pluginConfig.config Requireable npm package with a custom conventional-changelog preset
|
12 | * @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
|
13 | * @param {Object} pluginConfig.writerOpts Additional `conventional-changelog-writer` options that will overwrite ones loaded by `preset` or `config`.
|
14 | * @param {Object} context The semantic-release context.
|
15 | * @param {Array<Object>} context.commits The commits to analyze.
|
16 | * @param {String} context.cwd The current working directory.
|
17 | *
|
18 | * @return {Promise<Object>} a `Promise` that resolve to the `conventional-changelog-core` config.
|
19 | */
|
20 | export default async ({ preset, config, parserOpts, writerOpts, presetConfig }, { cwd }) => {
|
21 | let loadedConfig;
|
22 | const __dirname = dirname(fileURLToPath(import.meta.url));
|
23 |
|
24 | if (preset) {
|
25 | const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
|
26 | loadedConfig = await (
|
27 | (await importFrom.silent(__dirname, presetPackage)) || (await importFrom(cwd, presetPackage))
|
28 | )(presetConfig);
|
29 | } else if (config) {
|
30 | loadedConfig = await ((await importFrom.silent(__dirname, config)) || (await importFrom(cwd, config)))();
|
31 | } else {
|
32 | loadedConfig = await conventionalChangelogAngular();
|
33 | }
|
34 |
|
35 | return {
|
36 | parserOpts: { ...loadedConfig.parser, ...parserOpts },
|
37 | writerOpts: { ...loadedConfig.writer, ...writerOpts },
|
38 | };
|
39 | };
|