LinkCommand.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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';
  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. * @return void
  28. */
  29. protected function linkTests($files)
  30. {
  31. if (! is_file(base_path('phpunit.dusk.xml'))) {
  32. $files->copy(realpath(__DIR__.'/../../../phpunit.dusk.xml'), base_path('phpunit.dusk.xml'));
  33. }
  34. $target = base_path('tests');
  35. $testsPath = realpath(__DIR__.'/../../../tests');
  36. if (is_dir($target)) {
  37. $result = $this->ask("The [{$target}] directory already exists, are you sure to delete it? [yes/no]");
  38. if (strtolower($result) !== 'yes') {
  39. return;
  40. }
  41. $files->deleteDirectory($target);
  42. }
  43. $files->link(
  44. $testsPath, $target
  45. );
  46. $this->info("The [$testsPath] directory has been linked.");
  47. }
  48. /**
  49. * @param Filesystem $files
  50. * @return void
  51. */
  52. protected function linkAssets($files)
  53. {
  54. $basePath = Admin::asset()->getRealPath('@admin');
  55. $publicPath = public_path($basePath);
  56. if (! is_dir($publicPath.'/..')) {
  57. $files->makeDirectory($publicPath.'/..', 0755, true, true);
  58. }
  59. if (file_exists($publicPath)) {
  60. $this->warn("The [public/{$basePath}] directory already exists.");
  61. return;
  62. }
  63. $distPath = realpath(__DIR__.'/../../../resources/pre-dist');
  64. $files->link(
  65. $distPath, $publicPath
  66. );
  67. $this->info("The [$basePath] directory has been linked.");
  68. }
  69. }