(logger: Logger, flutterSdkPath: string | undefined, folder: string, flutterConfigKey: string)
| 24 | } |
| 25 | |
| 26 | export async function getFlutterConfigValue<T>(logger: Logger, flutterSdkPath: string | undefined, folder: string, flutterConfigKey: string): Promise<T> { |
| 27 | if (!flutterSdkPath) { |
| 28 | throw Error("Cannot find Android Studio without a Flutter SDK"); |
| 29 | } |
| 30 | const binPath = path.join(flutterSdkPath, flutterPath); |
| 31 | const args = ["config", "--machine"]; |
| 32 | |
| 33 | try { |
| 34 | const proc = await runToolProcess(logger, folder, binPath, args); |
| 35 | if (proc.exitCode === 0) { |
| 36 | // It's possible there is Flutter output before the JSON so trim everything before then. |
| 37 | let jsonString = proc.stdout.trim(); |
| 38 | const firstBrace = jsonString.indexOf("{"); |
| 39 | if (firstBrace > 0) { |
| 40 | jsonString = jsonString.substring(firstBrace); |
| 41 | } |
| 42 | const json = JSON.parse(jsonString); |
| 43 | return json[flutterConfigKey] as T; |
| 44 | } |
| 45 | throw Error(`Failed to run "flutter config --machine" (${proc.exitCode}): ${proc.stderr}`); |
| 46 | } catch (e) { |
| 47 | logger.error(e); |
| 48 | throw e; |
| 49 | } |
| 50 | } |
no test coverage detected