iterateJsonFile method

bool iterateJsonFile()

Implementation

bool iterateJsonFile() {
  var error = StringBuffer();

  var indexFile = '';
  list.forEach((f) {
    if (FileSystemEntity.isFileSync(f.path)) {
      var fileExtension = '.json';
      if (f.path.endsWith(fileExtension)) {
        var file = File(f.path);
        var dartPath = f.path.replaceFirst(srcDir, distDir).replaceFirst(
              fileExtension,
              '.dart',
              f.path.length - fileExtension.length - 1,
            );
        List basenameString = path.basename(f.path).split('.');
        String fileName = basenameString.first;
        Map<String, dynamic> jsonMap = json.decode(file.readAsStringSync());

        var relative = dartPath.replaceFirst(distDir + path.separator, '').replaceAll(path.separator, '/');

        var jsonModel = JsonModel.fromMap(fileName, jsonMap, relativePath: relative);
        if (!generateFileFromJson(dartPath, jsonModel, fileName)) {
          error.write('cant write $dartPath');
        }

        print('generated: $relative');
        indexFile += "export '$relative';\n";
      }
    }
  });
  if (indexFile.isNotEmpty) {
    File(path.join(distDir, 'index.dart')).writeAsStringSync(indexFile);
  }
  return indexFile.isNotEmpty;
}