-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPublishCommand.php
More file actions
138 lines (119 loc) · 3.17 KB
/
Copy pathPublishCommand.php
File metadata and controls
138 lines (119 loc) · 3.17 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php namespace Feather\Console;
use RuntimeException;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Illuminate\Foundation\AssetPublisher as Publisher;
class PublishCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'feather:publish';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Publish extension or theme assets';
/**
* Asset publisher instance.
*
* @var Illuminate\Foundation\AssetPublisher
*/
protected $publisher;
/**
* Path to themes
*
* @var string
*/
protected $themePath;
/**
* Path to extensions.
*
* @var string
*/
protected $extensionPath;
/**
* Create a new publish command instance.
*
* @param Illuminate\Foundation\AssetPublisher $publisher
* @param string $themePath
* @param string $extensionPath
* @return void
*/
public function __construct(Publisher $publisher, $themePath, $extensionPath)
{
parent::__construct();
$this->publisher = $publisher;
$this->themePath = $themePath;
$this->extensionPath = $extensionPath;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// The publish command encompasses both themes and extensions. Because of this a flag must be provided so that the
// publisher knows what's being published and where it is located.
if ( ! $this->input->getOption('theme') and ! $this->input->getOption('extension'))
{
$this->comment("Please use either the --theme or --extension flag.");
return;
}
$name = $this->input->getArgument('name');
// Using the AssetPublisher we can publish our themes or extensions to the correct destination within our public
// directory. If publishing fails we'll catch the exception and let the user no that they probably spelt the
// theme or extension incorrectly.
if ($this->input->getOption('theme'))
{
try
{
$this->publisher->publish("{$this->themePath}/{$name}/public", "../feather/themes/{$name}");
$this->line("<info>Successfully published theme:</info> {$name}");
}
catch (RuntimeException $error)
{
$this->comment('Failed to publish theme. There may be nothing to publish.');
}
}
elseif ($this->input->getOption('extension'))
{
try
{
$this->publisher->publish("{$this->extensionPath}/{$name}/public", "../feather/extensions/{$name}");
$this->line("<info>Successfully published extension:</info> {$name}");
}
catch (RuntimeException $error)
{
$this->comment('Failed to publish extension. There may be nothing to publish.');
}
}
}
/**
* Get the command arguments.
*
* @return array
*/
public function getArguments()
{
return array(
array('name', InputArgument::REQUIRED, 'Name of the theme or extension to publish')
);
}
/**
* Get the command options.
*
* @return array
*/
public function getOptions()
{
return array(
array('theme', null, InputOption::VALUE_NONE, 'Tells publisher to publish a theme'),
array('extension', null, InputOption::VALUE_NONE, 'Tells publisher to publish an extension'),
);
}
}