File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #!/usr/bin/env node
1+ #!/usr/bin/env node
22const path = require ( "path" ) ;
33const fs = require ( "fs" ) ;
44const execute = require ( './execute' ) ;
@@ -37,6 +37,38 @@ function getRepositories(path) {
3737 }
3838}
3939
40+ // TODO: handle getting closest config
41+ async function getConfig ( directory , filename = '' ) {
42+ const filePath = path . resolve ( directory , filename ) ;
43+ if ( ! filePath . includes ( 'node_modules' ) ) {
44+ const configPath = findClosestConfig ( filePath )
45+ if ( configPath ) {
46+ return { config : require ( configPath ) , configPath, filePath } ;
47+
48+ } else {
49+ console . log ( 'No CoCreate.config file found in parent directories.' ) ;
50+ }
51+ }
52+
53+ }
54+
55+ function findClosestConfig ( filePath ) {
56+ let currentDir = filePath ;
57+
58+ while ( currentDir !== '/' && currentDir !== '.' ) {
59+ let configFile = path . join ( currentDir , 'CoCreate.config.js' ) ;
60+
61+ if ( fs . existsSync ( configFile ) ) {
62+ return configFile ;
63+ }
64+
65+ currentDir = path . dirname ( currentDir ) ;
66+ }
67+
68+ return null ;
69+ }
70+
71+
4072const currentRepoPath = path . resolve ( process . cwd ( ) , "CoCreate.config.js" ) ;
4173let packageJsonPath = path . resolve ( process . cwd ( ) , 'package.json' ) ;
4274let directory
You can’t perform that action at this time.
0 commit comments