1
0
Fork 1

Apply `--verbose` to `make dev` & propagate to SSG

pull/37/head
gravel 1 year ago
parent fddd2ba957
commit 9380a82971
Signed by: gravel
SSH Key Fingerprint: SHA256:p4HP49CCk4YQMkJpWJ09L8peEPQWjERtdCRAFxPfbOY

@ -9,6 +9,12 @@
include_once "$PROJECT_ROOT/php/utils/logging.php"; include_once "$PROJECT_ROOT/php/utils/logging.php";
// Read the -v|--verbose option increasing logging verbosity to debug.
$options = getopt("v", ["verbose"]);
if (isset($options["v"]) or isset($options["verbose"])) {
$LOGGING_VERBOSITY = LoggingVerbosity::Debug;
}
// set timeout for file_get_contents() // set timeout for file_get_contents()
ini_set('default_socket_timeout', 6); // in seconds, default is 60 ini_set('default_socket_timeout', 6); // in seconds, default is 60

@ -1,5 +1,7 @@
port = 8081 PORT ?= 8081
output = output OUTPUT ?= output
FLAGS ?=
MAKE = make FLAGS=$(FLAGS)
# First goal is the default with `make`. # First goal is the default with `make`.
@ -14,49 +16,47 @@ all: fetch html
# Fetch room listing. # Fetch room listing.
fetch: fetch:
/bin/php php/fetch-servers.php /bin/php php/fetch-servers.php $(FLAGS)
# Fetch room listing with extra verbosity.
fetch-v:
/bin/php php/fetch-servers.php --verbose
# Generate HTML from data. # Generate HTML from data.
html: html:
/bin/php php/generate-html.php /bin/php php/generate-html.php $(FLAGS)
# Last item run in foreground to receive interrupts.
# Serve a local copy which responds to file changes. # Serve a local copy which responds to file changes.
dev: FLAGS = --verbose
dev: open dev: open
make server & $(MAKE) server &
make watchdog $(MAKE) watchdog
# (Last item run in foreground to receive interrupts.)
# Serve a local copy on LAN which responds to file changes. # Serve a local copy on LAN which responds to file changes.
lan-dev: FLAGS = --verbose
lan-dev: open lan-dev: open
ip addr | fgrep -e ' 192.' -e ' 10.' -which ip 1>/dev/null 2>/dev/null && ip addr | fgrep -e ' 192.' -e ' 10.' || true
make lan-server & $(MAKE) lan-server &
make watchdog $(MAKE) watchdog
# Serve a local copy. # Serve a local copy.
server: server:
/bin/php -S localhost:$(port) -t $(output) /bin/php -S "localhost:$(PORT)" -t "$(OUTPUT)"
# Serve a local copy on all interfaces. # Serve a local copy on all interfaces.
lan-server: lan-server:
/bin/php -S 0.0.0.0:$(port) -t $(output) /bin/php -S "0.0.0.0:$(PORT)" -t "$(OUTPUT)"
# Open locally served page in browser. # Open locally served page in browser.
open: open:
xdg-open http://localhost:$(port) >/dev/null 2>/dev/null & disown xdg-open "http://localhost:$(PORT)" >/dev/null 2>/dev/null & disown
# Update HTML on file change. Doesn't check for new files. # Update HTML on file change. Doesn't check for new files.
watchdog: watchdog:
find . | entr -n -s "make html" find . | grep -v ".git" | entr -n -s "$(MAKE) html"
# Remove artefacts # Remove artefacts
clean: clean:
-rm -r cache -rm -r cache 2>/dev/null || true
-rm -r output/*.html -rm -r output/*.html 2>/dev/null || true
# Build everything from scratch and test functionality. # Build everything from scratch and test functionality.
test: clean all open server test: clean all open server

@ -21,14 +21,6 @@
* 6. De-dupe servers based on pubkey * 6. De-dupe servers based on pubkey
*/ */
function main() { function main() {
global $LOGGING_VERBOSITY;
// Read the -v|--verbose option increasing logging verbosity to debug.
$options = getopt("v", ["verbose"]);
if (isset($options["v"]) or isset($options["verbose"])) {
$LOGGING_VERBOSITY = LoggingVerbosity::Debug;
}
global $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS; global $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS;
// Create default directories with conservative permissions. // Create default directories with conservative permissions.

@ -15,26 +15,34 @@
return $files; return $files;
} }
foreach (rglob("$TEMPLATES_ROOT/*.php") as $phppath) { function generate_html() {
// Do not render auxiliary PHP files. global $LOGGING_VERBOSITY, $TEMPLATES_ROOT, $DOCUMENT_ROOT;
if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
$flags = LoggingVerbosity::getVerbosityFlags($LOGGING_VERBOSITY)[1];
$docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_ROOT, $phppath); foreach (rglob("$TEMPLATES_ROOT/*.php") as $phppath) {
$relpath = str_replace($TEMPLATES_ROOT, "", $phppath); // Do not render auxiliary PHP files.
$docpath = str_replace(".php", ".html", $docpath); if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
// This works? Yes, yes it does.
// We do this to isolate the environment and include-once triggers,
// otherwise we could include the documents in an ob_* wrapper.
// Same as shell_exec, except we don't have to escape quotes. $docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_ROOT, $phppath);
log_info("Generating output for $relpath."); $relpath = str_replace($TEMPLATES_ROOT, "", $phppath);
$document = `cd "$TEMPLATES_ROOT"; php $phppath`; $docpath = str_replace(".php", ".html", $docpath);
file_put_contents($docpath, $document); // This works? Yes, yes it does.
// We do this to isolate the environment and include-once triggers,
// otherwise we could include the documents in an ob_* wrapper.
// Same as shell_exec, except we don't have to escape quotes.
log_info("Generating output for $relpath.");
$document = `cd "$TEMPLATES_ROOT"; php $phppath $flags`;
file_put_contents($docpath, $document);
}
log_info("Done generating HTML.");
} }
log_info("Done generating HTML."); generate_html();
?> ?>

@ -44,7 +44,7 @@
/** /**
* Returns the color marker for the given logging verbosity. * Returns the color marker for the given logging verbosity.
* @param $verbosity Logging verbosity to used for printing. * @param int $verbosity Logging verbosity to used for printing.
* @return ?string Terminal escape sequence to color foreground text. * @return ?string Terminal escape sequence to color foreground text.
*/ */
static function getVerbosityColorMarker(int $verbosity): ?string { static function getVerbosityColorMarker(int $verbosity): ?string {
@ -56,6 +56,18 @@
default => '' default => ''
}; };
} }
/**
* Returns a pair of optíons trigerring the given verbosity.
* @param int $verbosity Logging verbosity to set using flag.
* @return string[] Pair of short and long command-line verbosity flags.
*/
static function getVerbosityFlags(int $verbosity): array {
return match($verbosity) {
LoggingVerbosity::Debug => ["-v", "--verbose"],
default => ['', '']
};
}
} }
/** /**
@ -135,12 +147,12 @@
* Only logs when `$LOGGING_VERBOSITY` is debug and below. * Only logs when `$LOGGING_VERBOSITY` is debug and below.
* @param string $msg String message to log. * @param string $msg String message to log.
*/ */
function log_value(mixed $value) { function log_value(mixed $value, int $message_verbosity = LoggingVerbosity::Debug) {
log_debug(var_export($value, true)); _log_message(var_export($value, true), $message_verbosity);
} }
/** /**
* @var $LOGGING_VERBOSITY * @var int $LOGGING_VERBOSITY
* Global setting. * Global setting.
* Controls how detailed the displayed logs are. * Controls how detailed the displayed logs are.
*/ */