1
+ import childProcess from 'child_process' ;
1
2
import path from 'path' ;
2
- import * as configLoader from './configLoader' ;
3
- import { executeShellCommand } from '../common/util' ;
4
3
import * as adapter from './adapter' ;
4
+ import * as configLoader from '../configLoader' ;
5
5
6
6
let {
7
7
addPathToAdapterConfig,
@@ -15,6 +15,9 @@ export default init;
15
15
16
16
const CLI_PATH = path . normalize ( path . join ( __dirname , '../../' ) ) ;
17
17
18
+ /** Configuration sources in priority order. */
19
+ const LOADER_CONFIGS = [ '.czrc' , '.cz.json' , 'package.json' ] ;
20
+
18
21
/**
19
22
* CZ INIT
20
23
*
@@ -48,7 +51,7 @@ const defaultInitOptions = {
48
51
/**
49
52
* Runs npm install for the adapter then modifies the config.commitizen as needed
50
53
*/
51
- function init ( sh , repoPath , adapterNpmName , {
54
+ function init ( repoPath , adapterNpmName , {
52
55
save = false ,
53
56
saveDev = true ,
54
57
saveExact = false ,
@@ -60,13 +63,10 @@ function init (sh, repoPath, adapterNpmName, {
60
63
} = defaultInitOptions ) {
61
64
62
65
// Don't let things move forward if required args are missing
63
- checkRequiredArguments ( sh , repoPath , adapterNpmName ) ;
64
-
65
- // Move to the correct directory so we can run commands
66
- sh . cd ( repoPath ) ;
66
+ checkRequiredArguments ( repoPath , adapterNpmName ) ;
67
67
68
68
// Load the current adapter config
69
- let adapterConfig = loadAdapterConfig ( ) ;
69
+ let adapterConfig = configLoader . loader ( LOADER_CONFIGS , null , repoPath ) ;
70
70
71
71
// Get the npm string mappings based on the arguments provided
72
72
let stringMappings = yarn ? getYarnAddStringMappings ( dev , exact , force ) : getNpmInstallStringMappings ( save , saveDev , saveExact , force ) ;
@@ -88,11 +88,11 @@ function init (sh, repoPath, adapterNpmName, {
88
88
}
89
89
90
90
try {
91
- executeShellCommand ( sh , repoPath , installAdapterCommand ) ;
91
+ childProcess . execSync ( installAdapterCommand , { cwd : repoPath } ) ;
92
92
if ( includeCommitizen ) {
93
- executeShellCommand ( sh , repoPath , installCommitizenCommand ) ;
93
+ childProcess . execSync ( installCommitizenCommand , { cwd : repoPath } ) ;
94
94
}
95
- addPathToAdapterConfig ( sh , CLI_PATH , repoPath , adapterNpmName ) ;
95
+ addPathToAdapterConfig ( CLI_PATH , repoPath , adapterNpmName ) ;
96
96
} catch ( e ) {
97
97
console . error ( e ) ;
98
98
}
@@ -102,27 +102,11 @@ function init (sh, repoPath, adapterNpmName, {
102
102
* Checks to make sure that the required arguments are passed
103
103
* Throws an exception if any are not.
104
104
*/
105
- function checkRequiredArguments ( sh , path , adapterNpmName ) {
106
- if ( ! sh ) {
107
- throw new Error ( "You must pass an instance of shelljs when running init." ) ;
108
- }
105
+ function checkRequiredArguments ( path , adapterNpmName ) {
109
106
if ( ! path ) {
110
107
throw new Error ( "Path is required when running init." ) ;
111
108
}
112
109
if ( ! adapterNpmName ) {
113
110
throw new Error ( "The adapter's npm name is required when running init." ) ;
114
111
}
115
112
}
116
-
117
- /**
118
- * CONFIG
119
- * Loads and returns the adapter config at key config.commitizen, if it exists
120
- */
121
- function loadAdapterConfig ( ) {
122
- let config = configLoader . load ( ) ;
123
- if ( config ) {
124
- return config ;
125
- } else {
126
-
127
- }
128
- }
0 commit comments