@@ -3,6 +3,7 @@ import fs from 'fs';
3
3
import findNodeModules from 'find-node-modules' ;
4
4
import _ from 'lodash' ;
5
5
import detectIndent from 'detect-indent' ;
6
+ import sh from 'shelljs' ;
6
7
7
8
import { isFunction } from '../common/util' ;
8
9
@@ -30,15 +31,15 @@ export {
30
31
* Must be passed an absolute path to the cli's root
31
32
*/
32
33
function addPathToAdapterConfig ( sh , cliPath , repoPath , adapterNpmName ) {
33
-
34
+
34
35
let commitizenAdapterConfig = {
35
36
config : {
36
37
commitizen : {
37
38
path : `./node_modules/${ adapterNpmName } `
38
39
}
39
40
}
40
41
} ;
41
-
42
+
42
43
let packageJsonPath = path . join ( getNearestProjectRootDirectory ( ) , 'package.json' ) ;
43
44
let packageJsonString = fs . readFileSync ( packageJsonPath , 'utf-8' ) ;
44
45
// tries to detect the indentation and falls back to a default if it can't
@@ -55,28 +56,28 @@ function addPathToAdapterConfig(sh, cliPath, repoPath, adapterNpmName) {
55
56
* Generates an npm install command given a map of strings and a package name
56
57
*/
57
58
function generateNpmInstallAdapterCommand ( stringMappings , adapterNpmName ) {
58
-
59
+
59
60
// Start with an initial npm install command
60
61
let installAdapterCommand = `npm install ${ adapterNpmName } ` ;
61
-
62
+
62
63
// Append the neccesary arguments to it based on user preferences
63
64
for ( let [ key , value ] of stringMappings . entries ( ) ) {
64
65
if ( value ) {
65
66
installAdapterCommand = installAdapterCommand + ' ' + value ;
66
67
}
67
68
}
68
-
69
+
69
70
return installAdapterCommand ;
70
71
}
71
72
72
73
/**
73
74
* Gets the nearest npm_modules directory
74
75
*/
75
76
function getNearestNodeModulesDirectory ( options ) {
76
-
77
+
77
78
// Get the nearest node_modules directories to the current working directory
78
79
let nodeModulesDirectories = findNodeModules ( options ) ;
79
-
80
+
80
81
// Make sure we find a node_modules folder
81
82
if ( nodeModulesDirectories && nodeModulesDirectories . length > 0 ) {
82
83
return nodeModulesDirectories [ 0 ] ;
@@ -128,12 +129,12 @@ function resolveAdapterPath(inboundAdapterPath) {
128
129
// Check if inboundAdapterPath is a path or node module name
129
130
let parsed = path . parse ( inboundAdapterPath ) ;
130
131
let isPath = parsed . dir . length > 0 ;
131
-
132
- // Resolve from process.cwd() if inboundAdapterPath is a path
132
+
133
+ // Resolve from the root of the git repo if inboundAdapterPath is a path
133
134
let absoluteAdapterPath = isPath ?
134
- path . resolve ( getNearestProjectRootDirectory ( ) , inboundAdapterPath ) :
135
+ path . resolve ( getGitRootPath ( ) , inboundAdapterPath ) :
135
136
inboundAdapterPath ;
136
-
137
+
137
138
try {
138
139
// try to resolve the given path
139
140
return require . resolve ( absoluteAdapterPath ) ;
@@ -142,3 +143,7 @@ function resolveAdapterPath(inboundAdapterPath) {
142
143
throw error ;
143
144
}
144
145
}
146
+
147
+ function getGitRootPath ( ) {
148
+ return sh . exec ( 'git rev-parse --show-toplevel' ) . output . trim ( ) ;
149
+ }
0 commit comments