1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const execute_rule_1 = __importDefault(require("@commitlint/execute-rule"));
|
7 | const resolve_extends_1 = __importDefault(require("@commitlint/resolve-extends"));
|
8 | const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
|
9 | const merge_1 = __importDefault(require("lodash/merge"));
|
10 | const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
|
11 | const pick_1 = __importDefault(require("lodash/pick"));
|
12 | const union_1 = __importDefault(require("lodash/union"));
|
13 | const path_1 = __importDefault(require("path"));
|
14 | const resolve_from_1 = __importDefault(require("resolve-from"));
|
15 | const load_config_1 = require("./utils/load-config");
|
16 | const load_parser_opts_1 = require("./utils/load-parser-opts");
|
17 | const load_plugin_1 = __importDefault(require("./utils/load-plugin"));
|
18 | const pick_config_1 = require("./utils/pick-config");
|
19 | const w = (_, b) => Array.isArray(b) ? b : undefined;
|
20 | async function load(seed = {}, options = {}) {
|
21 | const cwd = typeof options.cwd === 'undefined' ? process.cwd() : options.cwd;
|
22 | const loaded = await load_config_1.loadConfig(cwd, options.file);
|
23 | const base = loaded && loaded.filepath ? path_1.default.dirname(loaded.filepath) : cwd;
|
24 |
|
25 |
|
26 |
|
27 | const config = pick_config_1.pickConfig(merge_1.default({}, loaded ? loaded.config : null, seed));
|
28 | const opts = merge_1.default({ extends: [], rules: {}, formatter: '@commitlint/format' }, pick_1.default(config, 'extends', 'plugins', 'ignores', 'defaultIgnores'));
|
29 |
|
30 | if (typeof config.parserPreset === 'string') {
|
31 | const resolvedParserPreset = resolve_from_1.default(base, config.parserPreset);
|
32 | config.parserPreset = {
|
33 | name: config.parserPreset,
|
34 | path: resolvedParserPreset,
|
35 | parserOpts: require(resolvedParserPreset),
|
36 | };
|
37 | }
|
38 |
|
39 | const extended = resolve_extends_1.default(opts, {
|
40 | prefix: 'commitlint-config',
|
41 | cwd: base,
|
42 | parserPreset: config.parserPreset,
|
43 | });
|
44 | const preset = pick_config_1.pickConfig(mergeWith_1.default(extended, config, w));
|
45 | preset.plugins = {};
|
46 |
|
47 |
|
48 |
|
49 | if (typeof preset.parserPreset === 'object') {
|
50 | preset.parserPreset.parserOpts = await load_parser_opts_1.loadParserOpts(preset.parserPreset.name,
|
51 |
|
52 | preset.parserPreset);
|
53 | }
|
54 |
|
55 | if (typeof config.formatter === 'string') {
|
56 | preset.formatter =
|
57 | resolve_from_1.default.silent(base, config.formatter) || config.formatter;
|
58 | }
|
59 |
|
60 | if (Array.isArray(extended.plugins)) {
|
61 | config.plugins = union_1.default(config.plugins, extended.plugins || []);
|
62 | }
|
63 |
|
64 | if (Array.isArray(config.plugins)) {
|
65 | config.plugins.forEach((plugin) => {
|
66 | if (typeof plugin === 'string') {
|
67 | load_plugin_1.default(preset.plugins, plugin, process.env.DEBUG === 'true');
|
68 | }
|
69 | else {
|
70 | preset.plugins.local = plugin;
|
71 | }
|
72 | });
|
73 | }
|
74 | const rules = preset.rules ? preset.rules : {};
|
75 | const qualifiedRules = (await Promise.all(Object.entries(rules || {}).map((entry) => execute_rule_1.default(entry)))).reduce((registry, item) => {
|
76 | const [key, value] = item;
|
77 | registry[key] = value;
|
78 | return registry;
|
79 | }, {});
|
80 | const helpUrl = typeof config.helpUrl === 'string'
|
81 | ? config.helpUrl
|
82 | : 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint';
|
83 | const prompt = preset.prompt && isPlainObject_1.default(preset.prompt) ? preset.prompt : {};
|
84 | return {
|
85 | extends: preset.extends,
|
86 | formatter: preset.formatter,
|
87 | parserPreset: preset.parserPreset,
|
88 | ignores: preset.ignores,
|
89 | defaultIgnores: preset.defaultIgnores,
|
90 | plugins: preset.plugins,
|
91 | rules: qualifiedRules,
|
92 | helpUrl,
|
93 | prompt,
|
94 | };
|
95 | }
|
96 | exports.default = load;
|
97 |
|
\ | No newline at end of file |