@@ -31,18 +31,22 @@ $directories = [
3131 'app/database/factories ' ,
3232 'app/shared/components ' ,
3333 'app/shared/layouts ' ,
34+ 'app/shared/errors ' ,
3435 'public/uploads ' ,
3536 'public/assets ' ,
3637 'public/js ' ,
3738 'public/styles ' ,
3839];
3940
4041foreach ($ directories as $ dir ) {
41- if (!is_dir ($ dir ) && !mkdir ($ dir , 0755 , true )) {
42- echo "Error: Could not create directory ' {$ dir }'. \n" ;
43- exit (1 );
42+ if (!is_dir ($ dir )) {
43+ if (mkdir ($ dir , 0755 , true )) {
44+ echo "{$ green }✓ {$ reset }Created directory: {$ dir }\n" ;
45+ } else {
46+ echo "{$ yellow }! {$ reset }Could not create directory: {$ dir }\n" ;
47+ }
4448 } else {
45- echo "{$ green } ✓ {$ reset }Created directory : {$ dir }\n" ;
49+ echo "{$ yellow } ! {$ reset }Directory already exists : {$ dir }\n" ;
4650 }
4751}
4852
@@ -66,13 +70,9 @@ if (!file_exists('warvil.json') && file_exists('warvil.json.example')) {
6670
6771// Add initial files that are necessary for WarvilPHP to work
6872$ defaultFiles = [
69- 'app/shared/layouts/main.php ' => file_exists ('app/shared/layouts/main.php ' ) ?
70- file_get_contents ('app/shared/layouts/main.php ' ) :
71- '<!DOCTYPE html><html><head><title><?= htmlspecialchars($warvilConfig[ \'name \']) ?></title><meta charset="UTF-8"><link rel="stylesheet" href="<?= htmlspecialchars($baseStyle) ?>"></head><body><?= $this->content ?></body></html> ' ,
72-
73- 'public/styles/base.css ' => file_exists ('public/styles/base.css ' ) ?
74- file_get_contents ('public/styles/base.css ' ) :
75- '* {padding: 0;margin: 0;box-sizing: border-box;font-family: "Arial", sans-serif;} '
73+ 'app/shared/errors/404.php ' => '<?php http_response_code(404); ?><h1>404 - Page Not Found</h1><p>The requested page could not be found.</p> ' ,
74+ 'app/shared/layouts/main.php ' => '<!DOCTYPE html><html><head><title><?= htmlspecialchars($warvilConfig[ \'name \']) ?></title><meta charset="UTF-8"><link rel="stylesheet" href="<?= htmlspecialchars($baseStyle) ?>"></head><body><?= $this->content ?></body></html> ' ,
75+ 'public/styles/base.css ' => '* {padding: 0;margin: 0;box-sizing: border-box;font-family: "Arial", sans-serif;} '
7676];
7777
7878foreach ($ defaultFiles as $ path => $ content ) {
@@ -84,6 +84,8 @@ foreach ($defaultFiles as $path => $content) {
8484 if (!file_exists ($ path )) {
8585 file_put_contents ($ path , $ content );
8686 echo "{$ green }✓ {$ reset }Created file: {$ path }\n" ;
87+ } else {
88+ echo "{$ yellow }! {$ reset }File already exists: {$ path }\n" ;
8789 }
8890}
8991
@@ -97,18 +99,38 @@ if (PHP_OS_FAMILY !== 'Windows') {
9799 if (!file_exists ($ binPath )) {
98100 symlink ($ warvilScriptPath , $ binPath );
99101 echo "{$ green }✓ {$ reset }Created symbolic link for warvil command \n" ;
102+ } else {
103+ echo "{$ yellow }! {$ reset }Symbolic link already exists \n" ;
100104 }
101105 } else {
102106 echo "{$ yellow }! {$ reset }Could not create symlink for warvil command (permission denied). You may need to run this manually: \n" ;
103107 echo " sudo ln -s {$ warvilScriptPath } {$ binPath }\n" ;
104108 }
105109}
106110
111+ // Generate an app key
112+ if (file_exists ('.env ' )) {
113+ $ envContent = file_get_contents ('.env ' );
114+ if (strpos ($ envContent , 'APP_KEY=base64: ' ) === false || strpos ($ envContent , 'APP_KEY=base64:your-random-key-here ' ) !== false ) {
115+ echo "{$ yellow }Generating application key... {$ reset }\n" ;
116+ // Execute the key generation command
117+ if (file_exists ('bin/warvil ' )) {
118+ exec ('php bin/warvil key:generate ' , $ output );
119+ foreach ($ output as $ line ) {
120+ echo $ line . "\n" ;
121+ }
122+ } else {
123+ echo "{$ yellow }! {$ reset }Could not generate application key. Please run manually: \n" ;
124+ echo " php bin/warvil key:generate \n" ;
125+ }
126+ }
127+ }
128+
107129// Update composer.json to include the proper cli commands
108130echo "{$ green }✓ {$ reset }WarvilPHP installed successfully! \n\n" ;
109131
110132echo "{$ yellow }Next steps: {$ reset }\n" ;
111- echo " 1. Configure your database in warvil.json \n" ;
133+ echo " 1. Configure your database in .env \n" ;
112134echo " 2. Start the development server with: {$ yellow }composer serve {$ reset }\n" ;
113135echo " 3. Create components with: {$ yellow }php bin/warvil make:controller YourController {$ reset }\n" ;
114136echo "\nEnjoy building with WarvilPHP! \n" ;
0 commit comments