call method

void call({
  1. required String packageName,
  2. required List<String> filePaths,
  3. required String tempFilePath,
})

Create references for all the supplied filePaths.

A temporary Dart file will be created at tempFilePath that will contain all the given filePaths as imports.

Implementation

void call({
  required String packageName,
  required List<String> filePaths,
  required String tempFilePath,
}) {
  final fileReferences = [
    '// ignore_for_file: unused_import', // Ignore unused imports, they're just used for referencing untested files
    ...filePaths
        .map((filePath) => filePath
            .replaceFirst('lib', '') // Remove `lib` from file path
            .replaceAll('\\', '/'))
        .map(
          (filePath) =>
              "import 'package:$packageName$filePath';", // Add import for file
        ),
    'void main(){ /* No-op */ }',
  ].join('\n');

  if (!_doesFileExist(tempFilePath)) {
    _createFile(tempFilePath);
  }

  _writeToFile(fileReferences, tempFilePath);
}