DartDefine.fromFile constructor

DartDefine.fromFile(
  1. String path, {
  2. required FileSystem fs,
})

Implementation

factory DartDefine.fromFile(String path, {required FileSystem fs}) {
  final file = fs.file(path);

  if (!file.existsSync()) {
    throw ArgumentError.value(
      file.path,
      'file',
      'File does not exist',
    );
  }

  final lines = file.readAsLinesSync();

  final defined = <String, String>{};

  for (final line in lines) {
    if (line.trim().isEmpty) continue;
    if (line.startsWith('#')) continue;

    final (:key, :value) = _parseEntry(line);

    defined[key] = value;
  }

  return DartDefine(defined: defined, files: [file.path]);
}