Skip to content

Commit

Permalink
Release 2.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
AngeloAvv committed Apr 1, 2024
1 parent 5e23a3a commit fea691e
Show file tree
Hide file tree
Showing 24 changed files with 380 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## NEXT

## 2.2.3

* Fixed add_firebase_build_phase script output paths
* Fixed "Unable to load contents of file list"

## 2.2.2

* Fixed misleading error message: The following fields were missing
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ software:

These prerequisites are needed to manipulate the iOS and macOS projects and
schemes. If you are interested in flavorizing Android only, you can skip
this step. Keep in mind that you will have to use a custom instructions
set with Android and Flutter processors only, otherwise an error will
occur.
this step.

If your app uses a Flutter plugin and you plan to create flavors for iOS and macOS, you need to make
sure there's an existing Podfile file under the ios/macos folder. This might lead to problems like
["Unable to load contents of file list"](doc%2Ftroubleshooting%2Funable-to-load-contents-of-file-list%2FREADME.md).

### Installation

Expand All @@ -44,7 +46,7 @@ in your [pubspec.yaml](https://dart.dev/tools/pub/pubspec):

```yaml
dev_dependencies:
flutter_flavorizr: ^2.2.2
flutter_flavorizr: ^2.2.3
```
You can install packages from the command line:
Expand Down Expand Up @@ -130,7 +132,7 @@ flavorizr:
| app | Object | | false | An object describing the general capabilities of an app |
| flavors | Array | | true | An array of items. Each of them describes a flavor configuration |
| [instructions](#available-instructions) | Array | | false | An array of instructions to customize the flavorizr process |
| assetsUrl | String | [link](https://github.com/AngeloAvv/flutter_flavorizr/releases/download/v2.2.2/assets.zip) | false | A string containing the URL of the zip assets file. The default points to the current release |
| assetsUrl | String | [link](https://github.com/AngeloAvv/flutter_flavorizr/releases/download/v2.2.3/assets.zip) | false | A string containing the URL of the zip assets file. The default points to the current release |
| ide | String | | false | The IDE in which the app is being developed. Currently only `vscode` or `idea` |

##### <a href="#available-instructions">Available instructions</a>
Expand All @@ -152,13 +154,15 @@ flavorizr:
| google:firebase | Google | Adds Google Firebase configurations for Android and iOS for each flavor |
| huawei:agconnect | Huawei | Adds Huawei AGConnect configurations for Android for each flavor |
| ide:config | IDE | Generates debugging configurations for each flavor of your IDE |
| ios:podfile | iOS | Updates the Pods-Runner path for each flavor |
| ios:xcconfig | iOS | Creates a set of xcconfig files for each flavor and build configuration |
| ios:buildTargets | iOS | Creates a set of build targets for each flavor and build configuration |
| ios:schema | iOS | Creates a set of schemas for each flavor |
| ios:dummyAssets | iOS | Generates some default icons for your custom flavors |
| ios:icons | iOS | Creates a set of icons for each flavor according to the icon directive |
| ios:plist | iOS | Updates the info.plist file |
| ios:launchScreen | iOS | Creates a set of launchscreens for each flavor |
| macos:podfile | macOS | Updates the Pods-Runner path for each flavor |
| macos:xcconfig | macOS | Creates a set of xcconfig files for each flavor and build configuration |
| macos:configs | macOS | Creates a set of xcconfig files for each flavor and build configuration |
| macos:buildTargets | macOS | Creates a set of build targets for each flavor and build configuration |
Expand Down Expand Up @@ -428,13 +432,15 @@ By default, when you do not specify a custom set of processors by appending the
* flutter:pages
* flutter:main
* flutter:targets
* ios:podfile
* ios:xcconfig
* ios:buildTargets
* ios:schema
* ios:dummyAssets
* ios:icons
* ios:plist
* ios:launchScreen
* macos:podfile
* macos:xcconfig
* macos:configs
* macos:buildTargets
Expand All @@ -459,9 +465,9 @@ class F {
static String get title {
switch (appFlavor) {
case Flavor.APPLE:
case Flavor.apple:
return 'Apple App';
case Flavor.BANANA:
case Flavor.banana:
return 'Banana App';
default:
return 'title';
Expand Down
18 changes: 10 additions & 8 deletions assets/scripts/darwin/add_build_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
require 'json'
require 'base64'

if ARGV.length != 6
puts 'We need exactly six arguments'
if ARGV.length != 5
puts 'We need exactly five arguments'
exit
end

project_path = ARGV[0]
file_path = ARGV[1]
flavor = ARGV[2]
# bundleId = ARGV[3]
mode = ARGV[4]
additional_build_settings = JSON.parse(Base64.decode64(ARGV[5]))
mode = ARGV[3]
additional_build_settings = JSON.parse(Base64.decode64(ARGV[4]))

project = Xcodeproj::Project.open(project_path)
config_name = "#{mode}-#{flavor}"
config_mode = mode.downcase == 'debug' ? :debug : :release
file_ref = project.files.detect { |file| file.path == file_path }

# Build configuration list for PBXProject "Runner"
base_config = project.build_configuration_list.build_configurations.detect { |config| config.name == mode }

build_config = project.add_build_configuration("#{mode}-#{flavor}", mode.downcase == 'debug' ? :debug : :release)
build_config.base_configuration_reference = project.files.detect { |file| file.path == file_path }
build_config = project.add_build_configuration(config_name, config_mode)
build_config.base_configuration_reference = file_ref
build_config.build_settings = base_config.build_settings.clone
build_config.build_settings = build_config.build_settings.merge(additional_build_settings)

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.2"
version: "2.2.3"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parser/models/flavorizr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Flavorizr {

@JsonKey(
defaultValue:
'https://github.com/AngeloAvv/flutter_flavorizr/releases/download/v2.2.2/assets.zip')
'https://github.com/AngeloAvv/flutter_flavorizr/releases/download/v2.2.3/assets.zip')
final String assetsUrl;

@JsonKey()
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parser/models/flavorizr.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion lib/src/parser/models/flavors/darwin/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

enum Target { debug, profile, release }
enum Target {
debug('debug'),
profile('release'),
release('release');

final String darwinTarget;

const Target(this.darwinTarget);
}
49 changes: 49 additions & 0 deletions lib/src/processors/commons/dynamic_file_string_processor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 Angelo Cassano
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

import 'package:flutter_flavorizr/src/processors/commons/abstract_file_string_processor.dart';

class DynamicFileStringProcessor extends AbstractFileStringProcessor {
DynamicFileStringProcessor(
super.path,
super.processor, {
required super.config,
});

@override
void execute() {
if (!file.existsSync()) {
return;
}

processor.input = file.readAsStringSync();

super.execute();
}

@override
String toString() =>
"DynamicFileStringProcessor: writing on file $path with nested $processor if exists";
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class DarwinBuildConfigurationsProcessor extends QueueProcessor {
String project,
String file,
String flavorName,
String bundleId,
Map<String, dynamic> buildConfigurations, {
required Flavorizr config,
}) : super(
Expand All @@ -52,7 +51,6 @@ class DarwinBuildConfigurationsProcessor extends QueueProcessor {
utils.flatPath(
'$file/$flavorName${target.name.capitalize}.xcconfig'),
flavorName,
bundleId,
target.name.capitalize,
base64.encode(utf8.encode(jsonEncode(buildConfigurations))),
],
Expand Down
81 changes: 81 additions & 0 deletions lib/src/processors/darwin/podfile_processor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2024 Angelo Cassano
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

import 'package:flutter_flavorizr/src/exception/malformed_resource_exception.dart';
import 'package:flutter_flavorizr/src/extensions/extensions_string.dart';
import 'package:flutter_flavorizr/src/parser/models/flavors/darwin/enums.dart';
import 'package:flutter_flavorizr/src/processors/commons/string_processor.dart';

class PodfileProcessor extends StringProcessor {
static const projectEntryPoint = 'project \'Runner\', {';
static const projectClosure = '}';

final List<String> flavors;

PodfileProcessor({
super.input,
required this.flavors,
required super.config,
});

@override
String execute() {
final projectPosition = input!.indexOf(projectEntryPoint);
final closedProjectPosition = input!.indexOf(projectClosure);

if (projectPosition < 0) {
throw MalformedResourceException(input!);
}

final buffer = StringBuffer();

_appendStartContent(buffer, projectPosition);
_appendFlavors(buffer);

_appendEndContent(buffer, closedProjectPosition);

return buffer.toString();
}

void _appendStartContent(StringBuffer buffer, int position) {
buffer.writeln(input!.substring(0, position + projectEntryPoint.length));
}

void _appendFlavors(StringBuffer buffer) {
for (final flavor in flavors) {
for (final target in Target.values) {
buffer.writeln(
' \'${target.name.capitalize}-$flavor\' => :${target.darwinTarget},');
}
}
}

void _appendEndContent(StringBuffer buffer, int position) {
buffer.write(input!.substring(position));
}

@override
String toString() => 'PodfileProcessor';
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class IOSBuildConfigurationsTargetsProcessor extends QueueProcessor {
project,
file,
flavorName,
flavor.ios!.bundleId,
{}
..addAll(config.app?.ios != null
? config.app!.ios!.buildSettings
Expand Down
2 changes: 2 additions & 0 deletions lib/src/processors/ios/xcconfig/ios_xcconfig_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class IOSXCConfigProcessor extends StringProcessor {
}

void _appendIncludes(StringBuffer buffer) {
buffer.writeln(
'#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.${_target.darwinTarget}.xcconfig"');
buffer.writeln('#include "Generated.xcconfig"');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class MacOSBuildConfigurationsTargetsProcessor extends QueueProcessor {
project,
file,
flavorName,
flavor.macos!.bundleId,
{}
..addAll(config.app?.macos != null
? config.app!.macos!.buildSettings
Expand Down
20 changes: 20 additions & 0 deletions lib/src/processors/processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ import 'package:flutter_flavorizr/src/processors/commons/copy_file_processor.dar
import 'package:flutter_flavorizr/src/processors/commons/copy_folder_processor.dart';
import 'package:flutter_flavorizr/src/processors/commons/delete_file_processor.dart';
import 'package:flutter_flavorizr/src/processors/commons/download_file_processor.dart';
import 'package:flutter_flavorizr/src/processors/commons/dynamic_file_string_processor.dart';
import 'package:flutter_flavorizr/src/processors/commons/existing_file_string_processor.dart';
import 'package:flutter_flavorizr/src/processors/commons/new_file_string_processor.dart';
import 'package:flutter_flavorizr/src/processors/commons/queue_processor.dart';
import 'package:flutter_flavorizr/src/processors/commons/unzip_file_processor.dart';
import 'package:flutter_flavorizr/src/processors/darwin/darwin_schemas_processor.dart';
import 'package:flutter_flavorizr/src/processors/darwin/podfile_processor.dart';
import 'package:flutter_flavorizr/src/processors/flutter/flutter_flavors_processor.dart';
import 'package:flutter_flavorizr/src/processors/flutter/target/flutter_targets_file_processor.dart';
import 'package:flutter_flavorizr/src/processors/google/firebase/firebase_processor.dart';
Expand Down Expand Up @@ -83,6 +85,7 @@ class Processor extends AbstractProcessor<void> {
'flutter:targets',

// iOS
'ios:podfile',
'ios:xcconfig',
'ios:buildTargets',
'ios:schema',
Expand All @@ -92,6 +95,7 @@ class Processor extends AbstractProcessor<void> {
'ios:launchScreen',

// macOS
'macos:podfile',
'macos:xcconfig',
'macos:configs',
'macos:buildTargets',
Expand Down Expand Up @@ -222,6 +226,14 @@ class Processor extends AbstractProcessor<void> {
),

//iOS
'ios:podfile': () => DynamicFileStringProcessor(
K.iOSPodfilePath,
PodfileProcessor(
flavors: flavorizr.iosFlavors.keys.toList(growable: false),
config: flavorizr,
),
config: flavorizr,
),
'ios:xcconfig': () => IOSXCConfigTargetsFileProcessor(
'ruby',
K.tempDarwinAddFileScriptPath,
Expand Down Expand Up @@ -265,6 +277,14 @@ class Processor extends AbstractProcessor<void> {
),

// MacOS
'macos:podfile': () => DynamicFileStringProcessor(
K.macOSPodfilePath,
PodfileProcessor(
flavors: flavorizr.macosFlavors.keys.toList(growable: false),
config: flavorizr,
),
config: flavorizr,
),
'macos:xcconfig': () => MacOSXCConfigTargetsFileProcessor(
K.macOSFlutterPath,
config: flavorizr,
Expand Down
Loading

0 comments on commit fea691e

Please sign in to comment.