Skip to content

Commit

Permalink
laravel-projects/packages/onix automatic push
Browse files Browse the repository at this point in the history
  • Loading branch information
mariojgt committed Oct 21, 2024
1 parent 17acce6 commit 63eb9b4
Show file tree
Hide file tree
Showing 45 changed files with 1,540 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Publish/BladeLayout/onix.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{ $title ?? 'Onix Grape js' }}</title>
{{ Vite::useBuildDirectory('vendor/Onix')->withEntryPoints([
{{ Vite::useBuildDirectory('vendor/Onix/' . session('template'))->withEntryPoints([
'resources/vendor/Onix/js/app.js',
'resources/vendor/Onix/css/app.css',
]) }}
Expand Down
9 changes: 0 additions & 9 deletions Publish/Config/onix.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
| Onix editor css and js files
|--------------------------------------------------------------------------
*/
// Files base path (this is the location where the manifest.json file is located in the public folder)
'use_cdn' => true,
'editor_base_path' => 'vendor/Onix',
// The last name of you css file used in vite
'editor_css' => [
Expand All @@ -69,13 +67,6 @@
'editor_js' => [
'app.js',
],
// If you want to use cdn instead of the local files you can add the cdn url here dont forget to change the use_cdn to true
'editor_css_cdn' => [
'https://cdn.jsdelivr.net/npm/daisyui@2.51.3/dist/full.css',
],
'editor_js_cdn' => [
'https://cdn.tailwindcss.com',
],

// If you want to restrict the access to the editor you can add the middleware here
'middleware' => [
Expand Down
2 changes: 1 addition & 1 deletion Publish/Npm/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
])
],
build: {
outDir: 'public/vendor/Onix',
outDir: 'public/vendor/Onix/starter',
emptyOutDir: true,
rollupOptions: {
input: {
Expand Down
1 change: 1 addition & 0 deletions Publish/OnixPhpBlocks/Class/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Footer extends BaseOnixBlocks
{
public string $template = 'starter';
public string $componentId = 'footer';
public string $label = 'footer';
public string $mediaPath = 'footer-media';
Expand Down
1 change: 1 addition & 0 deletions Publish/OnixPhpBlocks/Class/HomePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class HomePage extends BaseOnixBlocks
{
public string $template = 'starter';
public string $componentId = 'home-page-example-01';
public string $label = 'homepage example 01';
public string $mediaPath = 'home-page-example-01-media';
Expand Down
1 change: 1 addition & 0 deletions Publish/OnixPhpBlocks/Class/Navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Navbar extends BaseOnixBlocks
{
public string $template = 'starter';
public string $componentId = 'navbar';
public string $label = 'navbar';
public string $mediaPath = 'mavbar-media';
Expand Down
1 change: 1 addition & 0 deletions Publish/OnixPhpBlocks/Class/TodoList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class TodoList extends BaseOnixBlocks
{
public string $template = 'starter';
public string $componentId = 'todo-list';
public string $label = 'Todo List';
public string $mediaPath = 'todo-list-media';
Expand Down
597 changes: 597 additions & 0 deletions Publish/Public/assets/grape-3d252b9a.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Publish/Public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"css": [
"assets/onixGrapeJs-328607b6.css"
],
"file": "assets/grape-f2380d7a.js",
"file": "assets/grape-3d252b9a.js",
"imports": [
"_sweetalert2-7c60aed3.js"
],
Expand Down
1 change: 1 addition & 0 deletions Publish/Public/starter/assets/app-339814be.js

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

1 change: 1 addition & 0 deletions Publish/Public/starter/assets/app-4c960b16.css

Large diffs are not rendered by default.

597 changes: 597 additions & 0 deletions Publish/Public/starter/assets/grape-b02a3bd2.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Publish/Public/starter/assets/onixGrapeJs-328607b6.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Publish/Public/starter/assets/sweetalert2-4370e638.css

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions Publish/Public/starter/assets/sweetalert2-7c60aed3.js

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions Publish/Public/starter/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"_sweetalert2-7c60aed3.js": {
"css": [
"assets/sweetalert2-4370e638.css"
],
"file": "assets/sweetalert2-7c60aed3.js"
},
"resources/vendor/Onix/css/app.css": {
"file": "assets/app-4c960b16.css",
"isEntry": true,
"src": "resources/vendor/Onix/css/app.css"
},
"resources/vendor/Onix/js/OnixSetup/onixGrapeJs.css": {
"file": "assets/onixGrapeJs-328607b6.css",
"src": "resources/vendor/Onix/js/OnixSetup/onixGrapeJs.css"
},
"resources/vendor/Onix/js/OnixSetup/onixGrapeJs.js": {
"css": [
"assets/onixGrapeJs-328607b6.css"
],
"file": "assets/grape-b02a3bd2.js",
"imports": [
"_sweetalert2-7c60aed3.js"
],
"isEntry": true,
"src": "resources/vendor/Onix/js/OnixSetup/onixGrapeJs.js"
},
"resources/vendor/Onix/js/app.js": {
"file": "assets/app-339814be.js",
"imports": [
"_sweetalert2-7c60aed3.js"
],
"isEntry": true,
"src": "resources/vendor/Onix/js/app.js"
},
"sweetalert2.css": {
"file": "assets/sweetalert2-4370e638.css",
"src": "sweetalert2.css"
}
}
12 changes: 6 additions & 6 deletions Publish/Resource/js/OnixSetup/helpers/onixEditorHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const updateEditorStyle = async () => {
/**
* Load the editor css and javascript files so we can use them in the editor
*/
const getSiteStyles = async () => {
const getSiteStyles = async (template) => {
try {
return await onixApi.get('/site-styles').then((response) => {
return await onixApi.get('/site-styles?template=' + template).then((response) => {
return response.data;
});
} catch (error) {
Expand Down Expand Up @@ -79,8 +79,8 @@ const startCodeEditor = async (editor) => {
}]);
};

const loadBlocks = async (editor) => {
await onixApi.get('/load/blocks').then((response) => {
const loadBlocks = async (editor, template) => {
await onixApi.get('/load/blocks?template=' + template).then((response) => {
const blocks = response.data.blocks;
// If we are editng a block prevent the block to add himself to the editor
blocks.forEach((block) => {
Expand Down Expand Up @@ -173,7 +173,7 @@ const saveEditorData = async (editor, silentSave = false) => {
};

// Load the page of the component we are editing
const loadEditorData = async (editor, mode = 'page', slug) => {
const loadEditorData = async (editor, mode = 'page', slug, template) => {
// Clear the local storage
localStorage.removeItem("onix-data");

Expand Down Expand Up @@ -204,7 +204,7 @@ const loadEditorData = async (editor, mode = 'page', slug) => {
// Automatically update the editor style when the page is loaded
await updateEditorStyle();
// Load the blocks so when we load load the page the blocks are up to date
await loadBlocks(editor);
await loadBlocks(editor, template);

// Get all the blocks from the editor
const blocks = editor.BlockManager.getAll();
Expand Down
6 changes: 3 additions & 3 deletions Publish/Resource/js/OnixSetup/onixGrapeJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const startOnixEditor = async (cssStyles = [], jsScripts = []) => {
};

// Create a function and export to the window so we can call and start the editor from the blade file
window.startEditor = async function (mode, slug) {
const styles = await getSiteStyles();
window.startEditor = async function (mode, slug, template) {
const styles = await getSiteStyles(template);
await startOnixEditor(styles.css, styles.js);
await loadEditorData(editor, mode, slug);
await loadEditorData(editor, mode, slug, template);
}
// Expose to the browser the save function so we can use it in the blade file
window.saveEditorData = function () {
Expand Down
11 changes: 6 additions & 5 deletions Publish/Resource/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ window.deploySite = async function (deployMode, codeFeedbackId) {
}, 1000);
});
} catch (error) {
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Something went wrong deploying the site!😭',
});
console.log(error);
// Swal.fire({
// icon: 'error',
// title: 'Oops...',
// text: 'Something went wrong deploying the site!😭',
// });
}
setTimeout(() => {
clearInterval(codeFeedbak);
Expand Down
4 changes: 4 additions & 0 deletions src/Commands/CreateOnixBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function __construct()
*/
public function handle()
{
// Ask for the template name
$templateName = $this->ask('What is the name of the template? example: starter');
// Ask for the block id
$componentId = $this->ask('What is the id of the block?');
// Ask for the block name
Expand All @@ -61,6 +63,7 @@ public function handle()
'{{contentPath}}',
'{{category}}',
'{{className}}',
'{{templateName}}'
],
'values' => [
$componentId,
Expand All @@ -69,6 +72,7 @@ public function handle()
$contentPath,
$category,
$className,
$templateName
]
];

Expand Down
23 changes: 11 additions & 12 deletions src/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Artisan;
use Illuminate\Console\Command;
use Mariojgt\Onix\Model\OnixSetting;
use Mariojgt\Onix\Database\Seeders\OnixSettingsSeeder;
use Mariojgt\Onix\Database\Seeders\OnixTemplateSeeder;

class Install extends Command
{
Expand Down Expand Up @@ -48,18 +49,16 @@ public function handle()
// Migrate
Artisan::call('migrate');

// Create the settings or update them
$onixSetting = OnixSetting::first();
if ($onixSetting) {
$onixSetting->delete();
}
// Call the seeder for the onix settings
Artisan::call('db:seed', [
'--class' => OnixSettingsSeeder::class,
'--force' => true,
]);

$onixSetting = new OnixSetting();
$onixSetting->color_primary = '#000000ff';
$onixSetting->color_secondary = '#14213dff';
$onixSetting->color_tertiary = '#fca311ff';
$onixSetting->color_quaternary = '#e5e5e5ff';
$onixSetting->save();
Artisan::call('db:seed', [
'--class' => OnixTemplateSeeder::class,
'--force' => true,
]);

$this->newLine();
$this->info('The command was successful!');
Expand Down
22 changes: 15 additions & 7 deletions src/Controllers/OnixApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Mariojgt\Onix\Model\OnixBlock;
use App\Http\Controllers\Controller;
use Mariojgt\Onix\Model\OnixSetting;
use Mariojgt\Onix\Model\OnixTemplate;
use SebastianBergmann\Template\Template;

class OnixApiController extends OnixController
{
Expand All @@ -27,15 +29,15 @@ public function config()
]);
}

public function getSiteStyles()
public function getSiteStyles(Request $request)
{
$cssFiles = [];
$jsFiles = [];
if (config('onix.use_cdn')) {
$cssFiles = config('onix.editor_css_cdn');
$jsFiles = config('onix.editor_js_cdn');
} else {
$basePath = config('onix.editor_base_path');

$template = OnixTemplate::where('slug', $request->template)->firstOrFail();
$basePath = config('onix.editor_base_path') . '/' . $template->slug;

if ($template->use_manifest) {
// Find the manifest file so we can get the css and js files
$manifest = json_decode(file_get_contents(public_path($basePath . '/manifest.json')), true);
foreach ($manifest as $key => $item) {
Expand All @@ -48,6 +50,10 @@ public function getSiteStyles()
$jsFiles[] = url($basePath . '/' . $item['file']);
}
}
} else {
// If the template is not using the manifest file we going to get the css and js files from the database
$cssFiles[] = url($basePath . '/' . $template->css_file);
$jsFiles[] = url($basePath . '/' . $template->js_file);
}

return response()->json([
Expand Down Expand Up @@ -112,7 +118,9 @@ public function loadBlocks(Request $request)
$className = pathinfo($file, PATHINFO_FILENAME);
$class = 'App\\Onix\\Blocks\\' . $className;
$instance = new $class();
$blocks[] = $instance->getBlock();
if ($instance->template === $request->template) {
$blocks[] = $instance->getBlock();
}
}

$onixDataBaseBlocks = OnixBlock::all();
Expand Down
13 changes: 8 additions & 5 deletions src/Controllers/OnixApiDeployController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public function __construct()

public function startDeploy(Request $request)
{
$request->validate([
$validation = $request->validate([
'mode' => 'required|in:blade, inersia',
]);

switch ($request->mode) {
switch ($validation['mode']) {
case 'blade':
$this->bladeFilesDeploy($request);
break;
Expand Down Expand Up @@ -82,7 +82,7 @@ public function readyDeployStatusFile(Request $request)
}
}

public function bladeFilesDeploy(Request $request)
public function bladeFilesDeploy(Request $request): bool
{
// Get all the pages
$pages = OnixPage::all();
Expand Down Expand Up @@ -110,6 +110,8 @@ public function bladeFilesDeploy(Request $request)
$replace
);
}

return true;
}

/**
Expand Down Expand Up @@ -141,14 +143,15 @@ private function runDeployCommand(Request $request)
fclose($file);
}

private function loadStubFileAndSave($stubFile, $saveFilePath, $fileName, $fileExtension = '.php', $replace = null)
private function loadStubFileAndSave($stubFile, $saveFilePath, $fileName, $fileExtension = '.php', $replace = null) : void
{
File::isDirectory($saveFilePath) or File::makeDirectory($saveFilePath, 0777, true, true);

$stub = file_get_contents(app_path('Onix/Stubs/' . $stubFile . '.stub'));
if (!empty($replace)) {
$stub = str_replace($replace['variables'], $replace['values'], $stub);
}
file_put_contents($saveFilePath . '/' . $fileName . $fileExtension, $stub);

return;
}
}
8 changes: 6 additions & 2 deletions src/Controllers/OnixBlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mariojgt\Onix\Model\OnixPage;
use Mariojgt\Onix\Model\OnixBlock;
use App\Http\Controllers\Controller;
use Mariojgt\Onix\Model\OnixTemplate;

class OnixBlockController extends OnixController
{
Expand All @@ -16,8 +17,9 @@ class OnixBlockController extends OnixController
public function index(Request $request)
{
$block = OnixBlock::all();
$templates = OnixTemplate::all()->pluck('name', 'id');

return view('onix::content.block.index', compact('block'));
return view('onix::content.block.index', compact('block', 'templates'));
}

/**
Expand Down Expand Up @@ -49,10 +51,12 @@ public function store(Request $request)
'label' => 'required',
'media' => 'required',
'category' => 'required',
'slug' => 'required|unique:onix_blocks'
'slug' => 'required|unique:onix_blocks',
'template_id' => 'required',
]);

$block = new OnixBlock();
$block->template_id = $request->template_id;
$block->componentId = $request->componentId;
$block->label = $request->label;
$block->slug = Str::slug($request->slug, '-');
Expand Down
Loading

0 comments on commit 63eb9b4

Please sign in to comment.