area17 / twill

Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/cnWk7EFv8R.
https://twillcms.com
Apache License 2.0
3.78k stars 574 forks source link

Running twill:build when using a custom icon leads to an ErrorException caused by copy function because of missing target directory #2391

Closed emanueljacob closed 10 months ago

emanueljacob commented 10 months ago

Description

Running php artisan twill:build with having at least one custom-icon leads to an ErrorException.

This happens because twill is trying to copy the custom icon from its application specific location resources/views/twill/icons to the package specific location vendor/area17/twill/frontend/icons-custom using the PHP build-in copy function. However due to the fact that the directory vendor/area17/twill/frontend/icons-custom does not exist, the error occures.

The package does this in \A17\Twill\Commands\Build::copyIcons.

In Twill 2.x there was a checkto create the directory if it does not exist. Unfortunately this check has been removed in version 3.x

Twill 3.x: (copyIcons) https://github.com/area17/twill/blob/5bddccfb4c4a30afcd704a7e2b1a97026b0c14b0/src/Commands/Build.php#L235 Twill 2.x (copyIcons with prior check): https://github.com/area17/twill/blob/a068e1b13c8a7c005bf61d1b57871f941018fc2f/src/Commands/Build.php#L228

Steps to reproduce

  1. add a demo svg file named example.svg in the application specific directory resources/views/twill/icons
  2. run php artisan twill:build

you may also dump (or add a breakpoint) in the method \A17\Twill\Commands\Build::copyIcons to allow showing source and target paths (considering the fact that you have a custom icon that should be copied, see 1.) and you run twill:build, see 2.))

Expected result

the icon can be moved to the targetDirectory correctly.

Actual result

An ErrorException is being thrown.

 ErrorException 

  copy({YOURPATH}/vendor/area17/twill/frontend/icons-custom/{YOURCUSTOMSVGICONNAME}.svg): Failed to open stream: No such file or directory

Versions

Twill version: 3.0.2 Laravel version: 10.39 PHP version: 8.2 Database engine: mysql