@@ -11,6 +11,16 @@ trait Show
1111
1212 private const CROSS_MARK = "\u{2718}" ; // ✘
1313
14+ private const STOP = "\u{1F6AB}" ; // 🚫
15+
16+ private const ROCKET = "\u{1F680}" ; // 🚀
17+
18+ private const FIRE = "\u{1F525}" ; // 🔥
19+
20+ private const LINK = "\u{1F517}" ; // 🔗
21+
22+ private const STAR = "\u{2B50}" ; // ⭐
23+
1424 private function show (): void
1525 {
1626 $ fullStatus = $ this ->check ();
@@ -41,164 +51,77 @@ private function show(): void
4151
4252 table ($ headers , $ rows );
4353
44- $ badge = '<fg=black;bg=yellow;options=bold> ' ;
45- $ updateBadge = '<fg=black;bg=yellow;options=bold> ' ;
54+ $ icon = self ::STOP ;
55+ $ badge = '<fg=gray;bg=black;options=bold> ' ;
56+ $ updateBadge = '<fg=gray;bg=black;options=bold> ' ;
4657
4758 if ($ fullStatus ['status ' ] === 'error ' ) {
48- $ badge = '<fg=black;bg=red;options=bold> ' ;
59+ $ icon = self ::STOP ;
60+ $ badge = '<fg=red;bg=black;options=bold> ' ;
4961 }
5062
5163 if ($ fullStatus ['status ' ] === 'deploy ' ) {
52- $ badge = '<fg=black;bg=blue;options=bold> ' ;
64+ $ icon = self ::ROCKET ;
65+ $ badge = '<fg=blue;bg=black;options=bold> ' ;
5366 }
5467
5568 if ($ fullStatus ['status ' ] === 'linked ' ) {
56- $ badge = '<fg=black;bg=green;options=bold> ' ;
69+ $ icon = self ::LINK ;
70+ $ badge = '<fg=green;bg=black;options=bold> ' ;
5771 }
5872
5973 if ($ isInSync ) {
60- $ updateBadge = '<fg=black;bg=green;options=bold> ' ;
74+ $ updateIcon = self ::STAR ;
75+ $ updateBadge = '<fg=green;bg=black;options=bold> ' ;
6176 } else {
62- $ updateBadge = '<fg=black;bg=red;options=bold> ' ;
77+ $ updateIcon = self ::FIRE ;
78+ $ updateBadge = '<fg=red;bg=black;options=bold> ' ;
6379 }
6480
65- info (' ' .$ badge .strtoupper ($ fullStatus ['status ' ]).' </> ' .$ fullStatus ['message ' ]);
66- info (' ' .$ updateBadge .'UPDATE </> ' .($ isInSync ? 'All packages are in sync with composer.json ' : 'You need to run `php artisan devlink:link` to update the packages ' ));
67- info (' ' );
68- }
81+ info (' ' .$ icon .$ badge .strtoupper ($ fullStatus ['status ' ]).' </> ' .$ fullStatus ['message ' ]);
82+ info (' ' .$ updateIcon .$ updateBadge .'UPDATE </> ' .($ isInSync ? 'All packages are in sync with composer.json ' : 'You need to run `php artisan devlink:link` to update the packages ' ));
6983
70- private function getInstalledVersion (string $ name , array $ package ): ?string
71- {
72- $ packageName = $ this ->getPackageName ($ name , $ package );
73- if (! $ packageName ) {
74- return null ;
75- }
76-
77- $ path = $ package ['path ' ] ?? '' ;
78- if ($ path && ! str_contains ($ path , 'disabled/ ' )) {
79- $ composerJson = realpath (base_path ($ path )).'/composer.json ' ;
80- if (file_exists ($ composerJson )) {
81- $ composerData = json_decode (file_get_contents ($ composerJson ), true );
82-
83- return $ composerData ['version ' ] ?? 'dev-main ' ;
84- }
85- }
86-
87- $ composerLock = base_path ('composer.lock ' );
88- if (! file_exists ($ composerLock )) {
89- return null ;
90- }
84+ if (! $ isInSync && $ this ->getOutput ()->isVerbose ()) {
85+ info (' ' );
86+ info ('Detailed sync status: ' );
9187
92- $ lockData = json_decode (file_get_contents ($ composerLock ), true );
93- if (json_last_error () !== JSON_ERROR_NONE ) {
94- info ("Invalid composer.lock JSON for $ name " );
95-
96- return null ;
97- }
98-
99- foreach ([$ lockData ['packages ' ] ?? [], $ lockData ['packages-dev ' ] ?? []] as $ packages ) {
100- foreach ($ packages as $ pkg ) {
101- if (($ pkg ['name ' ] ?? '' ) === $ packageName ) {
102- return $ pkg ['version ' ] ?? null ;
88+ foreach ($ fullStatus ['packages ' ] as $ package ) {
89+ $ packageName = $ this ->getPackageName ($ package ['name ' ], $ package ['config ' ]);
90+ if (! $ packageName ) {
91+ continue ;
10392 }
104- }
105- }
106-
107- return null ;
108- }
109-
110- private function getShortPath (array $ row ): string
111- {
112- if (($ row ['type ' ] ?? '' ) === 'local ' ) {
113- return '- ' ;
114- }
115-
116- $ privateBasePath = config ('devlink.private_base_path ' );
117- if (($ row ['type ' ] ?? '' ) === 'private ' && $ privateBasePath === 'disabled ' ) {
118- return '- enable private path in config - ' ;
119- }
120-
121- $ path = $ this ->packages [$ row ['name ' ]]['path ' ] ?? '' ;
122- if (empty ($ path )) {
123- return '- ' ;
124- }
12593
126- if (str_starts_with ($ path , '../ ' )) {
127- return $ path ;
128- }
129-
130- $ basePath = base_path ();
131- if (str_starts_with ($ path , $ basePath )) {
132- return substr ($ path , strlen ($ basePath ) + 1 );
133- }
134-
135- return $ path ;
136- }
137-
138- private function getPackageName (string $ name , array $ package ): ?string
139- {
140- $ isLocal = ($ package ['type ' ] ?? '' ) === 'local ' ;
141- $ path = $ isLocal ? "packages/ $ name " : ($ package ['path ' ] ?? '' );
142-
143- if (! $ path || str_contains ($ path , 'disabled/ ' )) {
144- return null ;
145- }
146-
147- if (str_starts_with ($ path , '../ ' )) {
148- $ path = realpath (base_path ($ path ));
149- }
150-
151- $ composerJson = "$ path/composer.json " ;
152- if (! file_exists ($ composerJson )) {
153- return null ;
154- }
155-
156- $ data = json_decode (file_get_contents ($ composerJson ), true );
157-
158- return $ data ['name ' ] ?? null ;
159- }
160-
161- private function arePackagesInSync (array $ packages ): bool
162- {
163- $ composerJson = base_path ('composer.json ' );
164- if (! file_exists ($ composerJson )) {
165- return false ;
166- }
167-
168- $ composerData = json_decode (file_get_contents ($ composerJson ), true );
169- if (! $ composerData ) {
170- return false ;
171- }
172-
173- $ composerRequire = array_merge (
174- $ composerData ['require ' ] ?? [],
175- $ composerData ['require-dev ' ] ?? []
176- );
94+ $ expectedPath = $ package ['config ' ]['path ' ] ?? '' ;
95+ if (empty ($ expectedPath )) {
96+ continue ;
97+ }
17798
178- foreach ( $ packages as $ package ) {
179- $ packageName = $ this -> getPackageName ( $ package [ ' name ' ], $ package [ ' config ' ]);
180- if (! $ packageName ) {
181- continue ;
182- }
99+ $ composerJson = json_decode ( file_get_contents ( $ this -> composerJsonPath ), true );
100+ $ composerRequire = array_merge (
101+ $ composerJson [ ' require ' ] ?? [],
102+ $ composerJson [ ' require-dev ' ] ?? []
103+ );
183104
184- $ expectedPath = $ package ['config ' ]['path ' ] ?? '' ;
185- if (empty ($ expectedPath )) {
186- continue ;
187- }
105+ if (! isset ($ composerRequire [$ packageName ])) {
106+ info (" <fg=red>✘</> {$ packageName }: Not found in composer.json requirements " );
188107
189- if (! isset ($ composerRequire [$ packageName ])) {
190- return false ;
191- }
108+ continue ;
109+ }
192110
193- $ composerPath = $ composerRequire [$ packageName ];
194- if (str_contains ($ composerPath , 'path: ' )) {
195- $ composerPath = trim (str_replace ('path: ' , '' , $ composerPath ));
196- if ($ composerPath !== $ expectedPath ) {
197- return false ;
111+ $ composerPath = $ composerRequire [$ packageName ];
112+ if (str_contains ($ composerPath , 'path: ' )) {
113+ $ composerPath = trim (str_replace ('path: ' , '' , $ composerPath ));
114+ if ($ composerPath !== $ expectedPath ) {
115+ info (" <fg=red>✘</> {$ packageName }: Path mismatch " );
116+ info (" Expected: {$ expectedPath }" );
117+ info (" Found: {$ composerPath }" );
118+ } else {
119+ info (" <fg=green>✓</> {$ packageName }: Correctly linked " );
120+ }
198121 }
199122 }
200123 }
201124
202- return true ;
125+ info ( ' ' ) ;
203126 }
204127}
0 commit comments