-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
185 lines (163 loc) · 4.55 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
<?php
use Globalis\Robo\Core\Command;
class RoboFile extends \Globalis\Robo\Tasks
{
private $configDirectory = __DIR__ . '/.robo/config/';
private $buildDirectories = [
'back' => __DIR__ . '/.robo/build/back',
'front' => __DIR__ . '/.robo/build/front',
];
private $backAppPath = __DIR__ . '/contact_book_back';
private $frontAppPath = __DIR__ . '/contact_book_front';
/**
* Install App
*/
public function install()
{
$this->loadConfig();
$this->buildBackApp();
$this->buildFrontApp();
$this->installBackDependencies();
$this->installFrontDependencies();
}
/**
* Configure App
*/
public function config()
{
$this->configVariables = $this->taskConfiguration()
->initConfig($this->getProperties('config'))
->configFilePath($this->configDirectory . 'my.config')
->force(true)
->run()
->getData();
$this->install();
}
/**
* Start watching on asset and source files
*/
public function watch()
{
$this->loadConfig();
$this->taskExec($this->configVariables['NPM_PATH'].' run watch')
->dir($this->frontAppPath)
->run();
}
/**
* Create migration
*
* @param string $name Migration name (CamelCase)
*/
public function migrateCreate($name)
{
$name = explode(' ', str_replace(['_', '-'], ' ', $name));
foreach ($name as &$word) {
$word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1);
}
$name = implode('', $name);
$this->taskExec('vendor/bin/phinx')
->dir($this->backAppPath)
->arg('create')
->arg($name)
->run();
}
/**
* Database migrate
*/
public function migrateUp()
{
$this->taskExec('vendor/bin/phinx')
->dir($this->backAppPath)
->arg('migrate')
->run();
}
/**
* Migration rollback
*/
public function migrateDown()
{
$this->taskExec('vendor/bin/phinx')
->dir($this->backAppPath)
->arg('rollback')
->run();
}
/**
* Create seed file
*
* @param string $name Seed name (CamelCase)
*/
public function seedCreate($name)
{
$this->taskExec('vendor/bin/phinx')
->dir($this->backAppPath)
->arg('seed:create')
->arg($name)
->run();
}
/**
* Run seeds
*
* @param string $name Seed name (CamelCase)
*/
public function seedRun($name = null)
{
$task = $this->taskExec('vendor/bin/phinx')
->dir($this->backAppPath)
->arg('seed:run');
if ($name) {
$task->option('-s ' . $name);
}
$task->run();
}
private function buildBackApp()
{
$this->taskCopyReplaceDir([$this->buildDirectories['back'] => $this->backAppPath])
->from(array_keys($this->configVariables))
->to($this->configVariables)
->startDelimiter('<##')
->endDelimiter('##>')
->dirPermissions(0755)
->filePermissions(0644)
->run();
$this->migrateUp();
}
private function buildFrontApp()
{
$this->taskCopyReplaceDir([$this->buildDirectories['front'] => $this->frontAppPath])
->from(array_keys($this->configVariables))
->to($this->configVariables)
->startDelimiter('<##')
->endDelimiter('##>')
->dirPermissions(0755)
->filePermissions(0644)
->run();
}
private function installBackDependencies()
{
$this->taskComposerInstall()
->workingDir($this->backAppPath)
->preferDist()
->run();
}
private function installFrontDependencies()
{
$this->taskNpmInstall($this->configVariables['NPM_PATH'])
->dir($this->frontAppPath)
->run();
}
private function loadConfig()
{
$this->configVariables = $this->taskConfiguration()
->initConfig($this->getProperties('config'))
->configFilePath($this->configDirectory . 'my.config')
->run()
->getData();
}
private function getProperties($type)
{
if (!isset($this->properties)) {
$this->properties = include $this->configDirectory . 'properties.php';
}
return $this->properties[$type];
}
}