Skip to content

Commit

Permalink
Add CI and resolve some lints and fix tests (#433)
Browse files Browse the repository at this point in the history
* ci: Add CI

* chore: Resolve lint

* fix: Tests
  • Loading branch information
lsaudon committed Oct 23, 2022
1 parent 7d1472b commit d03227c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 35 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,26 @@
name: flutter_native_splash

on:
pull_request:
paths-ignore:
- '**.md'
push:
branches:
- master
paths-ignore:
- '**.md'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
- name: Install Dependencies
run: flutter packages get
- name: Format
run: flutter format . --set-exit-if-changed
- name: Analyze
run: flutter analyze .
- name: Test
run: flutter test --test-randomize-ordering-seed random
35 changes: 21 additions & 14 deletions lib/cli_commands.dart
Expand Up @@ -21,24 +21,23 @@ part 'web.dart';
late _FlavorHelper _flavorHelper;

/// Create splash screens for Android and iOS
void createSplash({String? path, String? flavor}) {
void createSplash({
required String? path,
required String? flavor,
}) {
if (flavor != null) {
print(
'''
╔════════════════════════════════════════════════════════════════════════════╗
║ Flavor detected! ║
╠════════════════════════════════════════════════════════════════════════════╣
║ Setting up the $flavor flavor.
║ Setting up the $flavor flavor.
╚════════════════════════════════════════════════════════════════════════════╝
''',
);
}

// It is important that the flavor setup occurs as soon as possible.
// So before we generate anything, we need to setup the flavor (even if it's the default one).
_flavorHelper = _FlavorHelper(flavor);

final config = getConfig(configFile: path);
final config = getConfig(configFile: path, flavor: flavor);
createSplashByConfig(config);
}

Expand Down Expand Up @@ -205,14 +204,14 @@ void createSplashByConfig(Map<String, dynamic> config) {
}
}

const String _greet = '''
const String greet = '''
✅ Native splash complete.
Now go finish building something awesome! 💪 You rock! 🤘🤩
Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash
''';

const String _whatsNew = '''
const String whatsNew = '''
╔════════════════════════════════════════════════════════════════════════════╗
║ WHAT IS NEW: ║
╠════════════════════════════════════════════════════════════════════════════╣
Expand All @@ -222,14 +221,16 @@ Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_n
║ Check the docs for more info. ║
╚════════════════════════════════════════════════════════════════════════════╝
''';
print(_whatsNew + _greet);
print(whatsNew + greet);
}

/// Remove any splash screen by setting the default white splash
void removeSplash({String? path, String? flavor}) {
_flavorHelper = _FlavorHelper(flavor);
void removeSplash({
required String? path,
required String? flavor,
}) {
print("Restoring Flutter's default native splash screen...");
final config = getConfig(configFile: path);
final config = getConfig(configFile: path, flavor: flavor);

final removeConfig = <String, dynamic>{
'color': '#ffffff',
Expand Down Expand Up @@ -281,7 +282,13 @@ String? _checkImageExists({
}

/// Get config from `pubspec.yaml` or `flutter_native_splash.yaml`
Map<String, dynamic> getConfig({String? configFile}) {
Map<String, dynamic> getConfig({
required String? configFile,
required String? flavor,
}) {
// It is important that the flavor setup occurs as soon as possible.
// So before we generate anything, we need to setup the flavor (even if it's the default one).
_flavorHelper = _FlavorHelper(flavor);
// if `flutter_native_splash.yaml` exists use it as config file, otherwise use `pubspec.yaml`
String filePath;
if (configFile != null) {
Expand Down
12 changes: 6 additions & 6 deletions lib/ios.dart
Expand Up @@ -18,7 +18,7 @@ final List<_IosLaunchImageTemplate> _iOSSplashImages =
), // original image must be @4x
];

final List<_IosLaunchImageTemplate> iOSSplashImagesDark =
final List<_IosLaunchImageTemplate> _iOSSplashImagesDark =
<_IosLaunchImageTemplate>[
_IosLaunchImageTemplate(fileName: 'LaunchImageDark.png', pixelDensity: 1),
_IosLaunchImageTemplate(fileName: 'LaunchImageDark@2x.png', pixelDensity: 2),
Expand All @@ -36,7 +36,7 @@ final List<_IosLaunchImageTemplate> _iOSBrandingImages =
pixelDensity: 3,
), // original image must be @4x
];
final List<_IosLaunchImageTemplate> iOSBrandingImagesDark =
final List<_IosLaunchImageTemplate> _iOSBrandingImagesDark =
<_IosLaunchImageTemplate>[
_IosLaunchImageTemplate(fileName: 'BrandingImageDark.png', pixelDensity: 1),
_IosLaunchImageTemplate(
Expand Down Expand Up @@ -81,10 +81,10 @@ void _createiOSSplash({
_applyImageiOS(
imagePath: darkImagePath,
dark: true,
list: iOSSplashImagesDark,
list: _iOSSplashImagesDark,
);
} else {
for (final template in iOSSplashImagesDark) {
for (final template in _iOSSplashImagesDark) {
final file =
File(_flavorHelper.iOSAssetsLaunchImageFolder + template.fileName);
if (file.existsSync()) file.deleteSync();
Expand All @@ -107,11 +107,11 @@ void _createiOSSplash({
_applyImageiOS(
imagePath: brandingDarkImagePath,
dark: true,
list: iOSBrandingImagesDark,
list: _iOSBrandingImagesDark,
targetPath: _flavorHelper.iOSAssetsBrandingImageFolder,
);
} else {
for (final template in iOSBrandingImagesDark) {
for (final template in _iOSBrandingImagesDark) {
final file =
File(_flavorHelper.iOSAssetsBrandingImageFolder + template.fileName);
if (file.existsSync()) file.deleteSync();
Expand Down
10 changes: 5 additions & 5 deletions lib/web.dart
Expand Up @@ -26,7 +26,7 @@ void _createWebSplash({
}

darkImagePath ??= imagePath;
createWebImages(
_createWebImages(
imagePath: imagePath,
webSplashImages: [
_WebLaunchImageTemplate(fileName: 'light-1x.png', pixelDensity: 1),
Expand All @@ -35,7 +35,7 @@ void _createWebSplash({
_WebLaunchImageTemplate(fileName: 'light-4x.png', pixelDensity: 4),
],
);
createWebImages(
_createWebImages(
imagePath: darkImagePath,
webSplashImages: [
_WebLaunchImageTemplate(fileName: 'dark-1x.png', pixelDensity: 1),
Expand All @@ -46,7 +46,7 @@ void _createWebSplash({
);

brandingDarkImagePath ??= brandingImagePath;
createWebImages(
_createWebImages(
imagePath: brandingImagePath,
webSplashImages: [
_WebLaunchImageTemplate(fileName: 'branding-1x.png', pixelDensity: 1),
Expand All @@ -55,7 +55,7 @@ void _createWebSplash({
_WebLaunchImageTemplate(fileName: 'branding-4x.png', pixelDensity: 4),
],
);
createWebImages(
_createWebImages(
imagePath: brandingDarkImagePath,
webSplashImages: [
_WebLaunchImageTemplate(
Expand Down Expand Up @@ -124,7 +124,7 @@ void createBackgroundImages({
}
}

void createWebImages({
void _createWebImages({
required String? imagePath,
required List<_WebLaunchImageTemplate> webSplashImages,
}) {
Expand Down
17 changes: 7 additions & 10 deletions test/flutter_native_splash_test.dart
Expand Up @@ -17,19 +17,12 @@ void main() {
final testDir =
p.join('.dart_tool', 'flutter_native_splash', 'test', 'config_file');

late String currentDirectory;
void setCurrentDirectory(String path) {
final pathValue = p.join(testDir, path);
Directory(path).createSync(recursive: true);
Directory(pathValue).createSync(recursive: true);
Directory.current = pathValue;
}

setUp(() {
currentDirectory = Directory.current.path;
});
tearDown(() {
Directory.current = currentDirectory;
});
test('default', () {
setCurrentDirectory('default');
File('flutter_native_splash.yaml').writeAsStringSync(
Expand All @@ -40,6 +33,7 @@ flutter_native_splash:
);
final Map<String, dynamic> config = getConfig(
configFile: 'flutter_native_splash.yaml',
flavor: null,
);
File('flutter_native_splash.yaml').deleteSync();
expect(config, isNotNull);
Expand All @@ -53,13 +47,16 @@ flutter_native_splash:
color: "#00ff00"
''',
);
final Map<String, dynamic> config = getConfig();
final Map<String, dynamic> config = getConfig(
configFile: null,
flavor: null,
);
File('pubspec.yaml').deleteSync();
expect(config, isNotNull);
expect(config['color'], '#00ff00');

// fails if config file is missing
expect(() => getConfig(), throwsException);
expect(() => getConfig(configFile: null, flavor: null), throwsException);
});
});
}

0 comments on commit d03227c

Please sign in to comment.