ReleasePacker.fromJson constructor

ReleasePacker.fromJson(
  1. Map<String, Object?> json, {
  2. Map<String, String>? properties,
  3. Directory? rootDirectory,
  4. bool allowPropertiesFromEnv = false,
})

Implementation

factory ReleasePacker.fromJson(
  Map<String, Object?> json, {
  Map<String, String>? properties,
  Directory? rootDirectory,
  bool allowPropertiesFromEnv = false,
}) {
  json = resolveJsonMapProperties(json, properties,
      allowEnv: allowPropertiesFromEnv);

  var name = json.get<String>('name') ?? 'app';
  var versionStr = json.get<String>('version');

  if (versionStr == null) {
    var versionFrom = json.get<String>('version_from');
    if (versionFrom != null) {
      var json = _readFilePath(versionFrom, rootDirectory);
      versionStr = json is Map ? json['version'] : null;
    }
  }

  var version = SemanticVersioning.parse(versionStr ?? '0.0.1');

  var prepare = json.get<List>('prepare', [])!;
  var prepareCommands = ReleasePackerCommand.toCommands(jsonList: prepare);

  var finalize = json.get<List>('finalize', [])!;
  var finalizeCommands = ReleasePackerCommand.toCommands(jsonList: finalize);

  var files = json.get<List>('files', [])!;
  var releaseFiles = files.map((e) => ReleasePackerFile.fromJson(e)).toList();

  return ReleasePacker(name, version, releaseFiles,
      prepareCommands: prepareCommands,
      finalizeCommands: finalizeCommands,
      properties: properties,
      configDirectory: rootDirectory);
}