-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create PubspecReader and use it (#868)
- Loading branch information
1 parent
380f6c5
commit efd1cd2
Showing
5 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/patrol_cli/lib/src/features/test/pubspec_reader.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:file/file.dart'; | ||
import 'package:path/path.dart' show join; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
class PatrolPubspecConfig { | ||
PatrolPubspecConfig({this.android, this.ios}); | ||
|
||
AndroidPubspecConfig? android; | ||
IOSPubspecConfig? ios; | ||
} | ||
|
||
class AndroidPubspecConfig { | ||
AndroidPubspecConfig({this.packageName, this.appName}); | ||
String? packageName; | ||
String? appName; | ||
} | ||
|
||
class IOSPubspecConfig { | ||
IOSPubspecConfig({this.bundleId, this.appName}); | ||
|
||
String? bundleId; | ||
String? appName; | ||
} | ||
|
||
/// Reads Patrol CLI configuration block from pubspec.yaml. | ||
class PubspecReader { | ||
const PubspecReader({ | ||
required Directory projectRoot, | ||
required FileSystem fs, | ||
}) : _projectRoot = projectRoot, | ||
_fs = fs; | ||
|
||
final Directory _projectRoot; | ||
final FileSystem _fs; | ||
|
||
PatrolPubspecConfig read() { | ||
final filePath = join(_projectRoot.path, 'pubspec.yaml'); | ||
final file = _fs.file(filePath); | ||
|
||
if (!file.existsSync()) { | ||
throw FileSystemException("pubspec.yaml doesn't exist", filePath); | ||
} | ||
|
||
final contents = file.readAsStringSync(); | ||
final yaml = loadYaml(contents) as Map; | ||
|
||
final config = PatrolPubspecConfig(); | ||
final patrol = yaml['patrol'] as Map?; | ||
if (patrol != null) { | ||
final patrol = yaml['patrol'] as Map; | ||
final android = patrol['android'] as Map?; | ||
if (android != null) { | ||
final androidConfig = AndroidPubspecConfig(); | ||
config.android = androidConfig; | ||
|
||
final dynamic packageName = android['package_name']; | ||
if (packageName != null && packageName is String?) { | ||
androidConfig.packageName = packageName; | ||
} | ||
final dynamic appName = android['app_name']; | ||
if (appName != null && appName is String?) { | ||
androidConfig.appName = appName; | ||
} | ||
} | ||
|
||
final ios = patrol['ios'] as Map?; | ||
if (ios != null) { | ||
final iosConfig = IOSPubspecConfig(); | ||
config.ios = iosConfig; | ||
|
||
final dynamic bundleId = ios['bundle_id']; | ||
if (bundleId != null && bundleId is String?) { | ||
iosConfig.bundleId = bundleId; | ||
} | ||
final dynamic appName = ios['app_name']; | ||
if (appName != null && appName is String?) { | ||
iosConfig.appName = appName; | ||
} | ||
} | ||
} | ||
|
||
return config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters