MCPcopy Index your code
hub / github.com/commitizen/cz-cli / addPathToAdapterConfig

Function addPathToAdapterConfig

src/commitizen/adapter.js:34–54  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

32 * Must be passed an absolute path to the cli's root
33 */
34function 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

Callers 1

initFunction · 0.85

Calls 1

Tested by

no test coverage detected