-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
159 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Author: garming | ||
* Date: 26/03/2018 | ||
* Time: 11:25 | ||
*/ | ||
|
||
namespace Tangram\AutoGenerator; | ||
|
||
|
||
class EnvMapGenerator extends BaseGenerator | ||
{ | ||
public function __construct() | ||
{ | ||
$this->fileName = "autobuild_env.php"; | ||
$this->config = []; | ||
} | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getConfig(): array | ||
{ | ||
return $this->config; | ||
} | ||
|
||
/** | ||
* @param array $config | ||
* | ||
* @return \Tangram\AutoGenerator\EnvMapGenerator | ||
*/ | ||
public function setConfig(array $config):EnvMapGenerator | ||
{ | ||
$this->config = array_merge($this->config,$config); | ||
return $this; | ||
} | ||
|
||
public function generate($absolutePathPerfix) | ||
{ | ||
$content = preg_replace('#,(\s+|)\)#', '$1)', var_export($this->config, true)); | ||
$this->write($absolutePathPerfix,$this->fileContent($content)); | ||
} | ||
private function fileContent($str){ | ||
return <<<"EOF" | ||
<?php | ||
function env(\$key = null){ | ||
static \$config = {$str}; | ||
if(empty(\$key)){ | ||
return \$config; | ||
} | ||
if(isset(\$config[\$key])){ | ||
return \$config[\$key]; | ||
} | ||
return null; | ||
} | ||
EOF; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: garming | ||
* Date: 11/01/2018 | ||
* Time: 01:07 | ||
*/ | ||
|
||
namespace Tangram\Command\Build; | ||
|
||
|
||
use Symfony\Component\Yaml\Yaml; | ||
use Tangram\AutoGenerator\EnvMapGenerator; | ||
use Tangram\Command\BaseCommandRun; | ||
use Tangram\Resourse\Applications; | ||
|
||
class EnvBuild extends BaseCommandRun | ||
{ | ||
public function exec($env = null){ | ||
if(empty($env)){ | ||
return; | ||
} | ||
/** @var \Tangram\Tangram $tangram */ | ||
$tangram = $this->getTangram(); | ||
|
||
$projectConfig = $tangram->getPorjectConfig(); | ||
|
||
//check env config exist | ||
$file = empty($projectConfig->getEnvPath()) ? $projectConfig->getAbsoluteEnvPath().$env : $projectConfig->getAbsoluteEnvPath().DIRECTORY_SEPARATOR.$env; | ||
if(!file_exists($file)){ | ||
$this->getIO()->writeError('<error>'.$projectConfig->getEnvPath().DIRECTORY_SEPARATOR.$env.' missing!!!</error>'); | ||
exit; | ||
} | ||
$envConfig = Yaml::parse(file_get_contents($file)); | ||
$applications = Applications::all(); | ||
|
||
$this->writeHeader('🌋️ ENV Build: '.$env); | ||
|
||
foreach ($applications as $application) { | ||
$generator = new EnvMapGenerator(); | ||
$this->writeHeader(" 💡".$generator->getFileName()." >> $application"); | ||
|
||
$generator->setConfig($envConfig) | ||
->generate($projectConfig->getAbsoluteApplicationPath() . DIRECTORY_SEPARATOR . $application); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters