@@ -14,7 +14,8 @@ class ReplaceCommand extends Command
1414 * @var string
1515 */
1616 protected $ signature = 'kui-jetstream:replace {stack : The development stack that should be replaced (livewire,inertia)}
17- {--composer=global : Absolute path to the Composer binary which should be used to install packages} ' ;
17+ {--composer=global : Absolute path to the Composer binary which should be used to install packages}
18+ {--vite : Vitejs} ' ;
1819
1920 /**
2021 * The console command description.
@@ -23,6 +24,8 @@ class ReplaceCommand extends Command
2324 */
2425 protected $ description = 'Replace laravel \\jetstream views. ' ;
2526
27+ protected $ isVite = false ;
28+
2629 /**
2730 * Create a new command instance.
2831 *
@@ -40,6 +43,14 @@ public function __construct()
4043 */
4144 public function handle ()
4245 {
46+ $ this ->writeLogo ();
47+
48+ $ this ->replaceFavIcon ();
49+
50+ if (file_exists (base_path ('vite.config.js ' )) || $ this ->option ('vite ' )) {
51+ $ this ->isVite = true ;
52+ }
53+
4354 if ($ this ->argument ('stack ' ) === 'inertia ' ) {
4455 return $ this ->replaceInertia ();
4556 }
@@ -53,24 +64,22 @@ public function replaceInertia()
5364 {
5465 // NPM Packages...
5566 $ this ->updateNodePackages (function ($ packages ) {
56- return [
67+ $ extraPackages = [
5768 '@heroicons/vue ' => '^1.0.4 ' ,
58- '@headlessui/vue ' => '^1.4.1 ' ,
69+ '@headlessui/vue ' => '^1.4.3 ' ,
5970 '@vueuse/core ' => '^6.5.3 ' ,
60- '@vue/babel-plugin-jsx ' => '^1.1.0 ' ,
61- 'autoprefixer ' => '^10.3.7 ' ,
62- 'postcss ' => '^8.3.9 ' ,
63- 'tailwindcss ' => '^3.0.7 ' ,
64- '@tailwindcss/forms ' => '^0.4.0 ' ,
65- '@tailwindcss/typography ' => '^0.5.0 ' ,
6671 'perfect-scrollbar ' => '^1.5.2 ' ,
67- 'vue ' => '^3.2.26 ' ,
6872 'vue-toastification ' => '^2.0.0-rc.1 '
6973 ] + $ packages ;
70- });
7174
72- // Views...
73- copy (__DIR__ . '/../../stubs/inertia/views/app.blade.php ' , resource_path ('views/app.blade.php ' ));
75+ if (!$ this ->isVite ) {
76+ $ extraPackages += ['@vue/babel-plugin-jsx ' => '^1.1.0 ' ];
77+ } else {
78+ $ extraPackages += ['@vitejs/plugin-vue-jsx ' => '^1.3.10 ' ];
79+ }
80+
81+ return $ extraPackages + $ packages ;
82+ });
7483
7584 // Components + Pages...
7685 (new Filesystem )->ensureDirectoryExists (resource_path ('js/Components ' ));
@@ -85,14 +94,23 @@ public function replaceInertia()
8594 (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/inertia/js/Pages ' , resource_path ('js/Pages ' ));
8695 (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/inertia/js/Toast ' , resource_path ('js/Toast ' ));
8796
88- // Tailwind / Webpack...
97+
8998 copy (__DIR__ . '/../../stubs/inertia/tailwind.config.js ' , base_path ('tailwind.config.js ' ));
9099 copy (__DIR__ . '/../../stubs/inertia/css/app.css ' , resource_path ('css/app.css ' ));
91- copy (__DIR__ . '/../../stubs/inertia/js/app.js ' , resource_path ('js/app.js ' ));
92- copy (__DIR__ . '/../../stubs/inertia/.babelrc ' , base_path ('.babelrc ' ));
93- copy (__DIR__ . '/../../stubs/inertia/webpack.config.js ' , base_path ('webpack.config.js ' ));
94- copy (__DIR__ . '/../../stubs/inertia/webpack.mix.js ' , base_path ('webpack.mix.js ' ));
95100
101+ if (!$ this ->isVite ) {
102+ copy (__DIR__ . '/../../stubs/inertia/views/app.mix.blade.php ' , resource_path ('views/app.blade.php ' ));
103+ copy (__DIR__ . '/../../stubs/inertia/.babelrc ' , base_path ('.babelrc ' ));
104+ copy (__DIR__ . '/../../stubs/inertia/webpack.config.js ' , base_path ('webpack.config.js ' ));
105+ copy (__DIR__ . '/../../stubs/inertia/webpack.mix.js ' , base_path ('webpack.mix.js ' ));
106+ copy (__DIR__ . '/../../stubs/inertia/js/app.mix.js ' , resource_path ('js/app.js ' ));
107+ } else {
108+ copy (__DIR__ . '/../../stubs/inertia/views/app.vite.blade.php ' , resource_path ('views/app.blade.php ' ));
109+ copy (__DIR__ . '/../../stubs/inertia/vite.config.js ' , base_path ('vite.config.js ' ));
110+ copy (__DIR__ . '/../../stubs/inertia/js/app.vite.js ' , resource_path ('js/app.js ' ));
111+ copy (__DIR__ . '/../../stubs/common/postcss.config.js ' , base_path ('postcss.config.js ' ));
112+ }
113+
96114 $ this ->info ('Jetstream ui scaffolding replaced successfully. ' );
97115 $ this ->comment ('Please execute the "npm install && npm run dev" command to build your assets. ' );
98116 }
@@ -103,12 +121,6 @@ public function replaceLivewire()
103121 $ this ->updateNodePackages (function ($ packages ) {
104122 return [
105123 '@alpinejs/collapse ' => '^3.4.2 ' ,
106- 'alpinejs ' => '^3.4.2 ' ,
107- 'autoprefixer ' => '^10.3.7 ' ,
108- 'postcss ' => '^8.3.9 ' ,
109- 'tailwindcss ' => '^3.0.7 ' ,
110- '@tailwindcss/forms ' => '^0.4.0 ' ,
111- '@tailwindcss/typography ' => '^0.5.0 ' ,
112124 'perfect-scrollbar ' => '^1.5.2 '
113125 ] + $ packages ;
114126 });
@@ -124,7 +136,6 @@ public function replaceLivewire()
124136 (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/livewire/views/api ' , resource_path ('views/api ' ));
125137 (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/livewire/views/auth ' , resource_path ('views/auth ' ));
126138 (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/livewire/views/components ' , resource_path ('views/components ' ));
127- (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/livewire/views/layouts ' , resource_path ('views/layouts ' ));
128139 (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/livewire/views/profile ' , resource_path ('views/profile ' ));
129140 (new Filesystem )->copyDirectory (__DIR__ . '/../../stubs/livewire/views/teams ' , resource_path ('views/teams ' ));
130141
@@ -136,9 +147,20 @@ public function replaceLivewire()
136147
137148 // Assets
138149 copy (__DIR__ . '/../../stubs/livewire/tailwind.config.js ' , base_path ('tailwind.config.js ' ));
139- copy (__DIR__ . '/../../stubs/livewire/webpack.mix.js ' , base_path ('webpack.mix.js ' ));
140150 copy (__DIR__ . '/../../stubs/livewire/css/app.css ' , resource_path ('css/app.css ' ));
141- copy (__DIR__ . '/../../stubs/livewire/js/app.js ' , resource_path ('js/app.js ' ));
151+
152+ if (!$ this ->isVite ) {
153+ copy (__DIR__ . '/../../stubs/livewire/views/layouts/app.mix.blade.php ' , resource_path ('views/layouts/app.blade.php ' ));
154+ copy (__DIR__ . '/../../stubs/livewire/views/layouts/guest.mix.blade.php ' , resource_path ('views/layouts/guest.blade.php ' ));
155+ copy (__DIR__ . '/../../stubs/livewire/webpack.mix.js ' , base_path ('webpack.mix.js ' ));
156+ copy (__DIR__ . '/../../stubs/livewire/js/app.mix.js ' , resource_path ('js/app.js ' ));
157+ } else {
158+ copy (__DIR__ . '/../../stubs/livewire/views/layouts/app.vite.blade.php ' , resource_path ('views/layouts/app.blade.php ' ));
159+ copy (__DIR__ . '/../../stubs/livewire/views/layouts/guest.vite.blade.php ' , resource_path ('views/layouts/guest.blade.php ' ));
160+ copy (__DIR__ . '/../../stubs/livewire/vite.config.js ' , base_path ('webpack.mix.js ' ));
161+ copy (__DIR__ . '/../../stubs/livewire/js/app.vite.js ' , resource_path ('js/app.js ' ));
162+ copy (__DIR__ . '/../../stubs/common/postcss.config.js ' , base_path ('postcss.config.js ' ));
163+ }
142164
143165 // Icons
144166 $ this ->requireComposerPackages ('blade-ui-kit/blade-heroicons:^1.2 ' );
@@ -203,21 +225,6 @@ protected static function updateNodePackages(callable $callback, $dev = true)
203225 );
204226 }
205227
206- /**
207- * Delete the "node_modules" directory and remove the associated lock files.
208- *
209- * @return void
210- */
211- protected static function flushNodeModules ()
212- {
213- tap (new Filesystem , function ($ files ) {
214- $ files ->deleteDirectory (base_path ('node_modules ' ));
215-
216- $ files ->delete (base_path ('yarn.lock ' ));
217- $ files ->delete (base_path ('package-lock.json ' ));
218- });
219- }
220-
221228 /**
222229 * Replace a given string within a given file.
223230 *
@@ -230,4 +237,24 @@ protected function replaceInFile($search, $replace, $path)
230237 {
231238 file_put_contents ($ path , str_replace ($ search , $ replace , file_get_contents ($ path )));
232239 }
240+
241+ protected function replaceFavIcon ()
242+ {
243+ (new Filesystem )->ensureDirectoryExists (base_path ('public ' ));
244+ copy (__DIR__ . '/../../stubs/common/favicon.ico ' , base_path ('public/favicon.ico ' ));
245+ }
246+
247+ protected function writeLogo ()
248+ {
249+ $ logo = PHP_EOL . '<fg=bright-blue>
250+ ██╗ ██╗ ██╗ ██╗██╗
251+ ██║ ██╔╝ ██║ ██║██║
252+ █████╔╝█████╗██║ ██║██║
253+ ██╔═██╗╚════╝██║ ██║██║
254+ ██║ ██╗ ╚██████╔╝██║
255+ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
256+ </> ' . PHP_EOL ;
257+
258+ return $ this ->line ($ logo );
259+ }
233260}
0 commit comments