diff --git a/.gitignore b/.gitignore index 6d3fb341..34aa8519 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # ---> VisualStudioCode .settings - +# Build directory +output/* diff --git a/build b/build new file mode 100755 index 00000000..b34a4b69 --- /dev/null +++ b/build @@ -0,0 +1,195 @@ +#!/usr/bin/env php + +########################### +# ComunicWeb build script # +# # +# @author Pierre HUBERT # +########################### + + $val) + $array[$num] = $input.$val; + + return $array; +} + +/** + * Copy an array of file into a specific target file + * + * @param array $files The list of file to copy + * @param string $target The target file to create + * @param bool TRUE for a success / FALSE else + */ +function files_to_file(array $files, string $target) : bool { + + $source = ""; + + foreach($files as $file){ + $source .= file_get_contents($file)."\n"; + } + + return file_put_contents($target, $source) != FALSE; +} + +/** + * Delete the entire content of directory + * + * @param string $path The path of the directory to delete + */ +function delDir(string $path){ + if(is_dir($path) == TRUE){ + $rootFolder = scandir($path); + if(sizeof($rootFolder) > 2){ + foreach($rootFolder as $folder){ + if($folder != "." && $folder != ".."){ + //Pass the subfolder to function + delDir($path."/".$folder); + } + } + + //On the end of foreach the directory will be cleaned, and you will can use rmdir, to remove it + rmdir($path); + } + } + else { + if(file_exists($path) == TRUE){ + //Suppression du fichier + unlink($path); + } + } +} + +// copies files and non-empty directories +function rcopy(string $src, string $dst) { + if (is_dir($src)) { + mkdir($dst, 0777, true); + $files = scandir($src); + foreach ($files as $file) + if ($file != "." && $file != "..") rcopy("$src/$file", "$dst/$file"); + } + else if (file_exists($src)) copy($src, $dst); +} + + +//Initialize page +require_once __DIR__."/system/system.php"; + + +//Defines some variables +$output = __DIR__."/output/"; +$debug_conf = "dev"; +$release_conf = "build"; + + + +//Load configurations +notice("Load configurations.", TRUE); +notice("Debug config: ".$debug_conf); +notice("Release config: ".$release_conf); + +load_config($debug_conf); +$debug = new $debug_conf; +$path_debug_assets = __DIR__."/".$debug::PATH_ASSETS; + +load_config($release_conf); +$release = new $release_conf; +$path_release_assets = $output.$release::PATH_ASSETS; + + + + +//Clean directory +notice("Clean build directory", TRUE); +if(file_exists($output)) + delDir($output); +mkdir($output, 0777, true); +mkdir($path_release_assets, 0777, true); + + + +//Create unminified version +notice("Create unminified files versions", TRUE); + +//3rd party CSS +notice("Third Party CSS"); +$thirdPartyDebugFiles = array_put_begining($path_debug_assets, $debug::THIRD_PARTY_CSS); +$targetThirdPartyCSS = $path_release_assets.$release::THIRD_PARTY_CSS; +files_to_file($thirdPartyDebugFiles, $targetThirdPartyCSS); + +//3rd party JS +notice("Third Party JS"); +$thirdPartyDebugFiles = array_put_begining($path_debug_assets, $debug::THIRD_PARTY_JS); +$targetThirdPartyJS = $path_release_assets.$release::THIRD_PARTY_JS; +files_to_file($thirdPartyDebugFiles, $targetThirdPartyJS); + +//App CSS +notice("App CSS"); +$appDebugFiles = array_put_begining($path_debug_assets, $debug::APP_CSS); +$targetAppCSS = $path_release_assets.$release::APP_CSS; +files_to_file($appDebugFiles, $targetAppCSS); + +//App JS +notice("App JS"); +$appDebugFiles = array_put_begining($path_debug_assets, $debug::APP_JS); +$targetAppJS = $path_release_assets.$release::APP_JS; +files_to_file($appDebugFiles, $targetAppJS); + + +//Make some adpations on third party files +$source = file_get_contents($targetThirdPartyCSS); +$source = str_replace("../fonts/fontawesome", "fontawesome_fonts/fontawesome", $source); +file_put_contents($targetThirdPartyCSS, $source); + +//Copy font awesome files and twemojies files + Google Fonts +rcopy($path_debug_assets."3rdparty/adminLTE/plugins/font-awesome/fonts", $path_release_assets."fontawesome_fonts"); +rcopy($path_debug_assets."3rdparty/twemoji/2/72x72/", $path_release_assets."3rdparty/twemoji/2/72x72/"); +rcopy($path_debug_assets."3rdparty/adminLTE/plugins/googleFonts/googleFonts/", $path_release_assets."googleFonts/"); +rcopy($path_debug_assets."3rdparty/wdt-emoji/sheets/", $path_release_assets."3rdparty/wdt-emoji/sheets/"); + +//Copy images and templates +rcopy($path_debug_assets."img/", $path_release_assets."img/"); +rcopy($path_debug_assets."templates/", $path_release_assets."templates/"); + + +//Create main HTML file +notice("Generate PHP root file"); +$page_src = '", $_SERVER["REDIRECT_URL"])){ + //This is a 404 not found error... + echo "

Error! 404 not found

"; + http_response_code(404); + exit(); + } +} ?>'; +$page_src .= load_page("build"); +file_put_contents($output."index.php", $page_src); + +// Add .htaccess file +$htaccess = ' +RewriteEngine On +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . index.php [L] + +'; +file_put_contents($output.".htaccess", $htaccess); \ No newline at end of file diff --git a/system/config/build.config.php b/system/config/build.config.php new file mode 100644 index 00000000..16b0aa45 --- /dev/null +++ b/system/config/build.config.php @@ -0,0 +1,69 @@ +