-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorageLinkCommand.js
More file actions
55 lines (43 loc) Β· 1.57 KB
/
storageLinkCommand.js
File metadata and controls
55 lines (43 loc) Β· 1.57 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
const Command = require('@ostro/console/command')
class StorageLinkCommand extends Command {
$signature = 'storage:link';
$description = 'Create the symbolic links configured for the application';
$options = [
this.createOption('--relative', 'The host address to serve the application on'),
this.createOption('--force', 'The port to serve the application on')
];
constructor($file) {
super()
this.$file = $file
}
async handle() {
let $relative = this.option('relative');
let links = this.links()
for (let $link in links) {
let $target = links[$link]
if (await this.$file.exists($link) && !await this.isRemovableSymlink($link, this.option('force'))) {
this.error(`The [${$link}] link already exists.`);
continue;
}
if (await isSymbolicLink($link)) {
await this.$file.delete($link);
}
if ($relative) {
await this.$file.relativeLink($target, $link);
} else {
await this.$file.link($target, $link);
}
this.info(`The [${$link}] link has been connected to [${$target}].`);
}
this.info('The links have been created.');
}
links() {
return this.$app['config']['filesystems.links'] || {
[public_path('storage')]: storage_path('app/public')
};
}
isRemovableSymlink($link, $force) {
return isSymbolicLink($link) && $force;
}
}
module.exports = StorageLinkCommand