1+ import childProcess from 'child_process' ;
12import path from 'path' ;
2- import * as configLoader from './configLoader' ;
3- import { executeShellCommand } from '../common/util' ;
43import * as adapter from './adapter' ;
4+ import * as configLoader from '../configLoader' ;
55
66let {
77 addPathToAdapterConfig,
@@ -15,6 +15,9 @@ export default init;
1515
1616const CLI_PATH = path . normalize ( path . join ( __dirname , '../../' ) ) ;
1717
18+ /** Configuration sources in priority order. */
19+ const LOADER_CONFIGS = [ '.czrc' , '.cz.json' , 'package.json' ] ;
20+
1821/**
1922 * CZ INIT
2023 *
@@ -48,7 +51,7 @@ const defaultInitOptions = {
4851/**
4952 * Runs npm install for the adapter then modifies the config.commitizen as needed
5053 */
51- function init ( sh , repoPath , adapterNpmName , {
54+ function init ( repoPath , adapterNpmName , {
5255 save = false ,
5356 saveDev = true ,
5457 saveExact = false ,
@@ -60,13 +63,10 @@ function init (sh, repoPath, adapterNpmName, {
6063} = defaultInitOptions ) {
6164
6265 // 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 ) ;
6767
6868 // Load the current adapter config
69- let adapterConfig = loadAdapterConfig ( ) ;
69+ let adapterConfig = configLoader . loader ( LOADER_CONFIGS , null , repoPath ) ;
7070
7171 // Get the npm string mappings based on the arguments provided
7272 let stringMappings = yarn ? getYarnAddStringMappings ( dev , exact , force ) : getNpmInstallStringMappings ( save , saveDev , saveExact , force ) ;
@@ -88,11 +88,11 @@ function init (sh, repoPath, adapterNpmName, {
8888 }
8989
9090 try {
91- executeShellCommand ( sh , repoPath , installAdapterCommand ) ;
91+ childProcess . execSync ( installAdapterCommand , { cwd : repoPath } ) ;
9292 if ( includeCommitizen ) {
93- executeShellCommand ( sh , repoPath , installCommitizenCommand ) ;
93+ childProcess . execSync ( installCommitizenCommand , { cwd : repoPath } ) ;
9494 }
95- addPathToAdapterConfig ( sh , CLI_PATH , repoPath , adapterNpmName ) ;
95+ addPathToAdapterConfig ( CLI_PATH , repoPath , adapterNpmName ) ;
9696 } catch ( e ) {
9797 console . error ( e ) ;
9898 }
@@ -102,27 +102,11 @@ function init (sh, repoPath, adapterNpmName, {
102102 * Checks to make sure that the required arguments are passed
103103 * Throws an exception if any are not.
104104 */
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 ) {
109106 if ( ! path ) {
110107 throw new Error ( "Path is required when running init." ) ;
111108 }
112109 if ( ! adapterNpmName ) {
113110 throw new Error ( "The adapter's npm name is required when running init." ) ;
114111 }
115112}
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