Skip to content

Commit

Permalink
Finally fixed previous issues that were not committed
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardosahon committed Dec 23, 2023
1 parent f25f8f0 commit 9492ea9
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 59 deletions.
16 changes: 16 additions & 0 deletions src/BobDBuilder/BobExec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace BrickLayer\Lay\BobDBuilder;

class BobExec
{
public function __construct(string $command)
{
$command = "php bob $command";

new Engine(
explode(" ", $command),
true
);
}
}
6 changes: 3 additions & 3 deletions src/BobDBuilder/Cmd/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Make implements CmdLayout
use Domain;
use Brick;

private readonly EnginePlug $plug;
private readonly array $tags;
private readonly string $internal_dir;
private EnginePlug $plug;
private array $tags;
private string $internal_dir;

public function _init(EnginePlug $plug): void
{
Expand Down
23 changes: 20 additions & 3 deletions src/BobDBuilder/Cmd/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BrickLayer\Lay\BobDBuilder\Cmd;

use BrickLayer\Lay\BobDBuilder\BobExec;
use BrickLayer\Lay\BobDBuilder\EnginePlug;
use BrickLayer\Lay\BobDBuilder\Interface\CmdLayout;
use BrickLayer\Lay\Core\Traits\IsSingleton;
Expand All @@ -11,13 +12,13 @@ class Project implements CmdLayout
{
use IsSingleton;

private readonly EnginePlug $plug;
private readonly array $tags;
private EnginePlug $plug;
private array $tags;

public function _init(EnginePlug $plug): void
{
$this->plug = $plug;
$plug->add_arg($this, ["project:create"], 'project_create', true);
$plug->add_arg($this, ["project:create"], 'project_create', true, 0);
}

public function _spin(): void
Expand All @@ -33,10 +34,13 @@ public function _spin(): void
public function create(): void
{
$cmd = $this->tags['project_create'][0] ?? null;
$tag = $this->tags['project_create'][1] ?? "";

if (!$cmd)
return;

$tag = trim($tag);

$server = $this->plug->server;

// copy env file if it doesn't exist
Expand All @@ -48,5 +52,18 @@ public function create(): void

// copy helper js file to project lay folder
new LayCopyDir($server->lay_static . "js", $server->shared . "lay");

if($tag == "--fresh-project") {
$this->plug->write_info("Fresh project detected!");

// create a default domain folder
new BobExec("make:domain Default * --force --silent");

// link lay folder to default folder
$s = DIRECTORY_SEPARATOR;
new BobExec("link:dir web{$s}shared{$s}lay web{$s}domains{$s}Default{$s}lay --silent");

$this->plug->write_info("Default domain folder created successfully!");
}
}
}
2 changes: 1 addition & 1 deletion src/BobDBuilder/Cmd/Symlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Symlink implements CmdLayout
{
use IsSingleton;

private readonly EnginePlug $plug;
private EnginePlug $plug;

public function _init(EnginePlug $plug): void
{
Expand Down
25 changes: 14 additions & 11 deletions src/BobDBuilder/Cmd/Traits/Make/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function domain(): void
. "Example: 'case-study'\n"
);

if (empty($pattern) || trim($pattern) == "*")
if (empty($pattern) || (!$this->plug->is_internal && trim($pattern) == "*"))
$this->plug->write_warn(
"Pattern cannot be an empty quote or '*'\n"
. "\n"
Expand All @@ -42,7 +42,7 @@ public function domain(): void


$domain = explode(" ", ucwords($domain));
$domain_id = implode("-", $domain) . "-id";
$domain_id = strtolower(implode("-", $domain) . "-id");
$domain = implode("", $domain);
$domain_dir = $this->plug->server->domains . $domain;
$exists = is_dir($domain_dir);
Expand Down Expand Up @@ -162,7 +162,7 @@ public function update_general_domain_entry(string $domain, string $domain_id, s
copy($main_file, $lock_file);

$file = new SplFileObject($lock_file, 'r+');
$file->setFlags(SplFileObject::DROP_NEW_LINE | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
$file->setFlags(SplFileObject::DROP_NEW_LINE);

$page = [];
$domains = [];
Expand All @@ -174,7 +174,7 @@ public function update_general_domain_entry(string $domain, string $domain_id, s
while (!$file->eof()) {
$entry = $file->fgets();

if($page_index > 0 && empty($entry))
if($page_index > 7 && empty($entry))
continue;

if (str_starts_with($entry, "Domain::new()"))
Expand All @@ -185,8 +185,8 @@ public function update_general_domain_entry(string $domain, string $domain_id, s
$domains[$key][] = $entry;

if(
$this->plug->force &&
$existing_domain_key !== null
$existing_domain_key === null &&
$this->plug->force
) {
if(
str_starts_with(ltrim($entry), "id:")
Expand Down Expand Up @@ -218,8 +218,12 @@ public function update_general_domain_entry(string $domain, string $domain_id, s
$page_index++;
}

$default_domain = end($domains);
array_pop($domains);
$default_domain = [];

if(!$this->plug->is_internal) {
$default_domain = end($domains);
array_pop($domains);
}

if($existing_domain_key)
unset($domains[$existing_domain_key]);
Expand All @@ -235,9 +239,8 @@ public function update_general_domain_entry(string $domain, string $domain_id, s
];

try{
array_push($page, "", ...$domains, ...[""], ...$new_domain, ...[""], ...$default_domain);

$file->seek(0);
array_push($page, "", ...$domains, ...[""], ...$new_domain, ...[""], ...$default_domain, ...[""]);
$file->rewind();
$file->fwrite(implode("\n", $page));
} catch (\Exception $e) {
Exception::throw_exception($e->getMessage(), "MakeDomain");
Expand Down
66 changes: 39 additions & 27 deletions src/BobDBuilder/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ class Engine
public EnginePlug $plug;

public function __construct(
private array $args
private array $args,
private readonly bool $is_internal = false
)
{
$show_help = array_search("--help", $this->args, true);
$show_help = $show_help === false ? array_search("--h", $this->args, true) : $show_help;

if ($show_help !== false) {
unset($this->args[$show_help]);
$show_help = true;
}

$force_action = array_search("--force", $this->args, true);
$force_action = $force_action === false ? array_search("--f", $this->args, true) : $force_action;

if ($force_action !== false) {
unset($this->args[$force_action]);
$force_action = true;
}
$force = $this->extract_global_tag("--force", "-f");
$show_help = $this->extract_global_tag("--help", "-h");
$silent = $this->extract_global_tag("--silent", "-s");

$this->plug = new EnginePlug($this->args);
$this->plug->is_internal = $this->is_internal;

$this->plug->force = $force_action ?? false;
$this->plug->show_help = $show_help ?? false;
$this->plug->force = $force;
$this->plug->show_help = $show_help;
$this->plug->silent = $silent;

foreach ($this->args as $i => $arg) {
if($this->plug->run($i, $arg) == CustomContinueBreak::BREAK)
Expand Down Expand Up @@ -61,20 +52,41 @@ public function __construct(

// End Bob execution
if(empty($this->plug->active_cmd))
$this->plug->write_info(
$this->plug->write_warn(
"-- Bob has determined that the current command is invalid\n"
. "-- Please use --help to see the list of available commands"
, ["current_cmd" => $this->plug->typed_cmd]
);

$this->plug->write_success(
"\n" . (
isset($this->plug->active_cmd_class) ?
"-- Operation completed!" :
""
),
['close_talk' => true]
);
if(!$this->plug->silent)
$this->plug->write_success(
"\n" . (
isset($this->plug->active_cmd_class) ?
"-- Operation completed!" :
""
),
['close_talk' => true]
);
}

public function extract_global_tag(string ...$tags) : bool
{
$out = false;

foreach ($tags as $tag) {
if($out !== false)
break;

$out = array_search($tag, $this->args, true);

}

if ($out !== false) {
unset($this->args[$out]);
$out = true;
}

return $out;
}

public function intro(bool $close_talk = true): void
Expand Down
9 changes: 5 additions & 4 deletions src/BobDBuilder/EnginePlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class EnginePlug
public bool $show_intro = true;
public bool $show_help = false;
public bool $force = false;
public bool $silent = false;
public bool $cmd_found = false;
public bool $is_internal = false;
public array $tags = [];
public array $plugged_args = [];
public string $typed_cmd = "";
Expand Down Expand Up @@ -200,7 +202,6 @@ public function write_fail(string $message, array $opts = []) : void {
}

public function write_talk(string $message, array $opts = []) : void {
$opts['color'] = "red";
$this->write($message, CmdOutType::TALK, $opts);
}

Expand All @@ -214,7 +215,7 @@ public function write_warn(string $message, array $opts = []) : void {
public function write(string $message, ?CmdOutType $type = null, array $opts = []): void
{
$kill = $opts['kill'] ?? false;
$open_talk = $opts['open_talk'] ?? false;
$open_talk = $opts['open_talk'] ?? false;
$close_talk = $opts['close_talk'] ?? false;
$current_cmd = $this->active_cmd ?: ($opts['current_cmd'] ?? "");
$hide_cur_cmd = $opts['hide_current_cmd'] ?? true;
Expand All @@ -236,7 +237,7 @@ public function write(string $message, ?CmdOutType $type = null, array $opts = [
"InvalidConsoleColor"
);

if ($open_talk)
if ($open_talk && !$this->silent)
Console::log("(^_^) Bob is Building --::--", Foreground::light_gray);

if (!$hide_cur_cmd && !empty($current_cmd)) {
Expand Down Expand Up @@ -283,7 +284,7 @@ public function write(string $message, ?CmdOutType $type = null, array $opts = [
Console::log($m, $color);
}

if ($close_talk)
if ($close_talk && !$this->silent)
Console::log("(-_-) Bob is Done -----", Foreground::light_gray);

Console::bell();
Expand Down
1 change: 0 additions & 1 deletion src/Core/View/DomainResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public static function set_res(string $key, mixed $value) : void
'img' => 'string',
'js' => 'string',
'shared' => 'object [root, static, css, img, js, img_default [object [logo, favicon, icon, meta]]]',
'server' => 'object',
'domain' => 'object',
'lay' => 'object [uri, root]',
])]
Expand Down
4 changes: 3 additions & 1 deletion src/Core/View/ViewSrc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
declare(strict_types=1);
namespace BrickLayer\Lay\Core\View;

use BrickLayer\Lay\Core\LayConfig;

final class ViewSrc {
public static function gen(string $src) : string
{
Expand All @@ -28,7 +30,7 @@ public static function gen(string $src) : string
if(!str_starts_with($src, $base))
return $src;

$local_file = str_replace($base, "", $src);
$local_file = str_replace($base, $client->domain->domain_root, $src);

$src .= "?mt=" . @filemtime($local_file);

Expand Down
11 changes: 4 additions & 7 deletions src/static/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ $lay.page = {
title : $id("LAY-PAGE-TITLE").content,
title_full : $id("LAY-PAGE-TITLE-FULL").innerHTML,
desc : $attr($id("LAY-PAGE-DESC"),"content"),
type : $attr($id("LAY-PAGE-TYPE"),"content"),
url : $attr($id("LAY-PAGE-URL"),"content"),
urlFull : $attr($id("LAY-PAGE-FULL-URL"),"content"),
img : $attr($id("LAY-PAGE-IMG"),"content"),
Expand All @@ -16,12 +15,10 @@ $lay.src = {
base : $id("LAY-PAGE-BASE").href,
api : $id('LAY-API').value + "?c=",
serve : $id('LAY-API').value,
custom_img : $id("LAY-CUSTOM-IMG").value,
back_img : $id("LAY-BACK-IMG").value,
front_img : $id("LAY-FRONT-IMG").value,
front_root : $id("LAY-FRONT-ROOT").value,
back_root : $id("LAY-BACK-ROOT").value,
custom_root : $id("LAY-CUSTOM-ROOT").value,
shared_root : $id('LAY-SHARED-ROOT').value,
shared_img : $id('LAY-SHARED-IMG').value,
domain_root : $id('LAY-DOMAIN-ROOT').value,
domain_img : $id('LAY-DOMAIN-IMG').value,
uploads : $id("LAY-UPLOAD").value,
}
$lay.fn = {
Expand Down
2 changes: 1 addition & 1 deletion src/static/js/constants.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9492ea9

Please sign in to comment.