diff --git a/files.php b/files.php index f1a703f4..70ee7ecd 100644 --- a/files.php +++ b/files.php @@ -325,15 +325,16 @@ "path" => "./popup/certaccept/", "local-path" => "./shared/popup/certaccept/html/" ], + [ /* javascript loader (debug) */ "type" => "js", - "search-pattern" => "/.*\.js$/", + "search-pattern" => "/(loader|certaccept)\.js$/", "build-target" => "dev", "path" => "./popup/certaccept/loader/", "local-path" => "./shared/loader/" ], - [ /* javascript loader for releases */ + [ /* javascript loader (releases) */ "type" => "js", "search-pattern" => "/.*loader_certaccept.min.js$/", "build-target" => "rel", @@ -342,13 +343,67 @@ "local-path" => "./shared/generated/" ], + [ /* javascript imported from shared for debug */ + "type" => "js", + "search-pattern" => "/^(BrowserIPC|log|proto|settings)\.js$/", + "build-target" => "dev", + + "path" => "./popup/certaccept/js/", + "local-path" => "./shared/js/" + ], + [ /* javascript for debug */ + "type" => "js", + "search-pattern" => "/^certaccept\.min\.js$/", + "build-target" => "rel", + + "path" => "./popup/certaccept/js/", + "local-path" => "./shared/generated/" + ], + + [ /* javascript for release */ "type" => "js", "search-pattern" => "/^.*\.js$/", "build-target" => "dev", "path" => "./popup/certaccept/js/", - "local-path" => "./shared/js/" + "local-path" => "./shared/popup/certaccept/js/" + ], + + [ /* shared css files */ + "type" => "css", + "search-pattern" => "/.*\.css$/", + "build-target" => "rel|dev", + + "path" => "./popup/certaccept/css/loader/", + "local-path" => "./shared/css/loader/" + ], + + [ /* shared css files */ + "type" => "css", + "search-pattern" => "/.*\.css$/", + "build-target" => "rel|dev", + + "path" => "./popup/certaccept/css/static/", + "local-path" => "./shared/popup/certaccept/css/static/" + ], + + [ /* img files */ + "type" => "img", + "search-pattern" => "/^(loading_error.*)\.(svg)$/", + "build-target" => "dev|rel", + + "path" => "./popup/certaccept/img/", + "local-path" => "./shared/img/" + ], + + [ /* jquery vendor */ + "type" => "js", + "search-pattern" => "/^jquery\/.*\.js$/", + "build-target" => "dev|rel", + + "path" => "./popup/certaccept/vendor/", + "local-path" => "./vendor/" ], ]; @@ -461,7 +516,7 @@ foreach($files as $key => $value){ $path = $base_dir.$dir.DIRECTORY_SEPARATOR.$value; if(!is_dir($path)) { - if(!$match || preg_match($match, ($dir ? $dir.DIRECTORY_SEPARATOR : "").$value)) + if(!$match || preg_match($match, ($dir ? $dir . DIRECTORY_SEPARATOR : "") . $value)) $results[] = ($dir ? $dir.DIRECTORY_SEPARATOR : "").$value; } else if($value != "." && $value != "..") { list_dir($base_dir, $match, $depth - 1, $results, ($dir ? $dir.DIRECTORY_SEPARATOR : "").$value); @@ -481,7 +536,25 @@ public $hash; } - function find_files($flag = 0b11, $local_path_prefix = "." . DIRECTORY_SEPARATOR, $type = "dev", $args = []) { //TODO Use cache here! + function normalizePath($path) { + return array_reduce(explode('/', $path), create_function('$a, $b', ' + if($a === 0 && $b === ".") + return "./"; + + if($a === 0) + $a = "/"; + + if($b === "" || $b === ".") + return $a; + + if($b === "..") + return dirname($a); + + return preg_replace("/\/+/", "/", "$a/$b"); + '), 0); + } + + function find_files($flag = 0b11, $local_path_prefix = "." . DIRECTORY_SEPARATOR, $target_path_prefix = "." . DIRECTORY_SEPARATOR, $type = "dev", $args = []) { //TODO Use cache here! global $APP_FILE_LIST; $result = []; @@ -510,8 +583,8 @@ $file = new AppFile; $f_info = pathinfo($f_entry); - $file->target_path = realpath(systemify_path($entry["path"]) . DIRECTORY_SEPARATOR . $f_info["dirname"] . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; - $file->local_path = realpath(getcwd() . DIRECTORY_SEPARATOR . systemify_path($entry["local-path"]) . DIRECTORY_SEPARATOR . $f_info["dirname"] . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $file->target_path = normalizePath($target_path_prefix . systemify_path($entry["path"]) . DIRECTORY_SEPARATOR . $f_info["dirname"]) . DIRECTORY_SEPARATOR; + $file->local_path = normalizePath(getcwd() . DIRECTORY_SEPARATOR . systemify_path($entry["local-path"]) . DIRECTORY_SEPARATOR . $f_info["dirname"]) . DIRECTORY_SEPARATOR; $file->name = $f_info["basename"]; $file->type = $entry["type"]; @@ -561,10 +634,10 @@ if($_SERVER["argv"][3] == "dev" || $_SERVER["argv"][3] == "development") { if ($_SERVER["argv"][2] == "web") { $flagset = 0b01; - $environment = join_path("web", "environment", "development"); + $environment = "." . DIRECTORY_SEPARATOR . join_path("web", "environment", "development"); } else if ($_SERVER["argv"][2] == "client") { $flagset = 0b10; - $environment = join_path("client-api", "environment", "ui-files", "raw"); + $environment = "." . DIRECTORY_SEPARATOR . join_path("client-api", "environment", "ui-files", "raw"); } else { error_log("Invalid type!"); goto help; @@ -573,10 +646,10 @@ $type = "rel"; if ($_SERVER["argv"][2] == "web") { $flagset = 0b01; - $environment = join_path("web", "environment", "release"); + $environment = "." . DIRECTORY_SEPARATOR . join_path("web", "environment", "release"); } else if ($_SERVER["argv"][2] == "client") { $flagset = 0b10; - $environment = join_path("client-api", "environment", "ui-files", "raw"); + $environment = "." . DIRECTORY_SEPARATOR . join_path("client-api", "environment", "ui-files", "raw"); } else { error_log("Invalid type!"); goto help; @@ -595,12 +668,7 @@ goto handle_error; } - $files = find_files($flagset, "." . DIRECTORY_SEPARATOR, $type, array_slice($_SERVER["argv"], 4)); - $original_path = realpath("."); - if(!chdir($environment)) { - error_log("Failed to enter directory " . $environment . "!"); - exit(1); - } + $files = find_files($flagset, "." . DIRECTORY_SEPARATOR, $environment . DIRECTORY_SEPARATOR, $type, array_slice($_SERVER["argv"], 4)); /** @var AppFile $file */ foreach($files as $file) { @@ -612,10 +680,6 @@ if(create_link($output, $file->local_path . $file->name, $file->target_path . $file->name, $dry_run) === false) goto handle_error; } - if(!chdir($original_path)) { - error_log("Failed to reset directory!"); - exit(1); - } echo "Generated!" . PHP_EOL; } diff --git a/scripts/build_declarations.sh b/scripts/build_declarations.sh index 9e97fc26..1e7d8c7c 100755 --- a/scripts/build_declarations.sh +++ b/scripts/build_declarations.sh @@ -41,8 +41,12 @@ replace_tribble client/declarations/exports.d.ts echo "Generated client declarations" #Shared -npm run dtsgen -- --config shared/tsconfig/dtsconfig.json -v -replace_tribble shared/declarations/exports.d.ts +./shared/generate_declarations.sh +[[ $? -ne 0 ]] && { + echo "Failed to generate shared" +} + +#replace_tribble shared/declarations/exports.d.ts echo "Generated shared declarations" #Now build the merged declaration for the shared project @@ -54,14 +58,10 @@ if [[ ! -d shared/declarations ]]; then exit 1 fi fi -#The shared part has no access to the other parts, it just declares a abstract API -#generate_link client/declarations/exports.d.ts shared/declarations/imports_client.d.ts -#generate_link web/declarations/exports.d.ts shared/declarations/imports_web.d.ts - #Last but not least the client imports -generate_link shared/declarations/exports.d.ts web/declarations/imports_shared.d.ts +generate_link shared/declarations/exports_app.d.ts web/declarations/imports_shared.d.ts generate_link shared/declarations/exports_loader_app.d.ts web/declarations/imports_shared_loader.d.ts -generate_link shared/declarations/exports.d.ts client/declarations/imports_shared.d.ts +generate_link shared/declarations/exports_app.d.ts client/declarations/imports_shared.d.ts generate_link shared/declarations/exports_loader_app.d.ts client/declarations/imports_shared_loader.d.ts \ No newline at end of file diff --git a/shared/css/generate_packed.sh b/shared/css/generate_packed.sh index ec0ba838..cfbbab48 100755 --- a/shared/css/generate_packed.sh +++ b/shared/css/generate_packed.sh @@ -50,6 +50,16 @@ files=( ) target_file=`pwd`/../generated/static/base.css + +if [[ ! -d $(dirname ${target_file}) ]]; then + echo "Creating target path ($(dirname ${target_file}))" + mkdir -p $(dirname ${target_file}) + if [[ $? -ne 0 ]]; then + echo "Failed to create target path!" + exit 1 + fi +fi + echo "/* Auto generated merged CSS file */" > ${target_file} for file in "${files[@]}"; do if [[ ${file} =~ css/* ]]; then diff --git a/shared/generate_declarations.sh b/shared/generate_declarations.sh new file mode 100755 index 00000000..32e2d64b --- /dev/null +++ b/shared/generate_declarations.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +BASEDIR=$(dirname "$0") +cd "$BASEDIR" +source ../scripts/resolve_commands.sh + +function generate_declaration() { + echo "Generating declarations for project $1 ($2)" + + if [[ -e ${2} ]]; then + rm ${2} + if [[ $? -ne 0 ]]; then + echo "Failed to remove old declaration file ($2)!" + echo "This could be critical later!" + fi + fi + + npm run dtsgen -- --config $(pwd)/tsconfig/$1 -v + if [[ ! -e $2 ]]; then + echo "Failed to generate definitions" + exit 1 + fi +} + +#Generate the loader definitions first +app_declaration="declarations/exports_app.d.ts" +loader_declaration_app="declarations/exports_loader_app.d.ts" +loader_declaration_certaccept="declarations/exports_loader_certaccept.d.ts" + +generate_declaration dtsconfig_app.json ${app_declaration} +generate_declaration dtsconfig_loader_app.json ${loader_declaration_app} +generate_declaration dtsconfig_loader_certaccept.json ${loader_declaration_certaccept} + +exit 0 \ No newline at end of file diff --git a/shared/generate_packed.sh b/shared/generate_packed.sh index 4c1ad88a..9bd70797 100755 --- a/shared/generate_packed.sh +++ b/shared/generate_packed.sh @@ -3,28 +3,7 @@ BASEDIR=$(dirname "$0") cd "$BASEDIR" source ../scripts/resolve_commands.sh - -#Generate the loader definitions first -LOADER_FILE="declarations/exports_loader_app.d.ts" -if [[ -e ${LOADER_FILE} ]]; then - rm ${LOADER_FILE} - if [[ $? -ne 0 ]]; then - echo "Failed to remove loader file!\nThis could be critical later!" - fi -fi - -npm run dtsgen -- --config $(pwd)/tsconfig/dtsconfig_loader_app.json -v -if [[ ! -e ${LOADER_FILE} ]]; then - echo "Failed to generate definitions" - exit 1 -fi - -npm run dtsgen -- --config $(pwd)/tsconfig/dtsconfig_packed.json -v -if [[ $? -ne 0 ]]; then - echo "Failed to generate definitions for the loader" - exit 1 -fi - +# The app loader execute_ttsc -p tsconfig/tsconfig_packed_loader_app.json if [[ $? -ne 0 ]]; then echo "Failed to generate packed loader file!" @@ -37,21 +16,37 @@ if [[ $? -ne 0 ]]; then exit 1 fi +# The popup certaccept loader +execute_ttsc -p tsconfig/tsconfig_packed_loader_certaccept.json +if [[ $? -ne 0 ]]; then + echo "Failed to generate packed loader file!" + exit 1 +fi +npm run minify-web-rel-file `pwd`/generated/loader_certaccept.min.js `pwd`/generated/loader_certaccept.js +if [[ $? -ne 0 ]]; then + echo "Failed to minimize packed loader file!" + exit 1 +fi + +# The main shared source execute_ttsc -p tsconfig/tsconfig_packed.json if [[ $? -ne 0 ]]; then echo "Failed to generate packed file!" exit 1 fi -#Now link the loader file -if [[ ! -L generated/load.js ]]; then - rm generated/load.js 2>/dev/null - ln -rs js/load.js generated/load.js +# The certaccept source +execute_ttsc -p tsconfig/tsconfig_packed_certaccept.json +if [[ $? -ne 0 ]]; then + echo "Failed to generate packed certaccept file!" + exit 1 fi -if [[ ! -d generated/static/ ]]; then - mkdir -p generated/static/ +npm run minify-web-rel-file `pwd`/generated/certaccept.min.js `pwd`/generated/certaccept.js +if [[ $? -ne 0 ]]; then + echo "Failed to minimize the certaccept file!" + exit 1 fi # Create packed CSS file diff --git a/shared/html/index.php b/shared/html/index.php index 1f67af08..a43010be 100644 --- a/shared/html/index.php +++ b/shared/html/index.php @@ -37,7 +37,7 @@ ?> - +