createFileAssets method

void createFileAssets(
  1. List pubspecAssets,
  2. Map morphemeAssets
)

Implementation

void createFileAssets(List<dynamic> pubspecAssets, Map morphemeAssets) {
  final outputDir = join(current, morphemeAssets.outputDir);

  for (var element in pubspecAssets) {
    final nameDir = element
        .toString()
        .split('/')
        .lastWhere((element) => element.isNotEmpty);
    if (RegExp(r'^\w+\.\w*').hasMatch(nameDir)) {
      continue;
    }

    final findOld = find(
      '*_${nameDir.snakeCase}.dart',
      workingDirectory: join(outputDir, 'src'),
    ).toList();

    for (var item in findOld) {
      delete(item);
    }

    final pathOutput = join(outputDir, 'src',
        '${projectName.snakeCase}_${nameDir.snakeCase}.dart');

    final assetsDir = '${morphemeAssets.pubspecDir}/$element'
        .replaceAll(RegExp(r'\/$'), '');

    pathOutput.write(
        '''abstract class ${projectName.pascalCase}${nameDir.pascalCase} {
// ignore: unused_field
static const String _assets = 'packages/${assetsDir.replaceAll(RegExp(r'\.'), current.split(separator).last)}';
''');

    final items = find(
      '[a-z]*.*',
      workingDirectory: join(current, assetsDir),
      recursive: false,
    ).toList();

    for (var item in items) {
      final nameWithExtension = item.split('/').last;
      pathOutput.append(
          '''  static const String ${nameWithExtension.split('.').first.camelCase} = '\$_assets/$nameWithExtension';''');
    }

    pathOutput.append('}');

    StatusHelper.generated(pathOutput);
  }
}