Made build more smart

This commit is contained in:
Pierre 2018-04-29 21:34:37 +02:00
parent f6297b39fb
commit d67cd14640

59
build
View File

@ -8,6 +8,9 @@
<?php <?php
//Output directory
define("OUTPUT_DIRECTORY", __DIR__."/output/");
//Defines some utilities //Defines some utilities
/** /**
@ -97,15 +100,18 @@ function rcopy(string $src, string $dst) {
//Initialize page //Initialize page
require_once __DIR__."/system/system.php"; require_once __DIR__."/system/system.php";
//Get the build configuration
if(!isset($_SERVER['argv'][1])) /**
exit("Usage: ./build [configuration]"); * Build application
*/
function build() {
if(!isset($_SERVER['argv'][2]))
exit(notice("Usage: ./build build [configuration]", TRUE));
//Defines some variables //Defines some variables
$output = __DIR__."/output/";
$debug_conf = "dev"; $debug_conf = "dev";
$release_conf = $_SERVER['argv'][1]; $release_conf = $_SERVER['argv'][2];
//Load configurations //Load configurations
@ -119,16 +125,16 @@ $path_debug_assets = __DIR__."/".$debug::PATH_ASSETS;
load_config($release_conf); load_config($release_conf);
$release = new $release_conf; $release = new $release_conf;
$path_release_assets = $output.$release::PATH_ASSETS; $path_release_assets = OUTPUT_DIRECTORY.$release::PATH_ASSETS;
//Clean directory //Clean directory
notice("Clean build directory", TRUE); notice("Clean build directory", TRUE);
if(file_exists($output)) if(file_exists(OUTPUT_DIRECTORY))
delDir($output); delDir(OUTPUT_DIRECTORY);
mkdir($output, 0777, true); mkdir(OUTPUT_DIRECTORY, 0777, true);
mkdir($path_release_assets, 0777, true); mkdir($path_release_assets, 0777, true);
@ -199,7 +205,7 @@ if(isset($_SERVER["REDIRECT_URL"])){
} }
} ?>'; } ?>';
$page_src .= load_page($release_conf); $page_src .= load_page($release_conf);
file_put_contents($output."index.php", $page_src); file_put_contents(OUTPUT_DIRECTORY."index.php", $page_src);
// Add .htaccess file // Add .htaccess file
$htaccess = '<IfModule mod_rewrite.c> $htaccess = '<IfModule mod_rewrite.c>
@ -210,9 +216,38 @@ RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L] RewriteRule . index.php [L]
</IfModule> </IfModule>
'; ';
file_put_contents($output.".htaccess", $htaccess); file_put_contents(OUTPUT_DIRECTORY.".htaccess", $htaccess);
//Done //Done
notice("Done.", TRUE); notice("Done.", TRUE);
} //BUILD
/**
* Clean build directory
*/
function clean(){
notice("Cleaning build directory.", TRUE);
delDir(OUTPUT_DIRECTORY);
}
//Get the action and do it
if(!isset($_SERVER['argv'][1]))
exit("Usage: ./build [action]");
$action = $_SERVER['argv'][1];
switch($action){
case "build":
build();
break;
case "clean":
clean();
break;
default:
notice("Accepted commands are build, clean.", TRUE);
}