-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
462 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
/testing/ | ||
/lemon/kernel | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
require "templates.php"; | ||
require "licenses.php"; | ||
|
||
/* | ||
* | ||
* Class for build command | ||
* | ||
* Can build project or license | ||
* | ||
* */ | ||
class Builder | ||
{ | ||
// List of all arguments provided by user | ||
private $arguments; | ||
|
||
/* | ||
* | ||
* Assigns arguments | ||
* | ||
* @param array $arguments; | ||
* | ||
* */ | ||
public function __construct($arguments) | ||
{ | ||
$this->arguments = $arguments; | ||
} | ||
|
||
/* | ||
* | ||
* Parses arguments to associative array | ||
* | ||
* @param array $arguments | ||
* | ||
* */ | ||
private function parse($arguments) | ||
{ | ||
$parsed = []; | ||
foreach($this->arguments as $argument) | ||
{ | ||
if(str_contains($argument, ":")) | ||
{ | ||
$argument = explode(':', $argument); | ||
$parsed[$argument[0]] = $argument[1]; | ||
} | ||
} | ||
|
||
return $parsed; | ||
} | ||
|
||
/* | ||
* | ||
* Executes specific builder | ||
* | ||
* Executing is provided by argument `type` | ||
* | ||
* */ | ||
public function execute() | ||
{ | ||
global $types; | ||
$arguments = $this->parse($this->arguments); | ||
if (!isset($arguments["type"])) | ||
{ | ||
echo textFormat("Type argument is missing!\n", 31); | ||
return; | ||
} | ||
if(in_array($arguments["type"], $types)) | ||
{ | ||
$action = $arguments["type"]; | ||
$this->$action($arguments); | ||
return; | ||
} | ||
echo textFormat("Type not found!\n", 31); | ||
} | ||
|
||
/* | ||
* | ||
* Builds starting project | ||
* | ||
* */ | ||
private function project() | ||
{ | ||
global $dirs; | ||
global $files; | ||
|
||
echo textFormat("\nBuilding project...\n\n", "33"); | ||
foreach ($dirs as $dir) | ||
{ | ||
if(!file_exists($dir)) | ||
{ | ||
echo textFormat("Building {$dir}...\n", "33"); | ||
mkdir($dir); | ||
} | ||
} | ||
foreach ($files as $file => $link) | ||
{ | ||
echo textFormat("Building {$file}...\n", "33"); | ||
$file = fopen($file, "w"); | ||
$content = file_get_contents($link); | ||
fwrite($file, $content); | ||
} | ||
echo textFormat("\nDone!\n\n", "33"); | ||
} | ||
|
||
/* | ||
* | ||
* Provider of generating license | ||
* | ||
* Generator is in LicenseBuilder class | ||
* | ||
* */ | ||
private function license() | ||
{ | ||
$licenses = new LicenseBuilder(); | ||
|
||
$licenses->buildLicense(); | ||
|
||
|
||
|
||
} | ||
} | ||
|
||
/* | ||
* | ||
* Function for creating Builder instance | ||
* | ||
* @param array $arguments | ||
* | ||
* */ | ||
function build($arguments) | ||
{ | ||
$builder = new Builder($arguments); | ||
|
||
$builder->execute(); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
require "templates.php"; | ||
|
||
/* | ||
* | ||
* Class for building licenses using interactive command | ||
* | ||
* */ | ||
class LicenseBuilder | ||
{ | ||
// License parameters | ||
private $parameters = [ | ||
"license" => "", | ||
"author" => "", | ||
"date" => "" | ||
]; | ||
|
||
/* | ||
* | ||
* Starts interactive command | ||
* | ||
* */ | ||
public function __construct() | ||
{ | ||
echo textFormat("License Builder\n\n", "33"); | ||
$this->licenseType(); | ||
} | ||
|
||
/* | ||
* | ||
* Assigns license type | ||
* | ||
* */ | ||
private function licenseType() | ||
{ | ||
global $licenses; | ||
$type = readline("Type license you want to build: "); | ||
|
||
if (isset($licenses[$type])) | ||
{ | ||
$this->parameters["license"] = $type; | ||
$this->licenseAuthor(); | ||
$this->parameters["date"] = date("Y"); | ||
return; | ||
} | ||
|
||
if ($type == "custom") | ||
{ | ||
$license = readline("Type your license content: "); | ||
$this->parameters["license"] = $license; | ||
return; | ||
} | ||
|
||
echo textFormat("This license is not available!\n", "31"); | ||
$this->licenseType(); | ||
|
||
} | ||
|
||
/* | ||
* | ||
* Assigns license author | ||
* | ||
* */ | ||
private function licenseAuthor() | ||
{ | ||
$name = readline("Type author name: "); | ||
|
||
if ($name != null) | ||
{ | ||
$this->parameters["author"] = $name; | ||
return; | ||
} | ||
|
||
echo textFormat("Name must be specified!\n", "31"); | ||
$this->licenseAuthor(); | ||
} | ||
|
||
/* | ||
* | ||
* Builds whole license file | ||
* | ||
* */ | ||
public function buildLicense() | ||
{ | ||
global $licenses; | ||
$file = fopen("LICENSE.md", "w"); | ||
$license = $this->parameters["license"]; | ||
|
||
if (!in_array($license, $licenses)) | ||
{ | ||
echo textFormat("Building license...\n", "33"); | ||
fwrite($file, $license); | ||
echo textFormat("Done!\n", "33"); | ||
return; | ||
} | ||
$content = file_get_contents($licenses[$license]); | ||
$content = str_replace("<copyright holders>", $this->parameters["author"], $content); | ||
$content = str_replace("<date>", $this->parameters["date"], $content); | ||
echo textFormat("Building license...\n", "33"); | ||
fwrite($file, $content); | ||
echo textFormat("Done!\n\n", "33"); | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* | ||
* Builders variables | ||
* | ||
* */ | ||
|
||
// List of supported arguments | ||
$arg_list = [ | ||
"type", | ||
]; | ||
|
||
// List of builder types | ||
$types = [ | ||
"project", | ||
"license" | ||
]; | ||
|
||
|
||
// List of project directories | ||
$dirs = [ | ||
"public", | ||
"views", | ||
"routes", | ||
"controllers", | ||
]; | ||
|
||
// List of project files | ||
$files = [ | ||
"public/index.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/index.php", | ||
"routes/web.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/web_routes.php" | ||
]; | ||
|
||
|
||
// List of supported licenses | ||
$licenses = [ | ||
"mit" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/licences/mit.txt", | ||
"apache" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/licences/apache.txt" | ||
|
||
]; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
require "info.php"; | ||
require __DIR__."/../Server/server.php"; | ||
require __DIR__."/../Builders/builder.php"; | ||
|
||
/* | ||
* | ||
* List of all commands | ||
* | ||
* */ | ||
$commands = [ | ||
"-h" => "help", | ||
"-i" => "info", | ||
"-v" => "version", | ||
"serve" => "serve", | ||
"build" => "build", | ||
|
||
]; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
// Formats text with color | ||
function textFormat($text, $color) | ||
{ | ||
return "\033[{$color}m{$text}\033[0m"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
// Importing text format for better colors | ||
require "helpers.php"; | ||
|
||
// List of all commands | ||
$help = " | ||
-h Shows this help | ||
-i Shows info about lemon | ||
-v Shows version of Lemon | ||
serve Starts development server | ||
build type:project - Builds starter project | ||
:license - Builds license | ||
"; | ||
|
||
$version = "2.0.0"; | ||
|
||
// Shows help | ||
function help() | ||
{ | ||
global $help; | ||
|
||
echo textFormat("\n\u{1F34B} Lemon help\n", "33"); | ||
echo $help; | ||
|
||
} | ||
|
||
// Shows info about project | ||
function info() | ||
{ | ||
global $version; | ||
|
||
echo textFormat("\n\u{1F34B} Lemon info\n", "33"); | ||
echo "\nLemon is simple micro framework that provides routing, etc.\n"; | ||
echo "Developed by TEN MAJKL -> Version {$version}\n\n"; | ||
} | ||
|
||
// Show version | ||
function version() | ||
{ | ||
global $version; | ||
|
||
echo textFormat("\n\u{1F34B} Lemon version\n", "33"); | ||
echo "\n->{$version}\n"; | ||
} | ||
|
||
?> |
Oops, something went wrong.