build method Null safety

bool build()

Implementation

bool build() {
  if (fileList.isEmpty) return false;
  List<JsonModel?> jsonModels = fileList
      .map((file) => buildJson(file as File))
      .cast<JsonModel?>()
      .toList();

  jsonModels.removeWhere((element) => element == null);

  List<JsonModel> jms = jsonModels.cast<JsonModel>();

  // index.dart
  File(path.join(distDir, 'index.dart'))
    ..createSync(recursive: true)
    ..writeAsStringSync(IndexTemplate(jms).toString());

  // converter.dart
  File(path.join(distDir, 'a.converter.dart'))
    ..createSync(recursive: true)
    ..writeAsStringSync(ConverterTemplate(jms).toString());

  jms.forEach((jsonModel) {
    File(jsonModel.distPath)
      ..createSync(recursive: true)
      ..writeAsStringSync((jsonModel.isResult
              ? ResultTemplate(jsonModel)
              : NormalTemplate(jsonModel))
          .toString());
  });

  return true;
}