MCPcopy
hub / github.com/commitizen/cz-cli / readConfigContent

Function readConfigContent

src/configLoader/getContent.js:19–43  ·  view source on GitHub ↗

* Read the content of a configuration file * - if not js or json: strip any comments * - if js or json: require it * @param {String} configPath - full path to configuration file * @return {Object}

(configPath)

Source from the content-addressed store, hash-verified

17 * @return {Object}
18 */
19function readConfigContent (configPath) {
20 const parsedPath = path.parse(configPath)
21 const isRcFile = parsedPath.ext !== '.js' && parsedPath.ext !== '.json';
22 const jsonString = readConfigFileContent(configPath);
23 const parse = isRcFile ?
24 (contents) => JSON.parse(stripJSONComments(contents)) :
25 (contents) => JSON.parse(contents);
26
27 try {
28 const parsed = parse(jsonString);
29
30 Object.defineProperty(parsed, 'configPath', {
31 value: configPath
32 });
33
34 return parsed;
35 } catch (error) {
36 error.message = [
37 `Parsing JSON at ${configPath} for commitizen config failed:`,
38 error.mesasge
39 ].join('\n');
40
41 throw error;
42 }
43}
44
45/**
46 * Get content of the configuration file

Callers 1

getConfigContentFunction · 0.85

Calls 2

readConfigFileContentFunction · 0.85
parseFunction · 0.50

Tested by

no test coverage detected