Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Add : Docgenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
drajathasan committed Dec 26, 2020
1 parent af6abe6 commit f65dd8e
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 95 deletions.
76 changes: 76 additions & 0 deletions src/SLiMSTarsius/Docgenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* @author Drajat Hasan
* @email [email protected]
* @create date 2020-12-26 23:23:54
* @modify date 2020-12-27 00:20:24
* @desc [description]
*/

namespace SLiMSTarsius;

class Docgenerator
{
public static function banner()
{
echo " _____ _
|_ _|_ _ _ __ ___(_)_ _ ___
| |/ _` | '__/ __| | | | / __|
| | (_| | | \__ \ | |_| \__ \
|_|\__,_|_| |___/_|\__,_|___/
";
echo "\t\t\t v1.1.0 \n";
}
public static function firstMeet()
{
// Greeting
self::banner();
echo "\n Hai, ini tarsius perkakas pengembangan untuk \e[36mSLiMS \033[0m:D\n";
// usage documentation
self::usage();
}

public static function usage()
{
// Start doc
echo "\n\e[33m Penggunaan \033[0m\n";
echo "\n";
echo " php tarsius [perintah] [parameter]";
echo "\n";
echo "\n\e[33m Perintah Tersedia \033[0m\n";
/* Plugin */
echo "\n\e[36m --plugin \033[0m";
echo "\n\e[32m --plugin:create \033[0m\tMembuat kerangka dasar plugin (mode non-hook)";
echo "\n\e[32m --plugin:enable \033[0m\tMengaktifkan plugin (fitur mendatang)";
echo "\n\e[32m --plugin:disable \033[0m\tMeng-non-aktifkan plugin (fitur mendatang)";
echo "\n\e[32m --plugin:delete \033[0m\tMenghapus plugin (fitur mendatang)";
echo "\n\e[32m --plugin:list \033[0m\tMenampilkan plugin tersedia (fitur mendatang)";
echo "\n\e[32m --plugin:info \033[0m\tMenampilkan informasi plugin (fitur mendatang)\n";
/* Module */
echo "\n\e[36m --module \033[0m";
echo "\n\e[32m --module:create \033[0m\tMembuat kerangka dasar module (fitur mendatang)";
echo "\n\e[32m --module:list \033[0m\tMenampilkan module tersedia (fitur mendatang)";
echo "\n\e[32m --module:info \033[0m\tMenampilkan informasi module (fitur mendatang)\n";
/* Template */
echo "\n\e[36m --template \033[0m\t(fitur mendatang)\n";
/* Library */
echo "\n\e[36m --library \033[0m\t(fitur mendatang)\n";
/* REST APi */
echo "\n\e[36m --rest-api \033[0m\t(fitur mendatang)\n";
echo "\n\e[33m Contoh Penggunaan \033[0m\n";
echo "\n";

echo " php tarsius --plugin:create buku_induk\n";
echo "\n";
}

public static function failedMsg($message, $pointMessage)
{
die(str_replace("{pointMsg}", "\e[1m\e[31m$pointMessage\033[0m", "\n\e[1mError\033[0m:\n\n$message")."\n\n");
}

public static function successMsg($message, $pointMessage)
{
die(str_replace("{pointMsg}", "\e[1m\e[92m$pointMessage\033[0m", $message)."\n\n");
}
}
9 changes: 8 additions & 1 deletion src/SLiMSTarsius/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ public function compile()
else
{
$value = explode(':', $value);
$this->arguments[$map[$id]] = [str_replace('-', '', $value[0]), $value[1]];
if (isset($value[0]) && isset($value[1]))
{
$this->arguments[$map[$id]] = [str_replace('-', '', $value[0]), $value[1]];
}
else
{
\SLiMSTarsius\Docgenerator::firstMeet(); exit;
}
}
unset($this->arguments[$id]);
}
Expand Down
36 changes: 24 additions & 12 deletions src/SLiMSTarsius/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* @author Drajat Hasan
* @email [email protected]
* @create date 2020-12-26 17:02:45
* @modify date 2020-12-26 17:03:16
* @modify date 2020-12-27 00:20:27
*/

namespace SLiMSTarsius;

use \SLiMSTarsius\Docgenerator as dg;

class Plugin
{
public $env;
Expand All @@ -26,7 +28,7 @@ public function create($dest, $pluginName)
'version' => 'Version (Minimal gunakan semantic versioning)',
'author' => 'Author (Pembuat)',
'author_uri' => 'Author URI (Halaman profil pembuat)',
'target_module' => 'Modul tujuan?',
'target_module' => 'Modul tujuan',
'label_menu' => 'Teks yang muncul di Menu?'
];

Expand All @@ -35,13 +37,13 @@ public function create($dest, $pluginName)

if (count($pluginName) > 1)
{
die("Hanya bisa membuat 1 plugin dalam 1 perintah!\n");
dg::failedMsg("{pointMsg}", 'Hanya bisa membuat 1 plugin dalam 1 perintah!');
}

$pluginName = $pluginName[0];

// set message
echo 'Membuat plugin '.$pluginName."\n";
echo "\nMembuat plugin \e[36m$pluginName\033[0m\n\n";
// get information and make plugin
$this->makeInteractive($interactiveMap)
->makePlugin($pluginName, $destinantion, $template);
Expand All @@ -52,15 +54,15 @@ private function makeInteractive($label)
if (is_array($label))
{
foreach ($label as $key => $question) {
echo $question.' plugin? [tuliskan] ';
echo "\e[1m$question plugin?\033[0m [tuliskan] ";
$this->interactiveResponse[$key] = trim(fgets(STDIN));
}

return $this;
}
else
{
die('Label harus Array!');
dg::failedMsg("{pointMsg} harus Array!", 'Label');
}
}

Expand All @@ -78,8 +80,18 @@ private function makePlugin($pluginName, $destDir, $template)
$this->interactiveResponse['date_created'] = date('Y-m-d H:i:s');

foreach ($this->interactiveResponse as $key => $value) {
$dotPlugin = str_replace('{'.$key.'}', $value, $dotPlugin);
$indexPlugin = str_replace('{'.$key.'}', $value, $indexPlugin);
if (!empty(trim($this->interactiveResponse[$key])))
{
$dotPlugin = str_replace('{'.$key.'}', $value, $dotPlugin);
$indexPlugin = str_replace('{'.$key.'}', $value, $indexPlugin);
}
else
{
// remove directory
rmdir($destDir.$pluginName);
// set message
dg::failedMsg("Parameter {pointMsg} tidak boleh kosong!", $key);
}
}

try {
Expand All @@ -89,20 +101,20 @@ private function makePlugin($pluginName, $destDir, $template)

if ($dotPlugin && $indexPlugin)
{
echo "Berhasil membuat plugin $pluginName \n";
dg::successMsg("{pointMsg}", "\nBerhasil membuat plugin $pluginName");
}
} catch (\ErrorException $e) {
die("Gagal membuat plugin $pluginName : \n ".$e->getMessage());
dg::failedMsg("Gagal membuat plugin {pointMsg} : $e->getMessage()", $pluginName);
}
}
else
{
die('Gagal membuat direktori plugin!');
dg::failedMsg("{pointMsg}", "Gagal membuat direktori plugin");
}
}
else
{
die('Plugin sudah ada. Ingin membuat plugin lagi? Hapus plugin yang sudah ada.'."\n");
dg::failedMsg("{pointMsg}", "Plugin sudah ada. Ingin membuat plugin lagi? Hapus plugin yang sudah ada.");
}
}
}
24 changes: 17 additions & 7 deletions src/SLiMSTarsius/Tarmagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Drajat Hasan
* @email [email protected]
* @create date 2020-12-26 17:02:45
* @modify date 2020-12-26 17:03:16
* @modify date 2020-12-27 00:20:21
*/

namespace SLiMSTarsius;
Expand All @@ -17,7 +17,21 @@ class Tarmagick
public static function plugin($action)
{
self::getEnvironment(self::$dir);
echo (new \SLiMSTarsius\Plugin(self::$environment))->$action(self::$dir, self::$parameter);

try {
$Plugin = new \SLiMSTarsius\Plugin(self::$environment);

if (method_exists($Plugin, $action))
{
$Plugin->$action(self::$dir, self::$parameter);
}
else
{
throw new \ErrorException($action);
}
} catch (\ErrorException $e) {
\SLiMSTarsius\Docgenerator::failedMsg("Metode {pointMsg} tidak ada!", $e->getMessage());
}
}

public static function module($action)
Expand Down Expand Up @@ -60,14 +74,10 @@ public static function startup($mainDirectory)
self::$parameter = $parser->arguments['parameter'];
return self::$method($parser->arguments['method'][1]);
}
else
{
echo "Metode tidak tersedia!";
}
}
else
{
echo "Hai, ini tarsius perkakas pengemban untuk SLiMS :D \n";
\SLiMSTarsius\Docgenerator::firstMeet();
}
}
}
15 changes: 0 additions & 15 deletions tests/plugins/buku_induk/buku_induk.plugin.php

This file was deleted.

60 changes: 0 additions & 60 deletions tests/plugins/buku_induk/index.php

This file was deleted.

0 comments on commit f65dd8e

Please sign in to comment.