File tree Expand file tree Collapse file tree 4 files changed +44
-16
lines changed
Expand file tree Collapse file tree 4 files changed +44
-16
lines changed Original file line number Diff line number Diff line change @@ -78,4 +78,30 @@ public static function getReactTag()
7878
7979 return null ;
8080 }
81+
82+ /**
83+ * Check if the vite is running or manifest does exist.
84+ *
85+ * @return bool true if vite is runnig or if manifest does exist, otherwise false;
86+ */
87+ public static function check (): bool
88+ {
89+ # Check if vite is running.
90+ $ entryFile = env ('VITE_ORIGIN ' ) . '/ ' . env ('VITE_RESOURCES_DIR ' ) . '/ ' . env ('VITE_ENTRY_FILE ' );
91+
92+ if (@file_get_contents ($ entryFile ))
93+ {
94+ $ result = true ;
95+ }
96+ elseif (!empty (static ::$ manifest ))
97+ {
98+ $ result = true ;
99+ }
100+ else
101+ {
102+ $ result = false ;
103+ }
104+
105+ return $ result ;
106+ }
81107}
Original file line number Diff line number Diff line change @@ -114,13 +114,13 @@ private function updateEnvFile()
114114 $ envFile = ROOTPATH . '.env ' ;
115115
116116 # For backup.
117- $ backupFile = '-BACKUP- ' . time ();
117+ $ backupFile = 'env -BACKUP- ' . time ();
118118
119119 # Does exist? if not, generate it =)
120120 if (is_file ($ envFile ))
121121 {
122122 # But first, let's take a backup.
123- copy ($ envFile , $ envFile . $ backupFile );
123+ copy ($ envFile , ROOTPATH . $ backupFile );
124124
125125 # Get .env.default content
126126 $ content = file_get_contents ($ this ->path . 'Config/env.default ' );
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public function run(array $params)
3737 */
3838 private function removeFrameworkFiles ()
3939 {
40- CLI ::write ('⚡ Removing vite files... ' , 'yellow ' );
40+ CLI ::write ('Removing vite files... ' , 'yellow ' );
4141 CLI ::newLine ();
4242
4343 # First vite.config.js
@@ -52,10 +52,6 @@ private function removeFrameworkFiles()
5252 $ publisher = new Publisher (null , ROOTPATH . 'resources ' );
5353 $ publisher ->wipe ();
5454 }
55-
56- CLI ::newLine ();
57- CLI ::write ('Deleted ✅ ' , 'green ' );
58- CLI ::newLine ();
5955 }
6056
6157 /**
@@ -74,7 +70,7 @@ private function resetEnvFile()
7470 $ backupFile = ROOTPATH . env ('VITE_BACKUP_FILE ' );
7571
7672 # Does exist? if not, generate it =)
77- if (is_file ($ envFile ))
73+ if (is_file ($ backupFile ))
7874 {
7975 # Remove current .env
8076 unlink ($ envFile );
@@ -85,9 +81,5 @@ private function resetEnvFile()
8581 unlink ($ backupFile );
8682 }
8783 }
88-
89- # env updated.
90- CLI ::write ('.env file updated ✅ ' , 'green ' );
91- CLI ::newLine ();
9284 }
9385}
Original file line number Diff line number Diff line change @@ -8,12 +8,22 @@ class Decorator implements ViewDecoratorInterface
88{
99 public static function decorate (string $ html ): string
1010 {
11- # Get generated js and css tags.
12- $ tags = CodeigniterVite::tags ();
11+ # Check if vite is running or manifest is ready.
12+ if (CodeigniterVite::check ())
13+ {
14+ # Get generated js and css tags.
15+ $ tags = CodeigniterVite::tags ();
1316
14- # Insert tags just before "</head>" tag.
15- $ html = empty ($ tags ) ? $ html : str_replace ('</head> ' , "\n\t$ tags \n</head> " , $ html );
17+ # Insert tags just before "</head>" tag.
18+ $ html = empty ($ tags ) ? $ html : str_replace ('</head> ' , "\n\t$ tags \n</head> " , $ html );
1619
20+ # Insert app id just after body tag
21+ $ html = empty ($ tags ) ? $ html : str_replace ('<body> ' , "<body> \n\t<div id= \"app \"> " , $ html );
22+ # Close it.
23+ $ html = empty ($ tags ) ? $ html : str_replace ('</body> ' , "\n\t</div> \n</body> " , $ html );
24+ }
25+
26+ # If not, then just return the html as it is.
1727 return $ html ;
1828 }
1929}
You can’t perform that action at this time.
0 commit comments