1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Godbout\DashDocsetBuilder\Services; |
4
|
|
|
|
5
|
|
|
use Godbout\DashDocsetBuilder\Contracts\Docset; |
6
|
|
|
use Illuminate\Console\Command as LaravelCommand; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
use LaravelZero\Framework\Commands\Command; |
9
|
|
|
|
10
|
|
|
class DocsetBuilder |
11
|
|
|
{ |
12
|
|
|
protected $docset; |
13
|
|
|
|
14
|
|
|
protected $grabber; |
15
|
|
|
protected $packager; |
16
|
|
|
protected $archiver; |
17
|
|
|
|
18
|
|
|
protected $command; |
19
|
|
|
|
20
|
|
|
|
21
|
18 |
|
public function __construct(?Docset $docset = null, ?Command $command = null) |
22
|
|
|
{ |
23
|
18 |
|
$this->docset = $docset; |
24
|
18 |
|
$this->command = $command ?? new LaravelCommand(); |
25
|
|
|
|
26
|
18 |
|
$this->newer = new DocsetNewer($this->command->argument('doc')); |
|
|
|
|
27
|
|
|
|
28
|
18 |
|
if ($this->docset) { |
29
|
18 |
|
$this->grabber = new DocsetGrabber($this->docset); |
30
|
18 |
|
$this->packager = new DocsetPackager($this->docset); |
31
|
18 |
|
$this->archiver = new DocsetArchiver($this->docset); |
32
|
|
|
} |
33
|
18 |
|
} |
34
|
|
|
|
35
|
|
|
public function new() |
36
|
|
|
{ |
37
|
|
|
$class = Str::studly($this->command->argument('doc')); |
|
|
|
|
38
|
|
|
|
39
|
|
|
if (! $class) { |
40
|
|
|
return $this->command->task(' - Never gonna give you up. Generating the Rick Astley Docset class for you', function () { |
41
|
|
|
$this->newer->new(); |
42
|
|
|
}); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $this->command->task(" - Generating $class.php", function () { |
46
|
|
|
$this->newer->new(); |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
|
50
|
6 |
|
public function build() |
51
|
|
|
{ |
52
|
6 |
|
$this->grab(); |
53
|
6 |
|
$this->package(); |
54
|
6 |
|
$this->archive(); |
55
|
6 |
|
} |
56
|
|
|
|
57
|
6 |
|
public function grab() |
58
|
|
|
{ |
59
|
6 |
|
if (method_exists($this->docset, 'grab')) { |
60
|
|
|
return $this->grabFromDocset(); |
61
|
|
|
} |
62
|
|
|
|
63
|
6 |
|
if ($this->grabber->sitemapExists()) { |
64
|
|
|
return $this->grabFromSitemap(); |
65
|
|
|
} |
66
|
|
|
|
67
|
6 |
|
return $this->grabFromIndex(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function grabFromDocset() |
71
|
|
|
{ |
72
|
|
|
return $this->command->task(' - Downloading doc from docset custom instructions', function () { |
73
|
|
|
return $this->docset->grab(); |
|
|
|
|
74
|
|
|
}); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function grabFromSitemap() |
78
|
|
|
{ |
79
|
|
|
return $this->command->task(' - Downloading doc from sitemap', function () { |
80
|
|
|
return $this->grabber->grabFromSitemap(); |
81
|
|
|
}); |
82
|
|
|
} |
83
|
|
|
|
84
|
6 |
|
protected function grabFromIndex() |
85
|
|
|
{ |
86
|
|
|
return $this->command->task(' - Downloading doc from index', function () { |
87
|
6 |
|
return $this->grabber->grabFromIndex(); |
88
|
6 |
|
}); |
89
|
|
|
} |
90
|
|
|
|
91
|
12 |
|
public function package() |
92
|
|
|
{ |
93
|
|
|
$this->command->task(' - Remove previous .docset', function () { |
94
|
12 |
|
$this->packager->removePreviousDocsetFile(); |
95
|
12 |
|
}); |
96
|
|
|
|
97
|
|
|
$this->command->task(' - Create new .docset', function () { |
98
|
12 |
|
return $this->packager->createDocsetFile(); |
99
|
12 |
|
}); |
100
|
|
|
|
101
|
|
|
$this->command->task(' - Copy original doc files', function () { |
102
|
12 |
|
return $this->packager->copyDocFiles(); |
103
|
12 |
|
}); |
104
|
|
|
|
105
|
|
|
$this->command->task(' - Create Info.plist', function () { |
106
|
12 |
|
return $this->packager->createInfoPlist(); |
107
|
12 |
|
}); |
108
|
|
|
|
109
|
|
|
$this->command->task(' - Populate SQLiteIndex', function () { |
110
|
12 |
|
return $this->packager->createAndPopulateSQLiteIndex(); |
111
|
12 |
|
}); |
112
|
|
|
|
113
|
|
|
$this->command->task(' - Format doc files for Dash', function () { |
114
|
12 |
|
return $this->packager->formatDocFiles(); |
115
|
12 |
|
}); |
116
|
|
|
|
117
|
|
|
$this->command->task(' - Copy icons', function () { |
118
|
12 |
|
$this->packager->copyIcons(); |
119
|
12 |
|
}); |
120
|
12 |
|
} |
121
|
|
|
|
122
|
12 |
|
public function archive() |
123
|
|
|
{ |
124
|
|
|
$this->command->task(' - Archiving package', function () { |
125
|
12 |
|
return $this->archiver->archive(); |
126
|
12 |
|
}); |
127
|
12 |
|
} |
128
|
|
|
} |
129
|
|
|
|