MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / getFlutterConfigValue

Function getFlutterConfigValue

src/extension/utils/misc.ts:26–50  ·  view source on GitHub ↗
(logger: Logger, flutterSdkPath: string | undefined, folder: string, flutterConfigKey: string)

Source from the content-addressed store, hash-verified

24}
25
26export 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}

Callers 2

getAndroidStudioDirMethod · 0.90

Calls 2

runToolProcessFunction · 0.90
errorMethod · 0.65

Tested by

no test coverage detected