Added prod, dev, and authors flags to gulp/compiler.

main
Robert 3 years ago
parent 18d03e6f40
commit 173a65e606
  1. 2
      README
  2. 26
      gulpfile.js
  3. 2
      src/bootstrap/safer_io.php
  4. 6
      src/classes/extras/bb_code_parser.php
  5. 6
      src/classes/extras/html_parser.php
  6. 2
      src/classes/extras/safer_sql.php
  7. 6
      src/classes/view.php
  8. 83
      src/compiler.php

@ -1,4 +1,4 @@
# Trying To Scale - PHP 8.x Framework # Trying To Scale - PHP 8.x micro Framework
#### tts for short...is a collection of scripts I really liked...and made improvements on or made from scratch... #### tts for short...is a collection of scripts I really liked...and made improvements on or made from scratch...

@ -7,24 +7,40 @@
const { src, dest, series, parallel, watch } = require('gulp'); const { src, dest, series, parallel, watch } = require('gulp');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const args = process.argv.slice(2); // Ignore node/path
var all_args = "";
for(let i = 0; i < args.length; i++) {
all_args += " " + args[i];
}
const php_source_files = [ const php_source_files = [
'**/*.php', '**/*.php',
'!**/dist/*.php' '!**/dist/*.php'
]; ];
function compile_php_files() { function compile_php_files() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
exec('php -f compiler.php', function (err, stdout, stderr) { exec('php -f compiler.php -- ' + all_args,
function (err, stdout, stderr) {
console.log(stdout); console.log(stdout);
console.log(stderr); console.log(stderr);
resolve(stdout); resolve(stdout);
}); });
}); });
} }
async function help() {
console.log(`compiler options:
--prod [will minify all files]
--dev [combines files UN-minified]
--authors [Removes all comments including authors]
`);
}
function watch_php() { function watch_php() {
process.chdir('src'); process.chdir('src');
watch(php_source_files, compile_php_files); watch(php_source_files, compile_php_files);
} }
exports.default = series(watch_php); exports.default = series(watch_php);
exports.help = help;

@ -434,7 +434,7 @@ final class safer_io {
$safer_db_data = $safer_data; $safer_db_data = $safer_data;
} else { } else {
if (isset($a->use_db_filter) && $a->use_db_filter == DB_FILTER::ON) { if (isset($a->use_db_filter) && $a->use_db_filter == DB_FILTER::ON) {
$safe_for_db = \tts\safer_sql::get_safer_sql_text($safer_data); $safe_for_db = \tts\extras\safer_sql::get_safer_sql_text($safer_data);
$text = $safe_for_db["text"]; $text = $safe_for_db["text"];
$meta[$input_field_name]['db_filter_status'] = $safe_for_db["status"] ?? \tts\SQL_SAFETY_FLAG::filtered; $meta[$input_field_name]['db_filter_status'] = $safe_for_db["status"] ?? \tts\SQL_SAFETY_FLAG::filtered;
} else { } else {

@ -4,13 +4,13 @@ declare(strict_types=1);
/** /**
* @link https://github.com/genert/bbcode/blob/master/src/Parser/BBCodeParser.php * @link https://github.com/genert/bbcode/blob/master/src/Parser/BBCodeParser.php
* The MIT License (MIT) * @license The MIT License (MIT)
* Copyright (c) Genert 2017 - present. * @copyright (c) Genert 2017 - present.
* *
* Take BB code 2 HTML, to display output * Take BB code 2 HTML, to display output
*/ */
namespace tts; namespace tts\extras;
final class bb_code_parser { final class bb_code_parser {
protected $parsers = [ protected $parsers = [

@ -4,13 +4,13 @@ declare(strict_types=1);
/** /**
* @link https://github.com/genert/bbcode/blob/master/src/Parser/HTMLParser.php * @link https://github.com/genert/bbcode/blob/master/src/Parser/HTMLParser.php
* The MIT License (MIT) * @license The MIT License (MIT)
* Copyright (c) Genert 2017 - present. * @copyright (c) Genert 2017 - present.
* *
* Take HTML 2 BB code .. to save into db * Take HTML 2 BB code .. to save into db
*/ */
namespace tts; namespace tts\extras;
final class html_parser { final class html_parser {
protected $parsers = [ protected $parsers = [

@ -13,7 +13,7 @@ declare(strict_types=1);
* Too many FALSE positives and too many FALSE Negatives!!! * Too many FALSE positives and too many FALSE Negatives!!!
*/ */
namespace tts; namespace tts\extras;
enum SQL_SAFETY_FLAG { enum SQL_SAFETY_FLAG {
case good; // All Okey case good; // All Okey

@ -8,12 +8,6 @@ declare(strict_types=1);
* @license https://mit-license.org/ * @license https://mit-license.org/
*/ */
/**
* @todo Add Template Service here instead of hardcoded
* Ref to Liquid.
*/
namespace tts; namespace tts;
final class view { final class view {

@ -8,8 +8,8 @@ declare(strict_types=1);
* @license https://mit-license.org/ * @license https://mit-license.org/
*/ */
$show_authors = true;
$debugging_AKA_non_production_mode = false; $debugging_AKA_non_production_mode = false;
if ($debugging_AKA_non_production_mode) { if ($debugging_AKA_non_production_mode) {
$print_new_line = true; $print_new_line = true;
$show_filename_comments = true; $show_filename_comments = true;
@ -17,10 +17,42 @@ if ($debugging_AKA_non_production_mode) {
$skip_extras_folder = false; $skip_extras_folder = false;
} else { } else {
$print_new_line = false; $print_new_line = false;
$show_filename_comments = false; $show_filename_comments = true;
$skip_mocking_data_arrays = true; $skip_mocking_data_arrays = true;
$skip_extras_folder = true; $skip_extras_folder = true;
} }
foreach($argv as $arg) {
if ($arg === "/?") {
?>
-prod break up mocking array data file and extras folder into separate files
-dev build one big file (non-minimized)
-authors (Removes all comment blocks, including the author/(c))
/? this help
<?php
exit(0);
}
if ($arg === "-prod" || $arg === "--prod") {
$debugging_AKA_non_production_mode = false;
$print_new_line = false;
$skip_mocking_data_arrays = true;
$skip_extras_folder = true;
echo "Prod mode on";
}
if ($arg === "-dev" || $arg === "--dev") {
$debugging_AKA_non_production_mode = true;
$print_new_line = true;
$skip_mocking_data_arrays = false;
$skip_extras_folder = false;
echo "Dev mode on";
}
if ($arg === "-authors" || $arg === "--authors") {
$show_authors = false;
$show_filename_comments = false;
echo "Skipping Comments/Authors...";
}
}
$make_one_file = true; $make_one_file = true;
if ($make_one_file) { if ($make_one_file) {
@ -29,6 +61,9 @@ if ($make_one_file) {
multi_files(); multi_files();
} }
/**
* Default and best mode
*/
function single_file(): void { function single_file(): void {
$bootstap_files = glob("bootstrap/*.php"); $bootstap_files = glob("bootstrap/*.php");
@ -51,6 +86,9 @@ function single_file(): void {
get_classes($rsearch['extras'], "tts_extras"); get_classes($rsearch['extras'], "tts_extras");
} }
/**
* Left in here in case you wanted to play with loading this way
*/
function multi_files(): void { function multi_files(): void {
$bootstap_files = glob("bootstrap/*.php"); $bootstap_files = glob("bootstrap/*.php");
@ -177,15 +215,22 @@ function rsearch(array & $file_list, string $folder, string $pattern): array {
return ['extras' => $extras, 'arrays' => $arrays]; return ['extras' => $extras, 'arrays' => $arrays];
} }
function remove_comments(string & $str): void { function remove_comments(string & $str): array {
$authors = [];
foreach (token_get_all($str) as $token ) { foreach (token_get_all($str) as $token ) {
if ($token[0] != \T_COMMENT && if ($token[0] != \T_COMMENT &&
$token[0] != \T_DOC_COMMENT $token[0] != \T_DOC_COMMENT
) { ) {
continue; // Do nothing on NON-Comments! continue; // Do nothing on NON-Comments!
} }
if (str_contains($token[1], "@author") || str_contains($token[1], "@copyright")) {
if (! str_contains($token[1], "Robert Strutts")) {
$authors[] = $token[1];
}
}
$str = str_replace($token[1], '', $str); // Replace comment $str = str_replace($token[1], '', $str); // Replace comment
} }
return $authors;
} }
function is_folder(string $dir): bool { function is_folder(string $dir): bool {
@ -206,7 +251,8 @@ function compile(
bool $append = false, bool $append = false,
?string $prefix = "", ?string $prefix = "",
?string $postfix = "" ?string $postfix = ""
): void { ): void {
$show_authors = $GLOBALS['show_authors'] ?? true;
$root_path = __DIR__ . '/'; $root_path = __DIR__ . '/';
is_folder($root_path); is_folder($root_path);
@ -226,11 +272,14 @@ function compile(
} }
if (! $append) { if (! $append) {
fwrite($fl_handle, "<?php \r\n declare(strict_types=1);\r\n"); fwrite($fl_handle, "<?php \r\n declare(strict_types=1);\r\n");
fwrite($fl_handle, "\t /** \r\n \t * @link https://git.mysnippetsofcode.com/tts/tts_framework \r\n \t * @author Robert Strutts <Robert@TryingToScale.com> \r\n \t * @copyright Copyright (c) 2022, Robert Strutts. \r\n \t * @license MIT \r\n \t */ \r\n"); if ($show_authors) {
fwrite($fl_handle, "\t /** \r\n \t * @link https://git.mysnippetsofcode.com/tts/tts_framework \r\n \t * @author Robert Strutts <Robert@TryingToScale.com> \r\n \t * @copyright Copyright (c) 2022, Robert Strutts. \r\n \t * @license MIT \r\n \t */ \r\n");
}
} }
if ($prefix !== null && ! empty($prefix)) { if ($prefix !== null && ! empty($prefix)) {
fwrite($fl_handle, $prefix); fwrite($fl_handle, $prefix);
} }
foreach ($files as $file) { foreach ($files as $file) {
$file_with_path = $root_path . $file; $file_with_path = $root_path . $file;
@ -238,8 +287,8 @@ function compile(
if ($content === false) { if ($content === false) {
continue; continue;
} }
remove_comments($content); $authors = remove_comments($content);
$a = explode(PHP_EOL, $content); $a = explode(PHP_EOL, $content);
unset($content); unset($content);
@ -249,9 +298,15 @@ function compile(
if ($is_php_start_block) { if ($is_php_start_block) {
$is_php_start_block = false; $is_php_start_block = false;
if ($GLOBALS['show_filename_comments']) { if ($GLOBALS['show_filename_comments']) {
$line = PHP_EOL . "/* Contents of : {$file} */"; $line = PHP_EOL . "/* Contents of : {$file} */" . PHP_EOL;
fwrite($fl_handle, $line); fwrite($fl_handle, $line);
} }
if ($show_authors) {
foreach($authors as $author) {
fwrite($fl_handle, PHP_EOL);
fwrite($fl_handle, "/*" . str_replace(['/*','*/','*'], ['','',''], $author) . "*/" . PHP_EOL);
}
}
continue; continue;
} }
@ -281,13 +336,19 @@ function compile(
'\\tts\\contacts\\', '\\tts\\contacts\\',
'\\tts\\traits\\database\\', '\\tts\\traits\\database\\',
'\\tts\\traits\\security\\', '\\tts\\traits\\security\\',
'\\tts\\services\\sessions\\']; '\\tts\\services\\sessions\\',
'\\tts\\exceptions\\',
'\\tts\\extras\\',
];
$replace = ['tts', 'tts', $replace = ['tts', 'tts',
'\\tts\\', '\\tts\\',
'\\tts\\', '\\tts\\',
'\\tts\\', '\\tts\\',
'\\tts\\', '\\tts\\',
'\\tts\\']; '\\tts\\',
'\\tts\\',
'\\tts\\',
];
$out = str_replace($search, $replace, $line); $out = str_replace($search, $replace, $line);
fwrite($fl_handle, $out); fwrite($fl_handle, $out);
} }

Loading…
Cancel
Save