-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): STUDIO_PATH environment variable (#3755)
- Loading branch information
Showing
4 changed files
with
85 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,37 @@ | ||
import { pathExists } from '@ionic/utils-fs'; | ||
import Debug from 'debug'; | ||
import open from 'open'; | ||
|
||
import { runCommand } from '../common'; | ||
import c from '../colors'; | ||
import type { Config } from '../definitions'; | ||
import { OS } from '../definitions'; | ||
import { logger } from '../log'; | ||
|
||
export async function openAndroid(config: Config): Promise<void> { | ||
logger.info(`Opening Android project at ${config.android.platformDir}.`); | ||
const debug = Debug('capacitor:android:open'); | ||
|
||
export async function openAndroid(config: Config): Promise<void> { | ||
const androidStudioPath = config.android.studioPath; | ||
const dir = config.android.platformDirAbs; | ||
|
||
switch (config.cli.os) { | ||
case OS.Mac: { | ||
await open(dir, { app: 'android studio', wait: false }); | ||
break; | ||
} | ||
case OS.Windows: { | ||
let androidStudioPath = config.windows.androidStudioPath; | ||
try { | ||
if (!(await pathExists(androidStudioPath))) { | ||
let commandResult = await runCommand('REG', [ | ||
'QUERY', | ||
'HKEY_LOCAL_MACHINE\\SOFTWARE\\Android Studio', | ||
'/v', | ||
'Path', | ||
]); | ||
commandResult = commandResult.replace(/(\r\n|\n|\r)/gm, ''); | ||
const ix = commandResult.indexOf('REG_SZ'); | ||
if (ix > 0) { | ||
androidStudioPath = | ||
commandResult.substring(ix + 6).trim() + '\\bin\\studio64.exe'; | ||
} | ||
} | ||
} catch (e) { | ||
androidStudioPath = ''; | ||
} | ||
if (androidStudioPath) { | ||
open(dir, { app: androidStudioPath, wait: false }); | ||
} else { | ||
logger.error( | ||
'Android Studio not found.\n' + | ||
'Make sure it\'s installed and configure "windowsAndroidStudioPath" in your capacitor.config.json to point to the location of studio64.exe, using JavaScript-escaped paths:\n' + | ||
'Example:\n' + | ||
'{\n' + | ||
' "windowsAndroidStudioPath": "C:\\\\Program Files\\\\Android\\\\Android Studio\\\\bin\\\\studio64.exe"\n' + | ||
'}', | ||
); | ||
} | ||
break; | ||
try { | ||
if (!(await pathExists(androidStudioPath))) { | ||
throw new Error(`Android Studio does not exist at: ${androidStudioPath}`); | ||
} | ||
case OS.Linux: { | ||
const linuxError = () => { | ||
logger.error( | ||
'Unable to launch Android Studio.\n' + | ||
'You must configure "linuxAndroidStudioPath" in your capacitor.config.json to point to the location of studio.sh, using JavaScript-escaped paths:\n' + | ||
'Example:\n' + | ||
'{\n' + | ||
' "linuxAndroidStudioPath": "/usr/local/android-studio/bin/studio.sh"\n' + | ||
'}', | ||
); | ||
}; | ||
|
||
try { | ||
await open(dir, { app: config.linux.androidStudioPath, wait: true }); | ||
} catch (e) { | ||
linuxError(); | ||
} | ||
break; | ||
} | ||
await open(dir, { app: androidStudioPath, wait: false }); | ||
logger.info( | ||
`Opening Android project at: ${c.strong(config.android.platformDir)}.`, | ||
); | ||
} catch (e) { | ||
debug('Error opening Android Studio: %O', e); | ||
|
||
logger.error( | ||
'Unable to launch Android Studio. Is it installed?\n' + | ||
`Attempted to open Android Studio at: ${c.strong( | ||
androidStudioPath, | ||
)}\n` + | ||
`You can configure this with the ${c.input( | ||
'STUDIO_PATH', | ||
)} environment variable.`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters