Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit a7a6825

Browse files
Merge pull request #5 from tpg/develop
v0.6
2 parents 69282dd + dbd2764 commit a7a6825

17 files changed

+120
-100
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ The following Composer packages are installed:
4444
- [inertiajs/inertia-laravel](https://github.com/inertiajs/inertia-laravel)
4545
- [laravel/horizon](https://github.com/laravel/horizon)
4646
- [laravel/telescope](https://github.com/laravel/telescope)
47-
- [thepublicgood/deadbolt](https://github.com/tpg/deadbolt)
4847
- [thepublicgood/is-presentable](https://github.com/tpg/is-presentable)
4948
- [tightenco/ziggy](https://github.com/tighten/ziggy)
5049
- [laravel/envoy](https://github.com/laravel/envoy) (dev)
@@ -56,6 +55,7 @@ The following NPM packages are installed:
5655
- [@inertiajs/inertia](https://github.com/inertiajs/inertia)
5756
- [@inertiajs/inertia-vue3](https://github.com/inertiajs/inertia)
5857
- [@inertiajs/progress](https://github.com/inertiajs/progress)
58+
- [@tailwindcss/typography](https://github.com/tailwindlabs/tailwindcss-typography)
5959
- [@vitejs/plugin-vue](https://github.com/vitejs/vite/tree/main/packages/plugin-vue)
6060
- [@vue/compiler-sfc](https://github.com/vuejs/core/tree/main/packages/compiler-sfc)
6161
- [autoprefixer](https://github.com/postcss/autoprefixer)
@@ -131,7 +131,7 @@ You'll need to make sure your app binds your new composer instead of the default
131131
]
132132
```
133133

134-
That's it. Now your app will use your new composer instead of the default Vitamin one. If you need to override the `compose` method in your view composer, remember to call `parent::compose()`:
134+
That's it. Now your app will use your new view composer instead of the default Vitamin one. If you need to override the `compose` method in your view composer, remember to call `parent::compose()`:
135135

136136
```php
137137
public function compose(View $view): void
@@ -151,13 +151,17 @@ During development, all assets are served from the dev server running at port 30
151151
Inertia is my go to these days, so Vitamin will set it up by default. During initialisation, you're asked where your Vue components are stored. You can customize this location in `app.js` if you wish. Vite will load your Vue pages from there. The Inertia documentation uses `resources/js/Pages`, so Vitamin will make that suggestion. However, technically, you can put them anywhere. The only requirement is that the location must be child of the JS path.
152152

153153
### Ziggy
154-
Ziggy is a JavaScript route helper for Laravel. If allows you to use your Laravel defined routes from within your JavaScript front-end. It ships with a fairly decent Vue plugin, so it's included by default. Inside your Vue components, you'll have access to `route` function which you can pass any Laravel defined route name. Something like:
154+
Ziggy is a JavaScript route helper for Laravel. If allows you to use your Laravel defined routes from within your JavaScript front-end. Vitamin comes with a `Router` script that provides a `route` function. You can import this into any Vue file to get access to your Laravel routes:
155155

156156
```javascript
157-
this.route('home');
157+
import {route} from '@/Scripts/Routing/Router.js'
158+
159+
route('home');
158160
```
159161

160-
Vitamin sets up Ziggy routes in the `resources/js/routes.js` file. This file needs to be regenerated each time your change your Laravel routes. Vitamin does this automatically by creating a simple Vite plugin that will run the `yarn routes` script each time a Laravel routes file changes. However, if you ever need to rebuild the routes, simply run `yarn routes` yourself.
162+
Vitamin sets up Ziggy routes in the `resources/js/Scripts/Routing/Ziggy.js` file. This file needs to be regenerated each time your change your Laravel routes. Vitamin does this automatically by creating a simple Vite plugin that will run the `yarn routes` script each time a Laravel routes file changes. However, if you ever need to rebuild the routes, simply run `yarn routes` yourself. If you. change the name of this file or want to place it somewhere else, remember to update the reference in the `Router.js` file as well.
163+
164+
In previous versions of Vitamin, the Ziggy Vue plugin was used, but since I don't use that anymore and now have
161165

162166
## TLS Certificates
163167
It's possible to get all of this to work with TLS as well so you can use an `https` address during development. First, you need to get Valet to secure your site. Valet provides a simple solution for this. If you're serving your site at `mysite.test` then you can get Valet to generate a new certificate:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
]
3636
},
3737
"branch-aliases": {
38-
"dev-master": "1.0.x-dev"
38+
"dev-develop": "1.0.x-dev"
3939
}
4040
}
4141
}

config/vitamin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
'port' => 3000,
1717

1818
/*
19-
* The view composer class to use
19+
* The view composer class to use.
2020
*/
2121
'composer' => \TPG\Vitamin\Composers\AppComposer::class,
2222

@@ -26,11 +26,11 @@
2626
'installers' => [
2727
VitaminConfigInstaller::class,
2828
ConfigInstaller::class,
29+
ComposerDependencyInstaller::class,
2930
NodeScriptInstaller::class,
3031
NodeDependencyInstaller::class,
3132
JavaScriptInstaller::class,
3233
TailwindInstaller::class,
33-
ComposerDependencyInstaller::class,
3434
InertiaInstaller::class,
35-
]
35+
],
3636
];

src/Console/InitCommand.php

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,19 @@ protected function install(VitaminInterface $vitamin): int
4242
$js = $this->getJsPath();
4343
$pages = $this->getPagesPath($js);
4444

45-
$settings = [
46-
'variables' => [
47-
'$HOST$' => $host,
48-
'$PORT$' => $port,
49-
'$JSPATH$' => $js,
50-
'$PAGESPATH$' => $pages,
51-
],
52-
'node' => [
53-
'@heroicons/vue',
54-
'@inertiajs/inertia',
55-
'@inertiajs/inertia-vue3',
56-
'@inertiajs/progress',
57-
'@vitejs/plugin-vue',
58-
'@vue/compiler-sfc',
59-
'autoprefixer@latest',
60-
'axios',
61-
'lodash',
62-
'postcss@latest',
63-
'tailwindcss@latest',
64-
'vite',
65-
'vue@next',
66-
],
67-
'composer' => [
68-
'require' => [
69-
'inertiajs/inertia-laravel',
70-
'laravel/horizon',
71-
'laravel/telescope',
72-
'thepublicgood/deadbolt',
73-
'thepublicgood/is-presentable',
74-
'tightenco/ziggy',
75-
],
76-
'dev' => [
77-
'laravel/envoy',
78-
'roave/security-advisories',
79-
],
80-
]
45+
$variables = [
46+
'$HOST$' => $host,
47+
'$PORT$' => $port,
48+
'$JSPATH$' => $js,
49+
'$PAGESPATH$' => $pages,
8150
];
8251

8352
if ($vitamin->getInstallers()->count() === 0) {
8453
$vitamin->initializeInstallers($this->input, $this->output);
8554
}
8655

8756
collect($vitamin->getInstallers())
88-
->each(fn (AbstractInstaller $installer) => $installer->run($settings));
57+
->each(fn (AbstractInstaller $installer) => $installer->run($variables));
8958

9059
return 0;
9160
}

src/Installers/AbstractInstaller.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
abstract class AbstractInstaller implements InstallerContract
1414
{
15-
protected array $settings = [];
15+
protected array $variables = [];
1616

1717
public function __construct(protected InputInterface $input, protected OutputInterface $output)
1818
{
@@ -36,7 +36,7 @@ protected function copyFiles(): void
3636

3737
$data = file_get_contents($source);
3838

39-
foreach ($this->variables() as $var => $value) {
39+
foreach ($this->variables as $var => $value) {
4040
$data = str_replace($var, (string)$value, $data);
4141
}
4242

@@ -51,11 +51,6 @@ protected function stubPath(string $filename): string
5151
return __DIR__.'/../../stubs/'.$filename;
5252
}
5353

54-
protected function variables(): array
55-
{
56-
return Arr::get($this->settings, 'variables', []);
57-
}
58-
5954
protected function removeFiles(): void
6055
{
6156
collect($this->filesToRemove())->each(function ($file) {
@@ -112,7 +107,7 @@ protected function prepDestination(string $destination): void
112107

113108
protected function makeDirectory(string $path): void
114109
{
115-
if (! mkdir($path) && ! is_dir($path)) {
110+
if (! mkdir($path, recursive: true) && ! is_dir($path)) {
116111
throw new \RuntimeException(sprintf('Directory "%s" was not created', $path));
117112
}
118113
}
@@ -129,9 +124,9 @@ protected function done(): void
129124
$this->output->writeln('[<info>✔</info>]');
130125
}
131126

132-
public function run(array $settings = []): void
127+
public function run(array $variables = []): void
133128
{
134-
$this->settings = $settings;
129+
$this->variables = $variables;
135130
$this->handle();
136131
}
137132

src/Installers/ComposerDependencyInstaller.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@
99

1010
class ComposerDependencyInstaller extends AbstractInstaller
1111
{
12+
protected array $require = [
13+
'inertiajs/inertia-laravel',
14+
'laravel/horizon',
15+
'laravel/telescope',
16+
'thepublicgood/is-presentable',
17+
'tightenco/ziggy',
18+
];
19+
20+
protected array $dev = [
21+
'laravel/envoy',
22+
'roave/security-advisories',
23+
];
24+
1225
public function handle(): void
1326
{
1427
$this->dependencies();
15-
$this->dependencies(true);
16-
17-
$this->start('Installing composer dev dependencies');
18-
19-
$this->getProcessInstance(Arr::get($this->settings, 'composer.dev'), true)->run(function (string $type, string $buffer) {
20-
$this->output->write('.');
21-
});
22-
23-
$this->done();
28+
$this->dependencies(dev: true);
2429
}
2530

2631
protected function dependencies(bool $dev = false): void
2732
{
2833
$this->start('Installing '. ($dev ? 'dev ' : null) .'composer dependencies');
2934

30-
$dependencies = Arr::get($this->settings, $dev ? 'composer.dev' : 'composer.require');
35+
$dependencies = $dev ? $this->dev : $this->require;
3136

3237
$this->getProcessInstance($dependencies, $dev)->run(function (string $type, string $buffer) {
3338
$this->output->write('.');

src/Installers/InertiaInstaller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function filesToCopy(): array
2121
{
2222
return [
2323
$this->stubPath('app.blade.php') => resource_path('views/app.blade.php'),
24-
$this->stubPath('Welcome.vue') => resource_path(Arr::get($this->settings, 'variables.$PAGESPATH$').'/Welcome.vue'),
24+
$this->stubPath('Welcome.vue') => resource_path(Arr::get($this->variables, '$PAGESPATH$').'/Welcome.vue'),
2525
$this->stubPath('web.routes.php') => base_path('routes/web.php'),
2626
];
2727
}
@@ -32,7 +32,7 @@ public function handle(): void
3232

3333
$this->installMiddleware();
3434
$this->buildRoutes();
35-
$this->createPaths($this->settings);
35+
$this->createPaths($this->variables);
3636

3737
$this->done();
3838
}
@@ -55,7 +55,7 @@ protected function buildRoutes(): void
5555
public function createPaths(array $settings): void
5656
{
5757
$paths = [
58-
Arr::get($settings, 'variables.$PAGESPATH$'),
58+
Arr::get($settings, '$PAGESPATH$'),
5959
];
6060

6161
foreach ($paths as $path) {

src/Installers/JavaScriptInstaller.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
namespace TPG\Vitamin\Installers;
66

77
use Illuminate\Support\Arr;
8+
use Symfony\Component\Process\Process;
89

910
class JavaScriptInstaller extends AbstractInstaller
1011
{
1112
protected function filesToCopy(): array
1213
{
13-
$jsPath = Arr::get($this->settings, 'variables.$JSPATH$');
14+
$jsPath = Arr::get($this->variables, '$JSPATH$');
1415

1516
return [
1617
$this->stubPath('bootstrap.js') => resource_path($jsPath.'/bootstrap.js'),
17-
$this->stubPath('router.js') => resource_path($jsPath.'/router.js'),
18+
$this->stubPath('Router.js') => resource_path($jsPath.'/Scripts/Routing/Router.js'),
1819
$this->stubPath('app.js') => resource_path($jsPath.'/app.js'),
1920
];
2021
}
@@ -30,6 +31,8 @@ public function handle(): void
3031
{
3132
$this->start('Installing JS files');
3233

34+
Process::fromShellCommandline('yarn routes');
35+
3336
$this->done();
3437
}
3538
}

src/Installers/NodeDependencyInstaller.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@
88

99
class NodeDependencyInstaller extends AbstractInstaller
1010
{
11+
protected array $dependencies = [
12+
'@heroicons/vue',
13+
'@inertiajs/inertia',
14+
'@inertiajs/inertia-vue3',
15+
'@inertiajs/progress',
16+
'@tailwindcss/typography',
17+
'@vitejs/plugin-vue',
18+
'@vue/compiler-sfc',
19+
'autoprefixer@latest',
20+
'axios',
21+
'lodash',
22+
'postcss@latest',
23+
'tailwindcss@latest',
24+
'vite',
25+
'vue@next',
26+
];
27+
1128
public function handle(): void
1229
{
1330
$this->start('Installing node dependencies');
1431

15-
$dependencies = $this->settings['node'] ?? [];
16-
17-
$process = $this->getProcessRunner($dependencies);
32+
$process = $this->getProcessRunner($this->dependencies);
1833

1934
$process->run(function (string $type, string $buffer) {
2035
$this->output->write('.');

src/Installers/VitaminConfigInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function handle(): void
2727

2828
protected function updateEnv(): void
2929
{
30-
$url = 'http://'.Arr::get($this->settings, 'variables.$HOST$');
30+
$url = 'http://'.Arr::get($this->variables, '$HOST$');
3131

3232
$env = preg_replace(
3333
'/^APP_URL\=(?:.+)$/m',

0 commit comments

Comments
 (0)