* Modifies the package.json, sets config.commitizen.path to the path of the adapter * Must be passed an absolute path to the cli's root
(cliPath, repoPath, adapterNpmName)
| 32 | * Must be passed an absolute path to the cli's root |
| 33 | */ |
| 34 | function addPathToAdapterConfig (cliPath, repoPath, adapterNpmName) { |
| 35 | |
| 36 | let commitizenAdapterConfig = { |
| 37 | config: { |
| 38 | commitizen: { |
| 39 | path: `./node_modules/${adapterNpmName}` |
| 40 | } |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | let packageJsonPath = path.join(getNearestProjectRootDirectory(repoPath), 'package.json'); |
| 45 | let packageJsonString = fs.readFileSync(packageJsonPath, 'utf-8'); |
| 46 | // tries to detect the indentation and falls back to a default if it can't |
| 47 | let indent = detectIndent(packageJsonString).indent || ' '; |
| 48 | let packageJsonContent = JSON.parse(packageJsonString); |
| 49 | let newPackageJsonContent = ''; |
| 50 | if (_.get(packageJsonContent, 'config.commitizen.path') !== adapterNpmName) { |
| 51 | newPackageJsonContent = _.merge(packageJsonContent, commitizenAdapterConfig); |
| 52 | } |
| 53 | fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJsonContent, null, indent) + '\n'); |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Get additional options for install command |
no test coverage detected