Skip to content

Commit

Permalink
feat: seed and migrations examples and some optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Argenis Chavarria authored and Argenis Chavarria committed Sep 22, 2024
1 parent 6685dc0 commit ca44ee4
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 178 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Advanced WordPress starter theme with Tailwind CSS, Laravel Blade and Vite
## Requirements

- [Acorn](https://roots.io/acorn/docs/installation/) v4
- [PHP](https://secure.php.net/manual/en/install.php) >= 8.1
- [Node](http://nodejs.org/) >= 16.0.0
- [PHP](https://secure.php.net/manual/en/install.php) >= 8.2
- [Node](http://nodejs.org/) >= 20.0.0
- [Yarn](https://yarnpkg.com/en/docs/install)
- WSL is not required

Expand Down
5 changes: 3 additions & 2 deletions app/Classes/Vite.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,12 @@ public function manifestHash($buildDirectory = null)
protected function chunk($manifest, $file)
{
$file = basename($file);
if (! isset($manifest[$file])) {
$fileName = pathinfo($file)['extension'] == "ts" ? basename($file, '.ts') . '.js' : $file;
if (! isset($manifest[$fileName])) {
throw new Exception("Unable to locate file in Vite manifest: {$file}.");
}

return ['file'=> $manifest[$file]];
return ['file'=> $manifest[$fileName]];
}

/**
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
},
"require": {
"php": ">=8.2",
"log1x/acf-composer": "^3.1",
"log1x/navi": "^3.0",
"log1x/poet": "^2.1.0",
"roots/acorn": "^4.3.0"
},
Expand Down
53 changes: 53 additions & 0 deletions config/acf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Default Field Type Settings
|--------------------------------------------------------------------------
|
| Here you can set default field group and field type configuration that
| is then merged with your field groups when they are composed.
|
| This allows you to avoid the repetitive process of setting common field
| configuration such as `ui` on every `trueFalse` field or your
| preferred `instruction_placement` on every `fieldGroup`.
|
*/

'defaults' => [
// 'trueFalse' => ['ui' => 1],
// 'select' => ['ui' => 1],
],

/*
|--------------------------------------------------------------------------
| Custom Field Types
|--------------------------------------------------------------------------
|
| Here you can define custom field types that are not included with ACF
| out of the box. This allows you to use the fluent builder pattern with
| custom field types such as `addEditorPalette()`.
|
*/

'types' => [
// 'editorPalette' => 'editor_palette',
// 'phoneNumber' => 'phone_number',
],

/*
|--------------------------------------------------------------------------
| Cache Manifest Path
|--------------------------------------------------------------------------
|
| Here you can define the cache manifest path. Fields are typically cached
| when running the `acf:cache` command. This will cache the built field
| groups and potentially improve performance in complex applications.
|
*/

'manifest' => storage_path('framework/cache'),

];
28 changes: 28 additions & 0 deletions database/migrations/2024_09_22_211216_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// Schema::create('test_table', function (Blueprint $table) {
// $table->increments('id');
// $table->string('name');
// $table->timestamps();
// });
}

/**
* Reverse the migrations.
*/
public function down(): void
{
// Schema::dropIfExists('test_table');
}
};
21 changes: 21 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
TermsPageSeeder::class,
]);

}
}
55 changes: 55 additions & 0 deletions database/seeders/TermsPageSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class TermsPageSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
// CHECK IF THE PAGE 'TERMS' EXIST
$existingPage = DB::table('posts')
->where('post_type', 'page')
->where(function ($query) {
$query->where('post_title', 'Terms')
->orWhere('post_name', 'terms');
})
->first();

if (!$existingPage) {
// CREATE THE TERMS PAGE IN WORDPRESS
$id = DB::table("posts")->insertGetId([
'post_author' => 1,
'post_date' => now(),
'post_date_gmt' => now(),
'post_content' => '',
'post_title' => 'Terms',
'post_excerpt' => '',
'post_status' => 'publish',
'comment_status' => 'open',
'ping_status' => 'open',
'to_ping' => '',
'pinged' => '',
'post_content_filtered' => '',
'post_name' => 'terms',
'post_modified' => now(),
'post_modified_gmt' => now(),
'post_type' => 'page',
]);

// ASIGN THE TEMPLATE TO THE PAGE
DB::table('postmeta')->insert([
'post_id' => $id,
'meta_key' => '_wp_page_template',
'meta_value' => 'template-custom.blade.php',
]);
}
}
}
5 changes: 1 addition & 4 deletions resources/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import.meta.glob([
'../fonts/**',
]);

import ExampleAjax from './exampleAjax';

/**
* Application entrypoint
* Here you can write your global custom scripts
*/
addEventListener('DOMContentLoaded', async () => {

console.log('Sage Vite is ready! 🎉');

// (new ExampleAjax).hello();


});
17 changes: 12 additions & 5 deletions resources/scripts/exampleAjax.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
export default class ExampleAjax{


ensureTrailingSlash(url) {
if (!url.endsWith('/')) {
url += '/';
}
return url;
}

hello(){

let url = document.querySelector('meta[name=base]').getAttribute('content')

// // Get admin-ajax.php URL
const ajaxURL: string = url + "wp-admin/admin-ajax.php";
const ajaxURL: string = this.ensureTrailingSlash(url) + "wp-admin/admin-ajax.php";
// create the params
const params = new URLSearchParams({
action: 'example_ajax_func',
Expand All @@ -23,4 +30,4 @@ export default class ExampleAjax{
console.log(response);
})
}
}
}
7 changes: 7 additions & 0 deletions resources/scripts/pages/front-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Here you can write your custom scripts that will be loaded only on the front page.

import ExampleAjax from '@scripts/exampleAjax';

console.log('Front page script is ready! 🎉');

(new ExampleAjax).hello(); // Example of how to use the ExampleAjax class
8 changes: 5 additions & 3 deletions resources/views/front-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

@section('content')


<div class="max-w-[600px] mx-auto mt-4">

<img class="rounded" src="{{ Vite::asset('resources/images/sage-vite.png') }}" alt="Sage + Vite Logo">
Expand All @@ -19,10 +18,13 @@
</ul>

@else
<p>You don't have pokemons :( </p>
<p>You don't have pokemons :( </p>
@endif

</div>


@endsection

@section('footer_scripts')
<script type="module" src="{!! Vite::asset('resources/scripts/pages/front-page.ts') !!}"></script>
@endsection
2 changes: 2 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@

@php(do_action('get_footer'))
@php(wp_footer())
@yield('footer_scripts')

</body>
</html>
Loading

0 comments on commit ca44ee4

Please sign in to comment.