getDenoConfig function

Future<DenoConfigurationFile?> getDenoConfig(
  1. List<String> tokens,
  2. ExecuteCommandFunction executeShellCommand
)

Implementation

Future<DenoConfigurationFile?> getDenoConfig(
  List<String> tokens,
  ExecuteCommandFunction executeShellCommand,
) async {
  final configPath = getConfigPath(tokens);
  String jsonString;

  if (configPath != null) {
    final output = await executeShellCommand(ExecuteCommandInput(
      command: "cat",
      args: [configPath],
    ));
    jsonString = output.stdout;
  } else {
    // Move backwards...
    final output = await executeShellCommand(const ExecuteCommandInput(
      command: "bash",
      args: [
        "-c",
        "until [[ ( -f deno.json || -f deno.jsonc || \$PWD = '/' ) ]]; do cd ..; done; \\cat deno.json 2>/dev/null || \\cat deno.jsonc 2>/dev/null",
      ],
    ));
    jsonString = output.stdout;
  }

  try {
    if (jsonString.trim().isEmpty) return null;
    return DenoConfigurationFile.fromJson(
        jsonDecode(stripJsonComments(jsonString)));
  } catch (e) {
    // print("Error parsing config file: $e");
    return null;
  }
}