mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit f6aa26b316026d92d64bf64862463ca79fafc85c
parent 90fa5c3a661734baab00b353ab85193d4e27bea2
Author: markseu <mark2011@mayberg.se>
Date:   Wed, 23 Jan 2019 12:02:06 +0100

added serve command to static site generator

Diffstat:
Msystem/plugins/command.php | 26+++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/system/plugins/command.php b/system/plugins/command.php @@ -4,7 +4,7 @@ // This file may be used and distributed under the terms of the public license. class YellowCommand { - const VERSION = "0.7.13"; + const VERSION = "0.7.14"; public $yellow; //access to API public $files; //number of files public $links; //number of links @@ -25,6 +25,7 @@ class YellowCommand { case "build": $statusCode = $this->processCommandBuild($args); break; case "check": $statusCode = $this->processCommandCheck($args); break; case "clean": $statusCode = $this->processCommandClean($args); break; + case "serve": $statusCode = $this->processCommandServe($args); break; case "version": $statusCode = $this->processCommandVersion($args); break; default: $statusCode = 0; } @@ -36,16 +37,17 @@ class YellowCommand { $help .= "build [directory location]\n"; $help .= "check [directory location]\n"; $help .= "clean [directory location]\n"; + $help .= "serve [url]\n"; $help .= "version\n"; return $help; } // Process command to show available commands public function processCommandHelp() { - echo "Datenstrom Yellow ".YellowCore::VERSION."\n"; + echo "Datenstrom Yellow is for people who make websites.\n"; $lineCounter = 0; foreach ($this->getCommandHelp() as $line) { - echo(++$lineCounter>1 ? " " : "Syntax: ")."yellow.php $line\n"; + echo(++$lineCounter>1 ? " " : "Syntax: ")."php yellow.php $line\n"; } return 200; } @@ -427,6 +429,24 @@ class YellowCommand { } return $statusCode; } + + // Process command to start built-in web server + public function processCommandServe($args) { + list($command, $url) = $args; + if (empty($url)) $url = "http://localhost:8000"; + list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($url); + if ($scheme=="http" && !empty($address)) { + if (!preg_match("/\:\d+$/", $address)) $address .= ":8000"; + echo "Starting built-in web server on $scheme://$address\n"; + echo "Press Ctrl-C to quit...\n"; + system("php -S $address yellow.php", $returnStatus); + $statusCode = $returnStatus!=0 ? 500 : 200; + } else { + $statusCode = 400; + echo "Yellow $command: Invalid arguments\n"; + } + return $statusCode; + } // Process command to show software version and updates public function processCommandVersion($args) {