-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboFile.php
262 lines (222 loc) · 9.17 KB
/
RoboFile.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
/**
* Robo tasks - webtrees GeneaJaubart
*
* @see http://robo.li/
* phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
declare(strict_types=1);
use Robo\Result;
use Symfony\Component\Finder\Finder;
class RoboFile extends \Robo\Tasks
{
/**
* Build and copy the application languages.
*
* @param string $target_dir Directory to which languages must be copied
* @param string $base_dir Base directory of the application
* @throws \Exception
* @return \Robo\Result<mixed>
*/
public function buildLanguages(string $target_dir, string $base_dir = __DIR__): Result
{
$this->taskExec('composer webtrees:lang')->progressMessage("Copying languages")->run();
$languages_build = $this->taskFilesystemStack();
$languages_dir = 'resources/lang';
$base_languages_dir = "$base_dir/$languages_dir";
$languages = Finder::create()->directories()->in($base_languages_dir)->depth(0);
foreach ($languages as $language_dir) {
$language_target_dir = "$target_dir/$languages_dir/{$language_dir->getFilename()}";
$languages_build->mkdir($language_target_dir);
$languages_build->copy("$language_dir/messages.php", "$language_target_dir/messages.php");
}
return $languages_build->progressMessage("Copying languages")->run();
}
/**
* Build the application modules ready for use.
*
* @param string $base_dir Base directory of the application
* @throws \Exception
* @return \Robo\Result<mixed>
*/
public function buildModules(string $base_dir = __DIR__, bool $delete = false): Result
{
$collection = $this->collectionBuilder();
$modules_dir = $base_dir . '/modules_v4';
$modules = Finder::create()->directories()->name('myartjaub_*')->in($modules_dir)->depth(0);
foreach ($modules as $module) {
$collection->progressMessage("Building module {$module->getRelativePathname()}");
$module_dir = $modules_dir . '/' . $module->getRelativePathname();
if (
Finder::create()->name('package-lock.json')->in($module_dir)->depth(0)->count() > 0
&& Finder::create()->name('composer.json')->in($module_dir)->depth(0)->count() === 0
) {
$collection->taskExec("npm install --no-fund")
->dir($module_dir);
$collection->taskExecStack()
->dir($module_dir)
->stopOnFail()
->exec('npm run production');
}
if ($delete) {
$collection->taskFilesystemStack()
->remove($module_dir . '/node_modules');
}
}
return $collection
->progressMessage("Application built.")
->run();
}
/**
* Clean the application folder by removing development files.
*
* @param string $base_dir Base directory of the application
* @throws \Exception
* @return \Robo\Result<mixed>
*/
public function clean(string $base_dir = __DIR__): Result
{
$collection = $this->collectionBuilder();
$modules_dir = $base_dir . '/modules_v4';
$modules = Finder::create()->directories()->name('myartjaub_*')->in($modules_dir)->depth(0);
foreach ($modules as $module) {
$collection->progressMessage("Starting deleting development folders for {$module->getRelativePathname()}");
$module_dir = $modules_dir . '/' . $module->getRelativePathname();
$collection->taskFilesystemStack()
->remove($module_dir . '/src')
->remove($module_dir . '/node_modules')
->remove($module_dir . '/vendor');
}
$filesToDelete = Finder::create()
->in($base_dir)
->files()
->notPath('vendor')
->name(['composer*.*', 'package*.*', 'webpack*.*']);
$collection
->progressMessage("Starting deleting development files")
->taskFilesystemStack()
->remove($filesToDelete);
return $collection
->progressMessage('Repository cleaning done.')
->run();
}
/**
* Run the Semistandard Javascript Linter on MyArtJaub modules
*
* @throws \Exception
* @return \Robo\Result<mixed>
*/
public function lintSemistandard(): Result
{
$collection = $this->collectionBuilder();
$modules_dir = __DIR__ . '/modules_v4';
$modules = Finder::create()->directories()->name('myartjaub_*')->in($modules_dir)->depth(0);
foreach ($modules as $module) {
$module_dir = $modules_dir . '/' . $module->getRelativePathname();
if (
Finder::create()->name('package-lock.json')->in($module_dir)->depth(0)->count() > 0
&& Finder::create()->name('composer.json')->in($module_dir)->depth(0)->count() === 0
) {
$collection->taskExecStack()
->dir($module_dir)
->stopOnFail()
->exec('npx semistandard');
}
}
return $collection->run();
}
/**
* Update NPM dependencies on MyArtJaub modules
*
*
* @throws \Exception
* @return \Robo\Result<mixed>
*/
public function updateNpmModules()
{
$collection = $this->collectionBuilder();
$modules_dir = __DIR__ . '/modules_v4';
$modules = Finder::create()->directories()->name('myartjaub_*')->in($modules_dir)->depth(0);
foreach ($modules as $module) {
$module_dir = $modules_dir . '/' . $module->getRelativePathname();
if (
Finder::create()->name('package-lock.json')->in($module_dir)->depth(0)->count() > 0
&& Finder::create()->name('composer.json')->in($module_dir)->depth(0)->count() === 0
) {
$collection->taskExec("npm update")
->dir($module_dir);
$collection->taskExec("npm outdated || exit 0")
->printOutput(true)
->dir($module_dir);
}
}
return $collection
->progressMessage("NPM Packages updated.")
->run();
}
/**
* Package the specific commitish in a zip file for distribution.
* Commitish can be a commit hash, a tag, or a branch.
*
* @param string $version Package version
* @param string $commit Commitish to be packaged
* @throws \Exception
* @return \Robo\Result<mixed>
*/
public function package(string $version, string $commit = 'main'): Result
{
$getCommitResult =
$this->taskExec("git rev-parse --quiet --verify $commit")
->interactive(false)
->run();
if (!$getCommitResult->wasSuccessful() || $getCommitResult->getMessage() === '') {
throw new \Exception('The commit requested does not exist');
}
$collection = $this->collectionBuilder();
// Define paths and variables
$workDir = $collection->workDir("build/release.tmp");
$PROJECT_NAME = 'webtrees-geneajaubart';
$output_name = "webtrees-$version";
$build_archive_dir = "$workDir/$output_name.build";
$build_archive_zip = "$build_archive_dir.zip";
$build_release_path = "build/$output_name.zip";
// Extract webtrees archive and build
$this->taskFilesystemStack()
->mkdir($workDir)
->progressMessage("Starting build of $PROJECT_NAME $commit")
->progressMessage("Export git archive at commit $commit")
->taskExec("git archive --format=zip --output=$build_archive_zip $commit")
->taskExtract($build_archive_zip)
->to($build_archive_dir)
->taskComposerInstall()
->dir($build_archive_dir)
->noDev()
->preferDist()
->optimizeAutoloader()
->progressMessage("Extraction of $PROJECT_NAME $commit completed!")
->run();
// Build and copy webtrees languages
$this->buildLanguages($build_archive_dir);
// Build MyArtJaub modules
$this->buildModules($build_archive_dir, true);
$collection->progressMessage("Build of $PROJECT_NAME $commit completed!");
$this->clean($build_archive_dir);
$filesToCompress = Finder::create()
->in($build_archive_dir)
->depth(0); // do not recurse, the Pack task already does it.
$collection
->progressMessage("Starting packaging of $PROJECT_NAME $commit")
->taskPack($build_release_path);
$nbCompressedFiles = 0;
foreach ($filesToCompress as $file) {
$collection->addFile($file->getRelativePathname(), $file->getRealPath());
$nbCompressedFiles++;
}
return $collection
->progressMessage("Added $nbCompressedFiles items to archive.")
->progressMessage("Deleting work directory...")
->taskDeleteDir($workDir)
->progressMessage("Package created: $build_release_path !!!")
->run();
}
}