@@ -47,22 +47,33 @@ export function matchLoadedConfigName(name: string) {
4747 * @returns An object with the `{@link SWACLIOptions}` config or an empty object if the config file, or the config entry were not found.
4848 */
4949export async function getConfigFileOptions ( configName : string | undefined , configFilePath : string ) : Promise < SWACLIConfig > {
50- logger . silly ( `Getting config file options from ${ configFilePath } ...` ) ;
50+ logger . silly ( `Getting config file options from " ${ configFilePath } " ...` ) ;
5151
52- configFilePath = path . resolve ( configFilePath ) ;
53- if ( ! swaCliConfigFileExists ( configFilePath ) ) {
54- logger . silly ( `Config file does not exist at ${ configFilePath } ` ) ;
55- return { } ;
52+ let configFilePathResolved = path . resolve ( configFilePath ) ;
53+ if ( ! swaCliConfigFileExists ( configFilePathResolved ) ) {
54+ logger . silly ( `Config file does not exist at "${ configFilePath } "` ) ;
55+
56+ // Handle the case when the user runs the command outside the project path
57+ if ( ! configName || ! swaCliConfigFileExists ( path . resolve ( configName , swaCliConfigFilename ) ) ) {
58+ return { } ;
59+ }
60+ logger . warn (
61+ `WARNING: Config file does not exist at "${ configFilePath } ", but can be detected at "${ path . join (
62+ configName ,
63+ swaCliConfigFilename
64+ ) } ". Do you mean "swa --config ${ path . join ( configName , swaCliConfigFilename ) } <command> ${ configName } [options]"?`
65+ ) ;
66+ configFilePathResolved = path . resolve ( configName , swaCliConfigFilename ) ;
5667 }
5768
58- const cliConfig = await tryParseSwaCliConfig ( configFilePath ) ;
69+ const cliConfig = await tryParseSwaCliConfig ( configFilePathResolved ) ;
5970 if ( ! cliConfig . configurations ) {
6071 logger . warn ( `${ swaCliConfigFilename } is missing the "configurations" property. No options will be loaded.` ) ;
6172 return { } ;
6273 }
6374
6475 // Use configuration root path as the outputLocation
65- const configDir = path . dirname ( configFilePath ) ;
76+ const configDir = path . dirname ( configFilePathResolved ) ;
6677 process . chdir ( configDir ) ;
6778
6879 logger . silly ( `Changed directory to ${ configDir } ` ) ;
@@ -76,10 +87,10 @@ export async function getConfigFileOptions(configName: string | undefined, confi
7687 }
7788
7889 const [ configName , config ] = Object . entries ( cliConfig . configurations ) [ 0 ] ;
79- printConfigMsg ( configName , configFilePath ) ;
90+ printConfigMsg ( configName , configFilePathResolved ) ;
8091 currentSwaCliConfigFromFile = {
8192 name : configName ,
82- filePath : configFilePath ,
93+ filePath : configFilePathResolved ,
8394 config,
8495 } ;
8596 return { ...config } ;
0 commit comments