@@ -19,19 +19,21 @@ export async function installChocolatey() {
1919 return ;
2020 }
2121 spinner . info (
22- colors . yellow ( "Running Chocolatey installation as non-admin..." )
22+ colors . yellow ( "Running Chocolatey installation as non-admin..." ) ,
2323 ) ;
2424 const scriptPath = getScriptPath ( "installChocolately.ps1" ) ;
2525 // Execute the PowerShell script for non-admin installation
2626 execSync ( `powershell.exe -ExecutionPolicy Bypass -File "${ scriptPath } "` , {
2727 stdio : "inherit" ,
2828 } ) ;
2929 spinner . succeed (
30- colors . green ( "Chocolatey installed successfully (non-admin)." )
30+ colors . green ( "Chocolatey installed successfully (non-admin)." ) ,
3131 ) ;
3232 // Add Chocolatey to the current session's PATH
33- const chocoPath = `${ process . env . ProgramData } \\chocoportable\\bin` ;
34- process . env . PATH = `${ process . env . PATH } ;${ chocoPath } ` ;
33+ const programData = process . env [ "ProgramData" ] || "C:\\ProgramData" ;
34+ const chocoPath = `${ programData } \\chocoportable\\bin` ;
35+ const currentPath = process . env [ "PATH" ] || "" ;
36+ process . env [ "PATH" ] = `${ currentPath } ;${ chocoPath } ` ;
3537 } catch ( error ) {
3638 spinner . fail ( colors . red ( "Failed to install Chocolatey." ) ) ;
3739 console . error ( error ) ;
@@ -68,11 +70,11 @@ export async function installJDK() {
6870 stdio : "inherit" ,
6971 } ) ;
7072 spinner . succeed (
71- colors . green ( "JAVA_HOME environment variable set successfully." )
73+ colors . green ( "JAVA_HOME environment variable set successfully." ) ,
7274 ) ;
7375 } catch ( error ) {
7476 spinner . fail (
75- colors . red ( "Failed to set JAVA_HOME environment variable." )
77+ colors . red ( "Failed to set JAVA_HOME environment variable." ) ,
7678 ) ;
7779 throw error ;
7880 }
@@ -102,18 +104,18 @@ export async function installJDK() {
102104 } ) ;
103105 execSync ( "source ~/.bashrc" , { stdio : "inherit" } ) ;
104106 spinner . succeed (
105- colors . green ( "JAVA_HOME environment variable set successfully." )
107+ colors . green ( "JAVA_HOME environment variable set successfully." ) ,
106108 ) ;
107109 } catch ( error ) {
108110 spinner . fail (
109- colors . red ( "Failed to set JAVA_HOME environment variable." )
111+ colors . red ( "Failed to set JAVA_HOME environment variable." ) ,
110112 ) ;
111113 throw error ;
112114 }
113115 }
114116 } else {
115117 spinner . fail (
116- colors . red ( "Please install OpenJDK manually on this operating system." )
118+ colors . red ( "Please install OpenJDK manually on this operating system." ) ,
117119 ) ;
118120 }
119121}
@@ -129,11 +131,11 @@ export async function installAndroidStudio() {
129131 await installChocolatey ( ) ;
130132 }
131133 const androidStudioPath = path . join (
132- process . env . ProgramFiles || "C:\\Program Files" ,
134+ process . env [ " ProgramFiles" ] || "C:\\Program Files" ,
133135 "Android" ,
134136 "Android Studio" ,
135137 "bin" ,
136- "studio.exe"
138+ "studio.exe" ,
137139 ) ;
138140
139141 if ( process . platform === "win32" ) {
@@ -163,14 +165,14 @@ export async function installAndroidStudio() {
163165
164166 // Set ANDROID_HOME environment variable
165167 const androidHomePath = path . join (
166- process . env . ProgramFiles || "C:\\Program Files" ,
168+ process . env [ " ProgramFiles" ] || "C:\\Program Files" ,
167169 "Android" ,
168- "Sdk"
170+ "Sdk" ,
169171 ) ;
170172
171173 if ( ! fs . existsSync ( androidHomePath ) ) {
172174 pathSpinner . fail (
173- colors . red ( "Android SDK not found. Please install Android Studio." )
175+ colors . red ( "Android SDK not found. Please install Android Studio." ) ,
174176 ) ;
175177 return ;
176178 }
@@ -185,17 +187,17 @@ export async function installAndroidStudio() {
185187
186188 execSync (
187189 `setx PATH "%PATH%;${ androidHomePath } \\tools;${ androidHomePath } \\platform-tools" /M` ,
188- { stdio : "inherit" }
190+ { stdio : "inherit" } ,
189191 ) ;
190192
191193 pathSpinner . succeed (
192- colors . green ( "Android Studio added to PATH successfully." )
194+ colors . green ( "Android Studio added to PATH successfully." ) ,
193195 ) ;
194196 } catch ( error ) {
195197 pathSpinner . fail (
196198 colors . red (
197- "Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables."
198- )
199+ "Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables." ,
200+ ) ,
199201 ) ;
200202 console . error ( error ) ;
201203 throw error ;
@@ -219,14 +221,14 @@ export async function installAndroidStudio() {
219221
220222 // Set ANDROID_HOME environment variable
221223 const androidHomePath = path . join (
222- process . env . HOME || "/home/user" ,
224+ process . env [ " HOME" ] || "/home/user" ,
223225 "Android" ,
224- "Sdk"
226+ "Sdk" ,
225227 ) ;
226228
227229 if ( ! fs . existsSync ( androidHomePath ) ) {
228230 pathSpinner . fail (
229- colors . red ( "Android SDK not found. Please install Android Studio." )
231+ colors . red ( "Android SDK not found. Please install Android Studio." ) ,
230232 ) ;
231233 return ;
232234 }
@@ -239,33 +241,33 @@ export async function installAndroidStudio() {
239241 `echo "export ANDROID_SDK_ROOT=${ androidHomePath } " >> ~/.bashrc` ,
240242 {
241243 stdio : "inherit" ,
242- }
244+ } ,
243245 ) ;
244246 execSync (
245247 `echo "export PATH=$PATH:${ androidHomePath } /tools:${ androidHomePath } /platform-tools" >> ~/.bashrc` ,
246248 {
247249 stdio : "inherit" ,
248- }
250+ } ,
249251 ) ;
250252 execSync ( "source ~/.bashrc" , { stdio : "inherit" } ) ;
251253
252254 pathSpinner . succeed (
253- colors . green ( "Android Studio added to PATH successfully." )
255+ colors . green ( "Android Studio added to PATH successfully." ) ,
254256 ) ;
255257 } catch ( error ) {
256258 pathSpinner . fail (
257259 colors . red (
258- "Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables."
259- )
260+ "Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables." ,
261+ ) ,
260262 ) ;
261263 console . error ( error ) ;
262264 throw error ;
263265 }
264266 } else {
265267 spinner . fail (
266268 colors . red (
267- "Please install Android Studio manually on this operating system."
268- )
269+ "Please install Android Studio manually on this operating system." ,
270+ ) ,
269271 ) ;
270272 }
271273}
0 commit comments