1 |
|
2 |
|
3 |
|
4 | const CZ_CONFIG_NAME = '.cz-config.js';
|
5 | const findConfig = require('find-config');
|
6 | const path = require('path');
|
7 | const log = require('./logger');
|
8 |
|
9 |
|
10 | const readConfigFile = () => {
|
11 |
|
12 | const czConfig = findConfig.require(CZ_CONFIG_NAME, { home: false });
|
13 |
|
14 | if (czConfig) {
|
15 | return czConfig;
|
16 | }
|
17 |
|
18 |
|
19 | let pkg = findConfig('package.json', { home: false });
|
20 | if (pkg) {
|
21 | const pkgDir = path.dirname(pkg);
|
22 |
|
23 | pkg = require(pkg);
|
24 |
|
25 | if (pkg.config && pkg.config['cz-customizable'] && pkg.config['cz-customizable'].config) {
|
26 |
|
27 | const pkgPath = path.resolve(pkgDir, pkg.config['cz-customizable'].config);
|
28 |
|
29 | log.info('>>> Using cz-customizable config specified in your package.json: ', pkgPath);
|
30 |
|
31 | return require(pkgPath);
|
32 | }
|
33 | }
|
34 |
|
35 | log.warn(
|
36 | 'Unable to find a configuration file. Please refer to documentation to learn how to set up: https://github.com/leonardoanalista/cz-customizable#steps "'
|
37 | );
|
38 | return null;
|
39 | };
|
40 |
|
41 | module.exports = readConfigFile;
|