1 | const {promisify} = require('util');
|
2 | const importFrom = require('import-from');
|
3 | const conventionalChangelogAngular = require('conventional-changelog-angular');
|
4 |
|
5 | /**
|
6 | * Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
|
7 | *
|
8 | * @param {Object} pluginConfig The plugin configuration.
|
9 | * @param {Object} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
|
10 | * @param {String} pluginConfig.config Requierable npm package with a custom conventional-changelog preset
|
11 | * @param {Object} pluginConfig.parserOpts Additionnal `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
|
12 | * @param {Object} context The semantic-release context.
|
13 | * @param {String} context.cwd The current working directory.
|
14 | * @return {Promise<Object>} a `Promise` that resolve to the `conventional-changelog-parser` options.
|
15 | */
|
16 | module.exports = async ({preset, config, parserOpts}, {cwd}) => {
|
17 | let loadedConfig;
|
18 |
|
19 | if (preset) {
|
20 | const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
|
21 | loadedConfig = importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage);
|
22 | } else if (config) {
|
23 | loadedConfig = importFrom.silent(__dirname, config) || importFrom(cwd, config);
|
24 | } else {
|
25 | loadedConfig = conventionalChangelogAngular;
|
26 | }
|
27 |
|
28 | if (typeof loadedConfig === 'function') {
|
29 | loadedConfig = await promisify(loadedConfig)();
|
30 | } else {
|
31 | loadedConfig = await loadedConfig;
|
32 | }
|
33 |
|
34 | return !preset && !config && parserOpts ? parserOpts : {...loadedConfig.parserOpts, ...parserOpts};
|
35 | };
|