forked from laravel/valet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalet.php
executable file
·220 lines (173 loc) · 4.64 KB
/
valet.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env php
<?php
/**
* Load correct autoloader depending on install location.
*/
if (file_exists(__DIR__.'/vendor/autoload.php')) {
require __DIR__.'/vendor/autoload.php';
} else {
require __DIR__.'/../../autoload.php';
}
use Silly\Application;
use Valet\Facades\Brew;
use Valet\Facades\Site;
use Valet\Facades\Caddy;
use Valet\Facades\Ngrok;
use Valet\Facades\PhpFpm;
use Valet\Facades\DnsMasq;
use Valet\Facades\Filesystem;
use Valet\Facades\CommandLine;
use Valet\Facades\Configuration;
use Illuminate\Container\Container;
/**
* Create the application.
*/
Container::setInstance(new Container);
$app = new Application('Laravel Valet', 'v1.1.3');
/**
* Prune missing directories and symbolic links on every command.
*/
if (is_dir(VALET_HOME_PATH)) {
Configuration::prune();
Site::pruneLinks();
}
/**
* Allow Valet to be run more conveniently by allowing the Node proxy to run password-less sudo.
*/
$app->command('install', function () {
Caddy::stop();
Configuration::install();
Caddy::install();
PhpFpm::install();
DnsMasq::install();
Caddy::restart();
output(PHP_EOL.'<info>Valet installed successfully!</info>');
});
/**
* Change the domain currently being used by Valet.
*/
$app->command('domain domain', function ($domain) {
DnsMasq::updateDomain(
Configuration::read()['domain'], $domain = trim($domain, '.')
);
Configuration::updateKey('domain', $domain);
info('Your Valet domain has been updated to ['.$domain.'].');
});
/**
* Get the domain currently being used by Valet.
*/
$app->command('current-domain', function () {
info(Configuration::read()['domain']);
});
/**
* Add the current working directory to the paths configuration.
*/
$app->command('park', function () {
Configuration::addPath(getcwd());
info("This directory has been added to Valet's paths.");
});
/**
* Remove the current working directory to the paths configuration.
*/
$app->command('forget', function () {
Configuration::removePath(getcwd());
info("This directory has been removed from Valet's paths.");
});
/**
* Register a symbolic link with Valet.
*/
$app->command('link [name]', function ($name) {
$linkPath = Site::link(getcwd(), $name = $name ?: basename(getcwd()));
info('A ['.$name.'] symbolic link has been created in ['.$linkPath.'].');
});
/**
* Display all of the registered symbolic links.
*/
$app->command('links', function () {
passthru('ls -la '.VALET_HOME_PATH.'/Sites');
});
/**
* Unlink a link from the Valet links directory.
*/
$app->command('unlink [name]', function ($name) {
Site::unlink($name ?: basename(getcwd()));
info('The ['.$name.'] symbolic link has been removed.');
});
/**
* Determine which Valet driver the current directory is using.
*/
$app->command('which', function () {
require __DIR__.'/drivers/require.php';
$driver = ValetDriver::assign(getcwd(), basename(getcwd()), '/');
if ($driver) {
info('This site is served by ['.get_class($driver).'].');
} else {
output('<fg=red>Valet could not determine which driver to use for this site.</>');
}
});
/**
* Stream all of the logs for all sites.
*/
$app->command('logs', function () {
$files = Site::logs(Configuration::read()['paths']);
$files = collect($files)->transform(function ($file) {
return escapeshellarg($file);
})->all();
if (count($files) > 0) {
passthru('tail -f '.implode(' ', $files));
} else {
output('<fg=red>No log files were found.</>');
}
});
/**
* Display all of the registered paths.
*/
$app->command('paths', function () {
$paths = Configuration::read()['paths'];
if (count($paths) > 0) {
output(json_encode($paths, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
} else {
info('No paths have been registered.');
}
});
/**
* Echo the currently tunneled URL.
*/
$app->command('fetch-share-url', function () {
output(Ngrok::currentTunnelUrl());
});
/**
* Start the daemon services.
*/
$app->command('start', function () {
PhpFpm::restart();
Caddy::restart();
info('Valet services have been started.');
});
/**
* Restart the daemon services.
*/
$app->command('restart', function () {
PhpFpm::restart();
Caddy::restart();
info('Valet services have been restarted.');
});
/**
* Stop the daemon services.
*/
$app->command('stop', function () {
PhpFpm::stop();
Caddy::stop();
info('Valet services have been stopped.');
});
/**
* Uninstall Valet entirely.
*/
$app->command('uninstall', function () {
Caddy::uninstall();
info('Valet has been uninstalled.');
});
/**
* Run the application.
*/
$app->run();