Skip to content

Commit 6869c9c

Browse files
Patrick McElhaneyPatrick McElhaney
Patrick McElhaney
authored and
Patrick McElhaney
committed
fix(adapter): allows git-cz to run from subdirectories
looks for a local cz adapter relative to the project root rather than the current directory closes commitizen#187
1 parent ec1c686 commit 6869c9c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/commitizen/adapter.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export {
3030
* Must be passed an absolute path to the cli's root
3131
*/
3232
function addPathToAdapterConfig(sh, cliPath, repoPath, adapterNpmName) {
33-
33+
3434
let commitizenAdapterConfig = {
3535
config: {
3636
commitizen: {
3737
path: `./node_modules/${adapterNpmName}`
3838
}
3939
}
4040
};
41-
41+
4242
let packageJsonPath = path.join(getNearestProjectRootDirectory(), 'package.json');
4343
let packageJsonString = fs.readFileSync(packageJsonPath, 'utf-8');
4444
// tries to detect the indentation and falls back to a default if it can't
@@ -55,28 +55,28 @@ function addPathToAdapterConfig(sh, cliPath, repoPath, adapterNpmName) {
5555
* Generates an npm install command given a map of strings and a package name
5656
*/
5757
function generateNpmInstallAdapterCommand(stringMappings, adapterNpmName) {
58-
58+
5959
// Start with an initial npm install command
6060
let installAdapterCommand = `npm install ${adapterNpmName}`;
61-
61+
6262
// Append the neccesary arguments to it based on user preferences
6363
for(let [key, value] of stringMappings.entries()) {
6464
if(value) {
6565
installAdapterCommand = installAdapterCommand + ' ' + value;
6666
}
6767
}
68-
68+
6969
return installAdapterCommand;
7070
}
7171

7272
/**
7373
* Gets the nearest npm_modules directory
7474
*/
7575
function getNearestNodeModulesDirectory(options) {
76-
76+
7777
// Get the nearest node_modules directories to the current working directory
7878
let nodeModulesDirectories = findNodeModules(options);
79-
79+
8080
// Make sure we find a node_modules folder
8181
if(nodeModulesDirectories && nodeModulesDirectories.length > 0) {
8282
return nodeModulesDirectories[0];
@@ -112,7 +112,7 @@ function getPrompter(adapterPath) {
112112

113113
// Load the adapter
114114
let adapter = require(resolvedAdapterPath);
115-
115+
116116
if(adapter && adapter.prompter && isFunction(adapter.prompter)) {
117117
return adapter.prompter;
118118
} else {
@@ -128,12 +128,12 @@ function resolveAdapterPath(inboundAdapterPath) {
128128
// Check if inboundAdapterPath is a path or node module name
129129
let parsed = path.parse(inboundAdapterPath);
130130
let isPath = parsed.dir.length > 0;
131-
131+
132132
// Resolve from process.cwd() if inboundAdapterPath is a path
133133
let absoluteAdapterPath = isPath ?
134-
path.resolve(process.cwd(), inboundAdapterPath) :
134+
path.resolve(getNearestProjectRootDirectory(), inboundAdapterPath) :
135135
inboundAdapterPath;
136-
136+
137137
try {
138138
// try to resolve the given path
139139
return require.resolve(absoluteAdapterPath);

0 commit comments

Comments
 (0)