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