process method

  1. @override
void process(
  1. String? path
)
override

Implementation

@override
void process(String? path) {
  print('Embed: ${config!.dir}');
  final outFileName = config!.outputFile ?? 'index.dart';
  var filesPaths = listFiles(config!.dir!, config!.recursive!, true);

  var relativePaths =
      filesPaths.map((i) => p.relative(i!, from: config!.dir)).toList();
  relativePaths.remove(outFileName);
  if (relativePaths.isEmpty) return null;

  final outFilePath = p.join(config!.dir!, outFileName);

  try {
    var output = formatCode(filesPaths.map((i) {
      final relFilePath = p.relative(i!, from: config!.dir);
      if (relFilePath == outFileName) return '';

      final fileName = p.basename(relFilePath);
      final slug = slugify(fileName, delimiter: '');
      return 'final $slug = \'' +
          Strings.toEscaped(File(i)
              .readAsStringSync(encoding: Utf8Codec(allowMalformed: true))) +
          '\';\n';
    }).join(''));

    fileWriteString(outFilePath, output);
  } catch (e) {
    print(e);
    return;
  }

  _lastGenerated = outFilePath;
}