1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-21 16:13:00 +00:00

Add dependency system to build system ahead of a feature-search refactor.

We should probably refactor the build script into something more 
object-oriented too, since it's getting somewhat complicated. I've added 
some ASCII art headers as a stop-gap for now, but a proper refactor of 
that too (into a class-based system probably) is incoming I think.
This commit is contained in:
Starbeamrainbowlabs 2020-03-11 23:32:10 +00:00
parent 6cfd60b765
commit 2eb4f73c5e
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 93 additions and 1 deletions

View file

@ -61,7 +61,8 @@ function register_module($settings)
"lastupdate" => filemtime("modules/" . $settings["id"] . ".php"),
// May not be set. Defaults to false
"optional" => $settings["optional"] ?? false,
"extra_data" => $settings["extra_data"] ?? []
"extra_data" => $settings["extra_data"] ?? [],
"depends" => $settings["depends"] ?? []
];
$module_index[] = $newmodule;
}

View file

@ -5,6 +5,7 @@ register_module([
"author" => "Starbeamrainbowlabs",
"description" => "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
"id" => "feature-search",
// "depends" => [ "search-engine" ],
"code" => function() {
global $settings, $paths;

View file

@ -27,6 +27,20 @@ function log_str(string $line) {
//else error_log($line);
}
/*
███ ███ ██████ ██████ ██ ██ ██ ███████
████ ████ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██ ██ ██ ██ ██ ██ █████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██████ ██████ ██████ ███████ ███████
██ ██████ █████ ██████ ██ ███ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ███
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██████ ██ ██ ██████ ██ ██ ████ ██████
*/
log_str("*** Beginning main build sequence ***\n");
log_str("Reading in module index...\n");
@ -67,11 +81,69 @@ foreach($module_index as $module) {
$module_list[] = $module;
}
/*
██████ ███████ ██████ ███████ ███ ██ ██████ ███████ ███ ██ ██████ ██ ██
██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ████ ██ ██ ██ ██
██ ██ █████ ██████ █████ ██ ██ ██ ██ ██ █████ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ██ ███████ ██ ████ ██████ ███████ ██ ████ ██████ ██
███████ ██████ █████ ███ ██ ███ ██ ██ ███ ██ ██████
██ ██ ██ ██ ████ ██ ████ ██ ██ ████ ██ ██
███████ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██████ ██ ██ ██ ████ ██ ████ ██ ██ ████ ██████
*/
function module_list_search(array $list, string $id) : bool {
foreach($list as $item) {
if($item->id === $id)
return true;
}
return false;
}
function module_list_find(array $list, string $id) {
foreach($list as $item) {
if($item->id === $id)
return $item;
}
return null;
}
log_str("Scanning for dependencies...\n");
$module_count = count($module_list);
for($i = 0; $i < $module_count; $i++) {
foreach($module_list[$i]->depends as $dependency) {
echo("scanning {$module_list[$i]->id}: $dependency\n");
if(!module_list_search($module_list, $dependency)) {
log_str("Adding missing dependency $dependency for {$module_list[$i]->id}\n");
$missing_dependency = module_list_find($module_index, $dependency);
if($missing_dependency == null) {
if(php_sapi_name() != "cli") header("content-type: text/plain");
echo("Error: {$module_list[$i]->id} requires $dependency as a dependency, but it couldn't be found in the module index. This looks like a bug.\n");
if(php_sapi_name() == "cli") exit(2);
else exit();
}
$module_list[] = $missing_dependency;
$module_count++;
}
}
}
if(php_sapi_name() != "cli") {
header("content-type: text/php");
header("content-disposition: attachment; filename=\"index.php\"");
}
/*
██████ ██████ ██████ ███████
██ ██ ██ ██ ██ ██
██ ██ ██ ██████ █████
██ ██ ██ ██ ██ ██
██████ ██████ ██ ██ ███████
*/
log_str("Reading in core files...\n");
$core_files_list = glob("core/*.php"); natsort($core_files_list);
@ -95,6 +167,15 @@ $core = str_replace([
$result = $core;
/*
██████ █████ ██████ ██ ██ ███████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ██ █████ █████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██████ ██ ██ ███████ ██ ██
*/
$extra_data_archive = new ZipArchive();
// Use dev/shm if possible (it's *always* in memory). PHP will default to the system's temporary directory if it's not available
$temp_filename = tempnam("/dev/shm", "pepperminty-wiki-pack");
@ -145,6 +226,15 @@ log_str("\n");
$extra_data_archive->close();
/*
███████ ██ ███ ██ ██ ███████ ██ ██ ███████ ██████
██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██
█████ ██ ██ ██ ██ ██ ███████ ███████ █████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ████ ██ ███████ ██ ██ ███████ ██ ██
*/
$archive_stream = fopen($temp_filename, "r");
$output_stream = null;