Skip to content

Commit 66ab19c

Browse files
committed
fix(adapter): fix windows json editing
The json parsing that we were using was overly complicated. This is much simpler and solves some of the odd behavior that was happening on windows when installing and dealing with adapters. Closes #42
1 parent 7bef1af commit 66ab19c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"gulp": "3.9.0",
6464
"gulp-git": "1.6.0",
6565
"inquirer": "0.11.0",
66-
"json": "9.0.3",
6766
"minimist": "1.2.0",
6867
"node-uuid": "1.4.3",
6968
"nodemon": "1.8.1",

src/commitizen/adapter.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path';
22
import fs from 'fs';
33
import findNodeModules from 'find-node-modules';
4+
import _ from 'lodash';
45

56
import {isFunction} from '../common/util';
67

@@ -28,8 +29,23 @@ export {
2829
* Must be passed an absolute path to the cli's root
2930
*/
3031
function addPathToAdapterConfig(sh, cliPath, repoPath, adapterNpmName) {
32+
33+
let commitizenAdapterConfig = {
34+
config: {
35+
commitizen: {
36+
path: `./node_modules/${adapterNpmName}`
37+
}
38+
}
39+
};
40+
3141
let packageJsonPath = path.join(getNearestProjectRootDirectory(), 'package.json');
32-
sh.exec(`${cliPath}/node_modules/.bin/json -I -f ${packageJsonPath} -e 'if(!this.config) {this.config={};}; if(!this.config.commitizen) { this.config.commitizen={};}; this.config.commitizen.path=\"./node_modules/${adapterNpmName}\"'`);
42+
let packageJsonString = fs.readFileSync(packageJsonPath);
43+
let packageJsonContent = JSON.parse(packageJsonString);
44+
let newPackageJsonContent = '';
45+
if(_.get(packageJsonContent,'config.commitizen.path') !== adapterNpmName) {
46+
newPackageJsonContent = _.merge(packageJsonContent, commitizenAdapterConfig);
47+
}
48+
fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJsonContent));
3349
}
3450

3551
/**

0 commit comments

Comments
 (0)