-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathPublishCommand.php
80 lines (69 loc) · 2.07 KB
/
PublishCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types = 1);
namespace Rebing\GraphQL\Console;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class PublishCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'graphql:publish {--force : Overwrite any existing files.}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Publishes GraphQL configuration file to config directory of app';
/**
* Filesystem instance for fs operations.
*
* @var Filesystem
*/
protected $files;
/**
* A list of files (source => destination).
*
* @var array<string,string>
*/
protected $fileMap = [];
public function __construct(Filesystem $files)
{
parent::__construct();
$this->files = $files;
$fromPath = __DIR__ . '/../..';
$this->fileMap = [
$fromPath . '/config/config.php' => app()->basePath('config/graphql.php'),
$fromPath . '/resources/views/graphiql.php' => app()->basePath('resources/views/vendor/graphql/graphiql.php'),
];
}
public function handle(): void
{
foreach ($this->fileMap as $from => $to) {
if ($this->files->exists($to) && !$this->option('force')) {
continue;
}
$this->createParentDirectory(\dirname($to));
$this->files->copy($from, $to);
$this->status($from, $to);
}
}
/**
* Create the directory to house the published files if needed.
*/
protected function createParentDirectory(string $directory): void
{
if (!$this->files->isDirectory($directory)) {
$this->files->makeDirectory($directory, 0755, true);
}
}
/**
* Write a status message to the console.
*/
protected function status(string $from, string $to): void
{
$this->line("<info>Copied File</info> <comment>[$from]</comment> <info>To</info> <comment>[$to]</comment>");
}
}