@@ -22,7 +22,7 @@ public function __construct(?string $path = null, ?Stream $stream = null) {
2222 }
2323 $ this ->defaultPath = implode (DIRECTORY_SEPARATOR , [
2424 getcwd (),
25- "build.json " ,
25+ "build.ini " ,
2626 ]);
2727 $ this ->workingDirectory = $ path ;
2828 $ this ->stream = $ stream ;
@@ -68,32 +68,49 @@ protected function formatWorkingDirectory():string {
6868
6969 /** @SuppressWarnings(PHPMD.ExitExpression) */
7070 protected function getJsonPath (string $ workingDirectory ):string {
71- $ jsonPath = $ workingDirectory ;
72- if (is_dir ($ jsonPath )) {
73- $ jsonPath .= DIRECTORY_SEPARATOR ;
74- $ jsonPath .= "build.json " ;
75- }
71+ $ jsonPath = $ this ->resolveConfigPath ($ workingDirectory )
72+ ?? $ this ->resolveConfigPath ($ this ->defaultPath );
7673
77- if (!is_file ($ jsonPath )) {
78- $ jsonPath = $ this ->defaultPath ;
79- }
80- if (!is_file ($ jsonPath )) {
81- $ whichPath = $ jsonPath === $ this ->defaultPath
82- ? "default "
83- : "user " ;
74+ if (is_null ($ jsonPath )) {
75+ $ whichPath = $ this ->defaultPath === $ workingDirectory
76+ ? "user "
77+ : "default " ;
8478
79+ $ errorString = "No build config found. Trying $ whichPath path: $ this ->defaultPath " ;
8580 $ this ->stream ->writeLine (
86- " No build config found. Trying $ whichPath path: $ jsonPath " ,
81+ $ errorString ,
8782 Stream::ERROR
8883 );
8984// TODO: Dynamic exit code https://github.com/PhpGt/Cli/issues/13
9085// phpcs:ignore
91- exit ( 1 );
86+ throw new BuildException ( $ errorString );
9287 }
9388
9489 return $ jsonPath ;
9590 }
9691
92+ protected function resolveConfigPath (string $ path ):?string {
93+ if (is_dir ($ path )) {
94+ $ iniPath = $ path . DIRECTORY_SEPARATOR . "build.ini " ;
95+ if (is_file ($ iniPath )) {
96+ return $ iniPath ;
97+ }
98+
99+ $ jsonPath = $ path . DIRECTORY_SEPARATOR . "build.json " ;
100+ if (is_file ($ jsonPath )) {
101+ return $ jsonPath ;
102+ }
103+
104+ return null ;
105+ }
106+
107+ if (is_file ($ path )) {
108+ return $ path ;
109+ }
110+
111+ return null ;
112+ }
113+
97114 /**
98115 * @SuppressWarnings(PHPMD.ExitExpression)
99116 * @param array<int, string> $errors
@@ -110,7 +127,7 @@ protected function checkRequirements(
110127 $ workingDirectory ,
111128 $ mode ,
112129 );
113- } catch (JsonParseException $ exception ) {
130+ } catch (ConfigurationParseException $ exception ) {
114131 $ this ->stream ->writeLine ("Syntax error in $ jsonPath " , Stream::ERROR );
115132// TODO: Dynamic exit code https://github.com/PhpGt/Cli/issues/13
116133// phpcs:ignore
0 commit comments