Skip to content

Commit

Permalink
fix(adapter): fix windows json editing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jimthedev committed Nov 9, 2015
1 parent 7bef1af commit 66ab19c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"gulp": "3.9.0",
"gulp-git": "1.6.0",
"inquirer": "0.11.0",
"json": "9.0.3",
"minimist": "1.2.0",
"node-uuid": "1.4.3",
"nodemon": "1.8.1",
Expand Down
18 changes: 17 additions & 1 deletion src/commitizen/adapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import fs from 'fs';
import findNodeModules from 'find-node-modules';
import _ from 'lodash';

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

Expand Down Expand Up @@ -28,8 +29,23 @@ export {
* Must be passed an absolute path to the cli's root
*/
function addPathToAdapterConfig(sh, cliPath, repoPath, adapterNpmName) {

let commitizenAdapterConfig = {
config: {
commitizen: {
path: `./node_modules/${adapterNpmName}`
}
}
};

let packageJsonPath = path.join(getNearestProjectRootDirectory(), 'package.json');
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}\"'`);
let packageJsonString = fs.readFileSync(packageJsonPath);
let packageJsonContent = JSON.parse(packageJsonString);
let newPackageJsonContent = '';
if(_.get(packageJsonContent,'config.commitizen.path') !== adapterNpmName) {
newPackageJsonContent = _.merge(packageJsonContent, commitizenAdapterConfig);
}
fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJsonContent));
}

/**
Expand Down

0 comments on commit 66ab19c

Please sign in to comment.