Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(adapter): Load adapter from package.json if path provided has one #97

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/commitizen/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ function resolveAdapterPath(inboundAdapterPath) {
// Try to open the provided path
try {

// If we're given a directory, append index.js
if(fs.lstatSync(inboundAdapterPath).isDirectory()) {

// Modify the path and make sure the modified path exists
outboundAdapterPath = path.join(inboundAdapterPath, 'index.js');
fs.lstatSync(outboundAdapterPath);
// If we're given a directory, check for a package.json, otherwise append index.js
if (fs.lstatSync(inboundAdapterPath).isDirectory()) {
let inboundAdapterPackageJsonPath = path.join(inboundAdapterPath, 'package.json');
if (fs.lstatSync(inboundAdapterPackageJsonPath)) {
let packageJsonString = fs.readFileSync(inboundAdapterPackageJsonPath, 'utf-8');
let packageJsonContent = JSON.parse(packageJsonString);
let inboundAdapterMainJsPath = _.get(packageJsonContent, 'main');
outboundAdapterPath = path.join(inboundAdapterPath, inboundAdapterMainJsPath);
} else {
// Modify the path and make sure the modified path exists
outboundAdapterPath = path.join(inboundAdapterPath, 'index.js');
fs.lstatSync(outboundAdapterPath);
}

} else {
// The file exists and is a file, so just return it
Expand All @@ -147,4 +154,4 @@ function resolveAdapterPath(inboundAdapterPath) {
throw err;
}

}
}