init static method

ConfigModel init()

Initializes the model for use within the tool

Implementation

static ConfigModel init() {
  // Fetch the pubspec.yaml content
  var configContent = FileService.getPubspecContent();

  // convert it to a yaml document
  var pubspecYaml = yaml.loadYamlDocument(configContent!.content);

  // retrieve the config portion
  var vermanConfig = Map<String, dynamic>.from(
    pubspecYaml.contents.value['verman_config'],
  );

  // extract the path forf the custom from the config
  var path = vermanConfig['path'] == null
      ? ''
      : p.join(Directory.current.path, vermanConfig['path']);

  // if the path is not empty, then load the custom config file
  if (path.isNotEmpty) {
    var content = FileService.getFileContent(path);
    var contentYaml = yaml.loadYamlDocument(content!.content);
    vermanConfig.addAll(
      Map<String, dynamic>.from(contentYaml.contents.value),
    );
  }

  // if the config is not empty, then return the model
  if (vermanConfig.isNotEmpty) {
    return ConfigModel.fromJson(vermanConfig);
  }

  // if the config is empty, then return the default model
  return ConfigModel(
    androidGradlePath: p.join(
      Directory.current.path,
      'android',
      'app',
      'build.gradle',
    ),
    iosInfoPlistPath: p.join(
      Directory.current.path,
      'ios',
      'Runner',
      'Info.plist',
    ),
    configFilePath: '',
  );
}