|
1
|
|
|
<?php |
|
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Deployer\Component\Initializer; |
|
9
|
|
|
|
|
10
|
|
|
class Initializer |
|
11
|
|
|
{ |
|
12
|
|
|
public function getRecipes() |
|
13
|
|
|
{ |
|
14
|
|
|
$recipes = []; |
|
15
|
|
|
$dir = new \DirectoryIterator(DEPLOYER_INCLUDE_PATH . '/recipe'); |
|
16
|
|
|
foreach ($dir as $fileinfo) { |
|
17
|
|
|
if ($fileinfo->isDot()) { |
|
18
|
|
|
continue; |
|
19
|
|
|
} |
|
20
|
|
|
if ($fileinfo->isDir()) { |
|
21
|
|
|
continue; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$recipe = pathinfo($fileinfo->getFilename(), PATHINFO_FILENAME); |
|
25
|
|
|
|
|
26
|
|
|
if ($recipe === 'README') { |
|
27
|
|
|
continue; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$recipes[] = $recipe; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
sort($recipes); |
|
34
|
|
|
return $recipes; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getTemplate(string $template, string $project, string $repository, array $hosts, bool $allow): string |
|
38
|
|
|
{ |
|
39
|
|
|
$h = ""; |
|
40
|
|
|
foreach ($hosts as $host) { |
|
41
|
|
|
$h .= "host('{$host}');\n"; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$dontTrack = $allow ? '' : "define('DONT_TRACK', 'ಠ_ಠ');\n"; |
|
45
|
|
|
|
|
46
|
|
|
return <<<PHP |
|
47
|
|
|
<?php |
|
48
|
|
|
namespace Deployer; |
|
49
|
|
|
{$dontTrack} |
|
50
|
|
|
require 'recipe/$template.php'; |
|
51
|
|
|
|
|
52
|
|
|
// Config |
|
53
|
|
|
|
|
54
|
|
|
set('application', '{$project}'); |
|
55
|
|
|
set('deploy_path', '~/{{application}}'); |
|
56
|
|
|
set('repository', '{$repository}'); |
|
57
|
|
|
|
|
58
|
|
|
add('shared_files', []); |
|
59
|
|
|
add('shared_dirs', []); |
|
60
|
|
|
add('writable_dirs', []); |
|
61
|
|
|
|
|
62
|
|
|
// Hosts |
|
63
|
|
|
|
|
64
|
|
|
{$h} |
|
65
|
|
|
|
|
66
|
|
|
// Tasks |
|
67
|
|
|
|
|
68
|
|
|
task('build', function () { |
|
69
|
|
|
run('cd {{release_path}} && npm run build'); |
|
70
|
|
|
}); |
|
71
|
|
|
|
|
72
|
|
|
task('build:upload', function () { |
|
73
|
|
|
upload('dist', '{{release_path}}/dist'); |
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
// If deploy fails automatically unlock. |
|
77
|
|
|
after('deploy:failed', 'deploy:unlock'); |
|
78
|
|
|
|
|
79
|
|
|
PHP; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|