Skip to content

Commit cb446a8

Browse files
Add inertiajs/inertia-laravel to composer array
Typically you'll install the composer preset as a dev dependency, and may remove it for production, but we still need the inertia-laravel dependency in prod, otherwise everything breaks when it's removed.
1 parent f709391 commit cb446a8

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This preset scaffolding removes the manual steps required to get up and running
1010
## Usage
1111

1212
1. Fresh install Laravel >= 6.0 and cd to your app.
13-
2. Install this preset via `composer require laravel-frontend-presets/inertiajs`. Laravel will automatically discover this package. No need to register the service provider.
13+
2. Install this preset via `composer require --dev laravel-frontend-presets/inertiajs`. Laravel will automatically discover this package. No need to register the service provider.
1414

1515
### Installation
1616

src/InertiaJsPreset.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static function install($command)
1818

1919
static::updatePackages();
2020
static::installBootstrapDefault();
21+
static::updateComposer(false);
2122
static::updateBootstrapping();
2223
static::updateWelcomePage();
2324
static::updateGitignore();
@@ -37,6 +38,13 @@ protected static function updatePackageArray(array $packages)
3738
], $packages);
3839
}
3940

41+
protected static function updateComposerArray(array $packages)
42+
{
43+
return array_merge([
44+
'inertiajs/inertia-laravel' => '^0.1',
45+
], $packages);
46+
}
47+
4048
protected static function updateBootstrapping()
4149
{
4250
copy(__DIR__.'/inertiajs-stubs/webpack.mix.js', base_path('webpack.mix.js'));
@@ -95,4 +103,27 @@ protected static function installBootstrapDefault()
95103
$process->run();
96104
});
97105
}
106+
107+
protected static function updateComposer($dev = true)
108+
{
109+
if (! file_exists(base_path('composer.json'))) {
110+
return;
111+
}
112+
113+
$configurationKey = $dev ? 'require-dev' : 'require';
114+
115+
$packages = json_decode(file_get_contents(base_path('composer.json')), true);
116+
117+
$packages[$configurationKey] = static::updateComposerArray(
118+
array_key_exists($configurationKey, $packages) ? $packages[$configurationKey] : [],
119+
$configurationKey
120+
);
121+
122+
ksort($packages[$configurationKey]);
123+
124+
file_put_contents(
125+
base_path('composer.json'),
126+
json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).PHP_EOL
127+
);
128+
}
98129
}

0 commit comments

Comments
 (0)