LinkCommand.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Dcat\Admin\Console\Development;
  3. use Dcat\Admin\Admin;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Filesystem\Filesystem;
  6. class LinkCommand extends Command
  7. {
  8. /**
  9. * The console command signature.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'admin:dev:link';
  14. /**
  15. * Execute the console command.
  16. *
  17. * @return void
  18. */
  19. public function handle()
  20. {
  21. $files = $this->laravel->make('files');
  22. $this->linkAssets($files);
  23. $this->linkTests($files);
  24. }
  25. /**
  26. * @param Filesystem $files
  27. *
  28. * @return void
  29. */
  30. protected function linkTests($files)
  31. {
  32. if (! is_file(base_path('phpunit.dusk.xml'))) {
  33. $files->copy(realpath(__DIR__.'/../../../phpunit.dusk.xml'), base_path('phpunit.dusk.xml'));
  34. }
  35. $target = base_path('tests');
  36. $testsPath = realpath(__DIR__.'/../../../tests');
  37. if (is_dir($target)) {
  38. $result = $this->ask("The [{$target}] directory already exists, are you sure to delete it? [yes/no]");
  39. if (strtolower($result) !== 'yes') {
  40. return;
  41. }
  42. $files->deleteDirectory($target);
  43. }
  44. $files->link(
  45. $testsPath, $target
  46. );
  47. $this->info("The [$testsPath] directory has been linked.");
  48. }
  49. /**
  50. * @param Filesystem $files
  51. *
  52. * @return void
  53. */
  54. protected function linkAssets($files)
  55. {
  56. $basePath = Admin::asset()->getRealPath('@admin');
  57. $publicPath = public_path($basePath);
  58. if (! is_dir($publicPath.'/..')) {
  59. $files->makeDirectory($publicPath.'/..', 0755, true, true);
  60. }
  61. if (file_exists($publicPath)) {
  62. $this->warn("The [public/{$basePath}] directory already exists.");
  63. return;
  64. }
  65. $distPath = realpath(__DIR__.'/../../../resources/pre-dist');
  66. $files->link(
  67. $distPath, $publicPath
  68. );
  69. $this->info("The [$basePath] directory has been linked.");
  70. }
  71. }