2016-12-05 13:42:38 +00:00
|
|
|
<?php if( !defined('__ROOT__') ) define('__ROOT__', dirname(dirname(__FILE__)) );
|
|
|
|
|
|
|
|
|
|
|
|
class Builder{
|
|
|
|
|
|
|
|
|
|
|
|
private static function src(){ return __ROOT__.'/src'; }
|
2016-12-05 18:54:19 +00:00
|
|
|
private $packages = null;
|
2016-12-05 13:42:38 +00:00
|
|
|
private $root = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* BUILDS A BUILDER WITH SPECIFIC LOCATION AND CONFIG
|
|
|
|
*
|
|
|
|
* @pRoot<String> Path to project root
|
2016-12-05 18:54:19 +00:00
|
|
|
* @pPackages<Array> Packages to load
|
2016-12-05 13:42:38 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-12-05 18:54:19 +00:00
|
|
|
public function __construct($pRoot, $pPackages){
|
2016-12-05 13:42:38 +00:00
|
|
|
/* [1] Stores the path
|
|
|
|
=========================================================*/
|
|
|
|
$this->root = $pRoot;
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* [2] Stores the packages
|
2016-12-05 13:42:38 +00:00
|
|
|
=========================================================*/
|
2016-12-05 18:54:19 +00:00
|
|
|
$this->packages = $pPackages;
|
2016-12-05 13:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function build(){
|
|
|
|
|
|
|
|
/* [1] Builds project's base file structure
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Copy from src/files */
|
2016-12-07 11:51:13 +00:00
|
|
|
echo "(1) Building file structure\n";
|
2016-12-05 13:42:38 +00:00
|
|
|
shell_exec("cp -r ".__ROOT__."/src/files/* ".$this->root);
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* [2] Browse each package to load
|
2016-12-05 13:42:38 +00:00
|
|
|
=========================================================*/
|
2016-12-07 11:51:13 +00:00
|
|
|
echo "(2) Building packages\n";
|
|
|
|
$count = 1;
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
foreach($this->packages as $package=>$version){
|
2016-12-07 11:51:13 +00:00
|
|
|
$path = "$package/$version";
|
2016-12-05 13:42:38 +00:00
|
|
|
|
2016-12-07 11:51:13 +00:00
|
|
|
echo " ($count) $package:$version\n";
|
2016-12-05 18:54:19 +00:00
|
|
|
/* (1) Copy package folder if it exists */
|
2016-12-07 11:51:13 +00:00
|
|
|
if( file_exists(__ROOT__."/src/packages/$path") && is_dir(__ROOT__."/src/packages/$path") && count(scandir(__ROOT__."/src/packages/$path")) > 2 )
|
|
|
|
shell_exec("cp -r ".__ROOT__."/src/packages/$path ".$this->root."/build/$package");
|
2016-12-05 13:42:38 +00:00
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* (2) Copy package config if it exists */
|
2016-12-07 11:51:13 +00:00
|
|
|
if( file_exists(__ROOT__."/src/config/$path") && is_dir(__ROOT__."/src/config/$path") && count(scandir(__ROOT__."/src/config/$path")) > 2 )
|
|
|
|
shell_exec("cp -r ".__ROOT__."/src/config/$path/* ".$this->root."/config/");
|
2016-12-05 13:42:38 +00:00
|
|
|
|
2016-12-07 11:51:13 +00:00
|
|
|
$count++;
|
2016-12-05 13:42:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 11:51:13 +00:00
|
|
|
echo "(*) Build finished\n";
|
|
|
|
|
|
|
|
/* [3] Start stats
|
|
|
|
=========================================================*/
|
|
|
|
echo "\n\nStatistics:\n";
|
|
|
|
echo shell_exec("du -hs ".$this->root."/*;");
|
|
|
|
echo "--\n";
|
|
|
|
echo shell_exec("du -hs ".$this->root."/;");
|
|
|
|
|
2016-12-05 13:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|