* 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)
| 17 | * @return {Object} |
| 18 | */ |
| 19 | function 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 |
no test coverage detected