-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathRoboFile.php
74 lines (60 loc) · 2.46 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
<?php
use Symfony\Component\Finder\Finder;
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks {
protected function checkPharReadonly() {
if (ini_get('phar.readonly')) {
throw new \Exception('Must set "phar.readonly = Off" in php.ini to build phars.');
}
}
public function phar() {
$phar_file = 'bin/jwkstool.phar';
// 1. Check php config
$this->checkPharReadonly();
// 2. Set up robo collections and create temp directory
$main_collection = $this->collectionBuilder();
$prepare_collection = $this->collectionBuilder();
$temp = $main_collection->tmpDir();
// 3. Prepare step
// (a) Copy files to temp directory
$prepare_collection->taskMirrorDir([
'src' => "$temp/src",
'bin' => "$temp/bin",
'build' => "$temp/build"
]);
$prepare_collection->taskFilesystemStack()->copy('composer.json', "$temp/composer.json");
$prepare_collection->taskFilesystemStack()->copy('box.json', "$temp/box.json");
// (b) composer install
$prepare_collection->taskComposerInstall()->dir($temp)->noDev();
// (c) run
$result = $prepare_collection->run();
if (!$result->wasSuccessful()) {
return $result;
}
// 4. Run box to create phar
$box_command = str_replace('/', DIRECTORY_SEPARATOR, 'vendor-bin/build/vendor/bin/box');
$main_collection->taskExec($box_command)->arg('compile')->arg('-c')->arg("$temp/box.json");
$main_collection->taskFilesystemStack()->copy("$temp/bin/jwkstool.phar", 'bin/jwkstool.phar', true);
// 7. Run everything
return $main_collection->run();
}
public function update_copyright() {
$current_year = date('Y', time());
$finder = new Finder();
$finder->in(['src', 'bin'])->name('*.php')->append(['LICENSE.txt']);
foreach($finder as $file) {
$this->taskReplaceInFile($file)
->regex('/Copyright \(C\) Kelvin Mo (\d{4})-(\d{4})(\R)/m')
->to('Copyright (C) Kelvin Mo $1-'. $current_year . '$3')
->run();
$this->taskReplaceInFile($file)
->regex('/Copyright \(C\) Kelvin Mo (\d{4})(\R)/m')
->to('Copyright (C) Kelvin Mo $1-'. $current_year . '$2')
->run();
}
}
}