Skip to content

Commit 1a93159

Browse files
committed
Frontend, Item
1 parent b149e51 commit 1a93159

File tree

14 files changed

+541
-101
lines changed

14 files changed

+541
-101
lines changed

docs/_devlog/Alf.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ That is the rest of the old config:
2222
],
2323
```
2424

25+
- [ ] Implement Frontend class, abstract? See Frontend/Idea.md
2526
- [ ] Build Skeleton -> Item
2627
- [ ] Refactor core traits to base classes
2728
- [ ] Create Item

packages/frontend/CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# Changelog
22

33
We currently don't track changes in this package. Please refer to the [Moox Monorepo](https://github.com/mooxphp/moox) for the latest changes.
4-
5-
We'll add a changelog in the future.

packages/frontend/README.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,64 @@
1-
![Moox Frontend](https://github.com/mooxphp/moox/raw/main/art/banner/frontend-package.jpg)
1+
![Moox Frontend](https://github.com/mooxphp/moox/raw/main/art/banner/frontend.jpg)
22

33
# Moox Frontend
44

5-
Moox Frontend is a package that provides a modular frontend for a CMS, Shop, Blog or any other Laravel and Filament project, that needs a frontend. Moox Frontend provides
5+
Frontend is a Moox Package using Moox Skeleton.
66

7-
- Frontend routing for resources (items including taxonomies)
8-
- Resolving URL conflicts between resources
9-
- Theme support, using Moox Themes
10-
- A preview feature for unpublished or soft-deleted resources
7+
## Features
118

12-
And the Pro version adds:
9+
<!--features-->
1310

14-
- Caching, static HTML and using a CDN
11+
- Feature 1
12+
- Feature 2
13+
- Feature 3
1514

16-
## Quick Installation
15+
<!--/features-->
1716

18-
These two commmands are all you need to install the package:
17+
## Requirements
18+
19+
See [Requirements](https://github.com/mooxphp/moox/blob/main/docs/Requirements.md).
20+
21+
## Installation
1922

2023
```bash
2124
composer require moox/frontend
22-
php artisan frontend:install
25+
php artisan moox:install
2326
```
2427

25-
Curious what the install command does? See manual installation below.
28+
Curious what the install command does? See [Installation](https://github.com/mooxphp/moox/blob/main/docs/Installation.md).
2629

27-
## Manual Installation
30+
## Screenshot
2831

29-
Instead of using the install-command `php artisan frontend:install` you are able to install this package manually step by step:
32+
![Moox Frontend](https://github.com/mooxphp/moox/raw/main/art/screenshots/frontend.jpg)
3033

31-
```bash
32-
// Publish and run the migrations:
33-
php artisan vendor:publish --tag="frontend-migrations"
34-
php artisan migrate
34+
## Get Started
3535

36-
// Publish the config file with:
37-
php artisan vendor:publish --tag="frontend-config"
38-
```
36+
See [Get Started](docs/GetStarted.md).
37+
38+
## User Guide
39+
40+
See [User Guide](docs/UserGuide.md).
41+
42+
## Integration
43+
44+
See [Integration](docs/Integration.md).
3945

4046
## Changelog
4147

4248
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
4349

44-
## Security Vulnerabilities
50+
## Roadmap
51+
52+
Please see [ROADMAP](ROADMAP.md) for more information on what is planned for this package.
53+
54+
## Security
4555

4656
Please review [our security policy](https://github.com/mooxphp/moox/security/policy) on how to report security vulnerabilities.
4757

4858
## Credits
4959

50-
- [All Contributors](../../contributors)
60+
Thanks to so many [people for their contributions](https://github.com/mooxphp/moox#contributors) to this package.
5161

5262
## License
5363

54-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
64+
The MIT License (MIT). Please see [our license and copyright information](https://github.com/mooxphp/moox/blob/main/LICENSE.md) for more information.

packages/frontend/ROADMAP.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Roadmap
2+
3+
## Current tasks
4+
5+
- [ ] Create that package

packages/frontend/build.php

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
function ask(string $question, string $default = ''): string
6+
{
7+
$answer = readline($question.($default !== '' && $default !== '0' ? sprintf(' (%s)', $default) : null).': ');
8+
9+
if (! $answer) {
10+
return $default;
11+
}
12+
13+
return $answer;
14+
}
15+
16+
function confirm(string $question, bool $default = false): bool
17+
{
18+
$answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')');
19+
20+
if ($answer === '' || $answer === '0') {
21+
return $default;
22+
}
23+
24+
return strtolower($answer) === 'y';
25+
}
26+
27+
function isValidPackageName($packageName): bool
28+
{
29+
if (empty($packageName)) {
30+
return false;
31+
}
32+
33+
$reservedName = 'frontend';
34+
35+
return ! str_contains(strtolower((string) $packageName), $reservedName);
36+
}
37+
38+
function writeln(string $line): void
39+
{
40+
echo $line.PHP_EOL;
41+
}
42+
43+
function run(string $command): string
44+
{
45+
return trim((string) shell_exec($command));
46+
}
47+
48+
function str_after(string $subject, string $search): string
49+
{
50+
$pos = strrpos($subject, $search);
51+
52+
if ($pos === false) {
53+
return $subject;
54+
}
55+
56+
return substr($subject, $pos + strlen($search));
57+
}
58+
59+
function slugify(string $subject): string
60+
{
61+
return strtolower(trim((string) preg_replace('/[^A-Za-z0-9-]+/', '-', $subject), '-'));
62+
}
63+
64+
function title_case(string $subject): string
65+
{
66+
return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $subject)));
67+
}
68+
69+
function title_snake(string $subject, string $replace = '_'): string
70+
{
71+
return str_replace(['-', '_'], $replace, $subject);
72+
}
73+
74+
function replace_in_file(string $file, array $replacements): void
75+
{
76+
$contents = file_get_contents($file);
77+
78+
file_put_contents(
79+
$file,
80+
str_replace(
81+
array_keys($replacements),
82+
array_values($replacements),
83+
$contents
84+
)
85+
);
86+
}
87+
88+
function remove_prefix(string $prefix, string $content): string
89+
{
90+
if (str_starts_with($content, $prefix)) {
91+
return substr($content, strlen($prefix));
92+
}
93+
94+
return $content;
95+
}
96+
97+
function replace_readme_paragraphs(string $file, string $content): void
98+
{
99+
$contents = file_get_contents($file);
100+
101+
file_put_contents(
102+
$file,
103+
preg_replace('/<!--shortdesc-->.*<!--\/shortdesc-->/s', $content, $contents) ?: $contents
104+
);
105+
}
106+
107+
function safeUnlink(string $filename): void
108+
{
109+
if (file_exists($filename) && is_file($filename)) {
110+
unlink($filename);
111+
}
112+
}
113+
114+
function determineSeparator(string $path): string
115+
{
116+
return str_replace('/', DIRECTORY_SEPARATOR, $path);
117+
}
118+
119+
function replaceForWindows(): array
120+
{
121+
return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ "Frontend frontend"'));
122+
}
123+
124+
function replaceForAllOtherOSes(): array
125+
{
126+
return explode(PHP_EOL, run('grep -E -r -l -i "Frontend|frontend" --exclude-dir=vendor ./* | grep -v '.basename(__FILE__)));
127+
}
128+
129+
writeln(' ');
130+
writeln(' ');
131+
writeln('▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓');
132+
writeln('▓▓▒░░▒▓▓▒▒░░░░░░▒▒▓▓▓▒░░░░░░░▒▓▓ ▓▓▓▓▒░░░░░░░▒▓▓▓▓ ▓▓▓▓▓▒░░░░░░░▒▒▓▓▓▓▓▒▒▒▒▓▓ ▓▓▓▒▒▒▒▓▓');
133+
writeln('▓▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓ ▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓░░░░░▒▓▓ ▓▓▒░░░░░▓▓');
134+
writeln('▓▒░░░░░░▒▓▓▓▓▒░░░░░░░▒▓▓▓▓░░░░░▒▓▓▓░░░░░▒▓▓▓▓▒░░░░░░░▓▓▓▓░░░░░░▒▓▓▓▓▓░░░░░░▒▓▓░░░░░▒▓▓▓▓▓░░░░░▒▓▓');
135+
writeln('▓▒░░░░▓▓▓▓ ▓▓░░░░░▓▓▓ ▓▓▓░░░░▒▓▓░░░░▒▓▓▓ ▓▓▓▓░░░░░▓░░░░░░▓▓▓▓ ▓▓▓▒░░░░▓▓▓▒░░░░░▓▓▓░░░░░▓▓▓');
136+
writeln('▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓▓ ▓▓▓░░▒░░░░░▓▓▓ ▓▓░░░░▒▓▓▓▓░░░░░░░░░░░▓▓');
137+
writeln('▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓ ▓▓▓░░░░░▒▓▓ ▓▓▒░░░░▓ ▓▓▓░░░░░░░░░▓▓');
138+
writeln('▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓▓ ▓▓▒░░░░░▒░░▒▓▓ ▓▓░░░░▒▓▓▓▒░░░░░▒░░░░░▒▓');
139+
writeln('▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓░░░░▒▓▓▓ ▓▓▓▒░░░░░▒▒░░░░░▒▓▓▓ ▓▓▓░░░░░▓▓▓░░░░░▒▓▓▓░░░░░▒▓▓');
140+
writeln('▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓▓░░░░░░▒▒▓▓▒░░░░░░▒▓▓▓▓░░░░░░░▒▒▓▓▒░░░░░░▓▓▓░░░░░▒▓▓▓▓▓▒░░░░░▓▓');
141+
writeln('▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓ ▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▒░░░░░▓▓▓ ▓▓▒░░░░░▒▓');
142+
writeln('▓▓░░░▒▓▓ ▓▓▒░░░▒▓▓ ▓▓░░░░▓▓ ▓▓▓▓▒░░░░░░▒▒▓▓▓▓ ▓▓▓▓▓▒▒░░░░░▒▒▓▓▓▓▓░░░░▒▓▓ ▓▓▓░░░░▒▓');
143+
writeln('▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓');
144+
writeln(' ');
145+
writeln(' ');
146+
writeln('Welcome to Moox Builder');
147+
writeln(' ');
148+
writeln('This script will guide you through the process of building your own Moox package.');
149+
writeln(' ');
150+
151+
$authorName = ask('Author name', 'Moox Developer');
152+
153+
$authorEmail = ask('Author email', 'dev@moox.org');
154+
155+
$currentDirectory = getcwd();
156+
$folderName = basename($currentDirectory);
157+
158+
if (! isValidPackageName($folderName)) {
159+
do {
160+
writeln('Invalid package name: "frontend" is not allowed.');
161+
$packageName = ask('Package name');
162+
} while (! isValidPackageName($packageName));
163+
} else {
164+
$packageName = $folderName;
165+
}
166+
167+
$packageSlug = slugify($packageName);
168+
$packageSlugWithoutPrefix = remove_prefix('laravel-', $packageSlug);
169+
170+
$className = title_case($packageName);
171+
$className = ask('Class name', $className);
172+
$variableName = lcfirst($className);
173+
$description = ask('Package description', 'This is my package '.$packageSlug);
174+
175+
writeln('------');
176+
writeln('Author : '.$authorName);
177+
writeln('Author Email : '.$authorEmail);
178+
writeln('Namespace : Moox\\'.$className);
179+
writeln('Packagename : moox\\'.$packageSlug);
180+
writeln(sprintf('Class name : %sPlugin', $className));
181+
writeln('------');
182+
183+
writeln('This script will replace the above values in all relevant files in the project directory.');
184+
185+
if (! confirm('Modify files?', true)) {
186+
exit(1);
187+
}
188+
189+
$files = (str_starts_with(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes());
190+
191+
foreach ($files as $file) {
192+
replace_in_file($file, [
193+
'frontend.jpg' => 'made-with-moox.jpg',
194+
'Moox Developer' => $authorName,
195+
'dev@moox.org' => $authorEmail,
196+
'Frontend' => $className,
197+
'frontend' => $packageSlug,
198+
'Frontend is a Moox Package using Moox Skeleton.' => $description,
199+
'not used as installed package, only used as template for new Moox packages' => 'we do not know yet',
200+
'creating simple Laravel packages' => 'we do not know yet',
201+
]);
202+
203+
match (true) {
204+
str_contains((string) $file, determineSeparator('src/FrontendServiceProvider.php')) => rename($file, determineSeparator('./src/'.$className.'ServiceProvider.php')),
205+
str_contains((string) $file, 'README.md') => replace_readme_paragraphs($file, $description),
206+
default => [],
207+
};
208+
}
209+
210+
rename(determineSeparator('config/frontend.php'), determineSeparator('./config/'.$packageSlugWithoutPrefix.'.php'));
211+
212+
if (confirm('Execute `composer install` and run tests?')) {
213+
run('composer install && composer test');
214+
}
215+
216+
if (confirm('Let this script delete itself?', true)) {
217+
unlink(__FILE__);
218+
}
219+
220+
writeln(' ');
221+
writeln('Moox Builder is finished. Have fun!');

packages/frontend/composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "moox/frontend",
3-
"description": "A modular Frontend for Laravel and Filament",
3+
"description": "Frontend is a Moox Package using Moox Skeleton.",
44
"keywords": [
5+
"Moox",
56
"Laravel",
67
"Filament",
7-
"Filament plugin",
8+
"Moox package",
89
"Laravel package"
910
],
10-
"homepage": "https://moox.org/",
11+
"homepage": "https://moox.org/docs/frontend",
1112
"license": "MIT",
1213
"authors": [
1314
{
@@ -75,4 +76,4 @@
7576
"pestphp/pest-plugin": true
7677
}
7778
}
78-
}
79+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Get Started
2+
3+
This is the optional section for beginners.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Integration
2+
3+
In this section, we will cover the integration of Moox Frontend into your project.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Usage
2+
3+
This is the user guide for the package.

0 commit comments

Comments
 (0)