| 1 | <?php |
||
| 2 | |||
| 3 | namespace Maristela\Cli; |
||
| 4 | |||
| 5 | use Composer\Script\Event; |
||
| 6 | use Maristela\Cli\FileHandle; |
||
| 7 | use Maristela\Cli\Processor\Classic as Processor; |
||
| 8 | |||
| 9 | class App |
||
| 10 | { |
||
| 11 | public static function buildComponents(Event $event) |
||
| 12 | { |
||
| 13 | $config = self::getConfigurations($event); |
||
| 14 | |||
| 15 | $fileHandle = new FileHandle(); |
||
| 16 | $processor = new Processor($fileHandle); |
||
| 17 | |||
| 18 | $files = glob("{$config['componentsDir']}/**/index.php"); |
||
| 19 | |||
| 20 | foreach ($files as $file) { |
||
| 21 | $fileHandle->write( |
||
| 22 | $file, |
||
| 23 | $processor->compile($file), |
||
| 24 | "{$config['componentsDir']}/_static" |
||
| 25 | ); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | private static function getConfigurations(Event $event) |
||
| 30 | { |
||
| 31 | $baseDir = $event->getComposer()->getConfig()->get('vendor-dir') . '/../'; |
||
| 32 | |||
| 33 | $defaults = [ |
||
| 34 | 'componentsDir' => $baseDir . 'components/', |
||
| 35 | ]; |
||
| 36 | |||
| 37 | $file = $baseDir . '.maristela-cli.json'; |
||
| 38 | |||
| 39 | if (!file_exists($file)) { |
||
| 40 | return $defaults; |
||
| 41 | } |
||
| 42 | |||
| 43 | $config = json_decode(file_get_contents($file), true); |
||
| 44 | |||
| 45 | if (empty($config['componentsDir'])) { |
||
| 46 | throw new Exception('The "componentsDir" is not defined on config file.'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 47 | } |
||
| 48 | |||
| 49 | $config['componentsDir'] = "{$baseDir}{$config['componentsDir']}"; |
||
| 50 | |||
| 51 | return array_merge($defaults, $config); |
||
| 52 | } |
||
| 53 | } |
||
| 54 |