mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
Rework build system to reduce repetition
This commit is contained in:
parent
f915df22ff
commit
daa8ac2a3b
7 changed files with 136 additions and 123 deletions
|
@ -5,9 +5,6 @@ php:
|
|||
- 5.6
|
||||
- nightly
|
||||
|
||||
before_script:
|
||||
- rm build/index.php
|
||||
- php rebuild_module_index.php
|
||||
- php build.php
|
||||
before_script: php build.php
|
||||
|
||||
script: php -l build/index.php
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
@echo off
|
||||
echo Deleting old index.php
|
||||
del build\index.php
|
||||
php rebuild_module_index.php
|
||||
php build.php
|
||||
php build.php
|
||||
|
|
133
build.php
133
build.php
|
@ -1,79 +1,54 @@
|
|||
<?php
|
||||
|
||||
if(php_sapi_name() == "cli")
|
||||
{
|
||||
echo("Beginning build...\n");
|
||||
echo("Reading in module index...\n");
|
||||
}
|
||||
|
||||
$module_index = json_decode(file_get_contents("module_index.json"));
|
||||
$module_list = [];
|
||||
foreach($module_index as $module)
|
||||
{
|
||||
$module_list[] = $module->id;
|
||||
}
|
||||
|
||||
if(isset($_GET["modules"]))
|
||||
{
|
||||
$module_list = explode(",", $_GET["modules"]);
|
||||
}
|
||||
|
||||
if(php_sapi_name() != "cli")
|
||||
{
|
||||
header("content-type: text/php");
|
||||
}
|
||||
|
||||
if(php_sapi_name() == "cli") echo("Reading in core files...");
|
||||
|
||||
$core = file_get_contents("core.php");
|
||||
$settings = file_get_contents("settings.fragment.php");
|
||||
$settings = str_replace([ "<?php", "?>" ], "", $settings);
|
||||
$core = str_replace("{settings}", $settings, $core);
|
||||
|
||||
$result = $core;
|
||||
|
||||
foreach($module_list as $module_id)
|
||||
{
|
||||
if($module_id == "") continue;
|
||||
|
||||
if(php_sapi_name() == "cli") echo("Adding $module_id\n");
|
||||
|
||||
$module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module_id) . ".php";
|
||||
|
||||
//echo("id: $module_id | filepath: $module_filepath\n");
|
||||
|
||||
if(!file_exists($module_filepath))
|
||||
{
|
||||
http_response_code(400);
|
||||
exit("Failed to load module with name: $module_filepath");
|
||||
}
|
||||
|
||||
$modulecode = file_get_contents($module_filepath);
|
||||
$modulecode = str_replace([ "<?php", "?>" ], "", $modulecode);
|
||||
$result = str_replace(
|
||||
"// %next_module% //",
|
||||
"$modulecode\n// %next_module% //",
|
||||
$result);
|
||||
}
|
||||
|
||||
if(php_sapi_name() == "cli")
|
||||
{
|
||||
if(file_exists("build/index.php"))
|
||||
{
|
||||
echo("index.php already exists in the build folder, exiting\n");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("Done. Saving to disk...");
|
||||
file_put_contents("build/index.php", $result);
|
||||
echo("complete!\n");
|
||||
echo("*** Build Completed ***\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exit($result);
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
echo("*** Preparing environment ***\n");
|
||||
|
||||
$build_env = new stdClass();
|
||||
$build_env->target = "build/index.php";
|
||||
|
||||
if(file_exists($build_env->target))
|
||||
{
|
||||
echo("Deleting old target...\n");
|
||||
unlink($build_env->target);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//////////////////////// Rebuild Module Index ////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
echo("*** Rebuilding module index ***\n");
|
||||
$modules = glob("modules/*.php");
|
||||
$module_index = [];
|
||||
|
||||
function register_module($settings)
|
||||
{
|
||||
global $module_index;
|
||||
$newmodule = [
|
||||
"name" => $settings["name"],
|
||||
"version" => $settings["version"],
|
||||
"author" => $settings["author"],
|
||||
"description" => $settings["description"],
|
||||
"id" => $settings["id"],
|
||||
"lastupdate" => filemtime("modules/" . $settings["id"] . ".php")
|
||||
];
|
||||
$module_index[] = $newmodule;
|
||||
}
|
||||
|
||||
foreach($modules as $filename)
|
||||
{
|
||||
echo("Processing $filename\n");
|
||||
require($filename);
|
||||
}
|
||||
|
||||
echo("*** Processing complete ***\n");
|
||||
|
||||
echo("Writing new module index to disk...");
|
||||
file_put_contents("module_index.json", json_encode($module_index, JSON_PRETTY_PRINT));
|
||||
echo("done\n");
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
////////////////////////// Build New Target //////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
require("pack.php");
|
||||
|
||||
?>
|
||||
|
|
3
build.sh
3
build.sh
|
@ -1,5 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
echo Deleting old index.php
|
||||
rm build/index.php
|
||||
php rebuild_module_index.php
|
||||
php build.php
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
function download()
|
||||
{
|
||||
var url = "build.php?web=true&modules=",
|
||||
var url = "pack.php?web=true&modules=",
|
||||
checkboxes = document.querySelectorAll("input[type=checkbox]");
|
||||
for(var i = 0; i < checkboxes.length; i++)
|
||||
{
|
||||
|
|
79
pack.php
Normal file
79
pack.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
if(php_sapi_name() == "cli")
|
||||
{
|
||||
echo("*** Beginning main build sequence ***\n");
|
||||
echo("Reading in module index...\n");
|
||||
}
|
||||
|
||||
$module_index = json_decode(file_get_contents("module_index.json"));
|
||||
$module_list = [];
|
||||
foreach($module_index as $module)
|
||||
{
|
||||
$module_list[] = $module->id;
|
||||
}
|
||||
|
||||
if(isset($_GET["modules"]))
|
||||
{
|
||||
$module_list = explode(",", $_GET["modules"]);
|
||||
}
|
||||
|
||||
if(php_sapi_name() != "cli")
|
||||
{
|
||||
header("content-type: text/php");
|
||||
}
|
||||
|
||||
if(php_sapi_name() == "cli") echo("Reading in core files...");
|
||||
|
||||
$core = file_get_contents("core.php");
|
||||
$settings = file_get_contents("settings.fragment.php");
|
||||
$settings = str_replace([ "<?php", "?>" ], "", $settings);
|
||||
$core = str_replace("{settings}", $settings, $core);
|
||||
|
||||
$result = $core;
|
||||
|
||||
foreach($module_list as $module_id)
|
||||
{
|
||||
if($module_id == "") continue;
|
||||
|
||||
if(php_sapi_name() == "cli") echo("Adding $module_id\n");
|
||||
|
||||
$module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module_id) . ".php";
|
||||
|
||||
//echo("id: $module_id | filepath: $module_filepath\n");
|
||||
|
||||
if(!file_exists($module_filepath))
|
||||
{
|
||||
http_response_code(400);
|
||||
exit("Failed to load module with name: $module_filepath");
|
||||
}
|
||||
|
||||
$modulecode = file_get_contents($module_filepath);
|
||||
$modulecode = str_replace([ "<?php", "?>" ], "", $modulecode);
|
||||
$result = str_replace(
|
||||
"// %next_module% //",
|
||||
"$modulecode\n// %next_module% //",
|
||||
$result);
|
||||
}
|
||||
|
||||
if(php_sapi_name() == "cli")
|
||||
{
|
||||
if(file_exists("build/index.php"))
|
||||
{
|
||||
echo("index.php already exists in the build folder, exiting\n");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo("Done. Saving to disk...");
|
||||
file_put_contents("build/index.php", $result);
|
||||
echo("complete!\n");
|
||||
echo("*** Build completed! ***\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exit($result);
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
echo("Rebuilding module index...\n");
|
||||
$modules = glob("modules/*.php");
|
||||
$module_index = [];
|
||||
|
||||
function register_module($settings)
|
||||
{
|
||||
global $module_index;
|
||||
$newmodule = [
|
||||
"name" => $settings["name"],
|
||||
"version" => $settings["version"],
|
||||
"author" => $settings["author"],
|
||||
"description" => $settings["description"],
|
||||
"id" => $settings["id"],
|
||||
"lastupdate" => filemtime("modules/" . $settings["id"] . ".php")
|
||||
];
|
||||
$module_index[] = $newmodule;
|
||||
}
|
||||
|
||||
foreach($modules as $filename)
|
||||
{
|
||||
echo("Processing $filename\n");
|
||||
require($filename);
|
||||
}
|
||||
|
||||
echo("*** Processing Complete ***\n");
|
||||
|
||||
echo("Writing new module index to disk...");
|
||||
file_put_contents("module_index.json", json_encode($module_index, JSON_PRETTY_PRINT));
|
||||
echo("done\n");
|
||||
|
||||
?>
|
Loading…
Reference in a new issue