Skip to content

Commit 468e924

Browse files
committed
refactor: simplify configLoader call
1 parent 88aa26f commit 468e924

File tree

4 files changed

+6
-28
lines changed

4 files changed

+6
-28
lines changed

src/commitizen.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
import * as adapter from './commitizen/adapter';
33
import * as cache from './commitizen/cache';
44
import commit from './commitizen/commit';
5-
import * as configLoader from './commitizen/configLoader';
65
import init from './commitizen/init';
76
import * as staging from './commitizen/staging';
87

98
export {
109
adapter,
1110
cache,
1211
commit,
13-
configLoader,
1412
init,
1513
staging
1614
};

src/commitizen/configLoader.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/commitizen/init.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import childProcess from 'child_process';
22
import path from 'path';
3-
import * as configLoader from './configLoader';
43
import * as adapter from './adapter';
4+
import * as configLoader from '../configLoader';
55

66
let {
77
addPathToAdapterConfig,
@@ -15,6 +15,9 @@ export default init;
1515

1616
const CLI_PATH = path.normalize(path.join(__dirname, '../../'));
1717

18+
/** Configuration sources in priority order. */
19+
const LOADER_CONFIGS = ['.czrc', '.cz.json', 'package.json'];
20+
1821
/**
1922
* CZ INIT
2023
*
@@ -63,7 +66,7 @@ function init (repoPath, adapterNpmName, {
6366
checkRequiredArguments(repoPath, adapterNpmName);
6467

6568
// Load the current adapter config
66-
let adapterConfig = loadAdapterConfig(repoPath);
69+
let adapterConfig = configLoader.loader(LOADER_CONFIGS, null, repoPath);
6770

6871
// Get the npm string mappings based on the arguments provided
6972
let stringMappings = yarn ? getYarnAddStringMappings(dev, exact, force) : getNpmInstallStringMappings(save, saveDev, saveExact, force);
@@ -107,16 +110,3 @@ function checkRequiredArguments (path, adapterNpmName) {
107110
throw new Error("The adapter's npm name is required when running init.");
108111
}
109112
}
110-
111-
/**
112-
* CONFIG
113-
* Loads and returns the adapter config at key config.commitizen, if it exists
114-
*/
115-
function loadAdapterConfig (cwd) {
116-
let config = configLoader.load(null, cwd);
117-
if (config) {
118-
return config;
119-
} else {
120-
121-
}
122-
}

src/configLoader/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default loader;
1313

1414
/**
1515
* Get content of the configuration file
16-
* @param {String} config - partial path to configuration file
16+
* @param {String|null} config - partial path to configuration file
1717
* @param {String} cwd - directory path which will be joined with config argument
1818
* @return {Object|undefined}
1919
*/

0 commit comments

Comments
 (0)