Skip to content

Commit

Permalink
feat: add build options and copyWith options
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Sep 3, 2023
1 parent 1490530 commit 1b7aa63
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/firebase_build/lib/app_build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export 'src/app_build.dart'
flutterWebAppBuildAndServe,
flutterWebAppClean,
FlutterFirebaseWebAppOptions,
FlutterWebAppBuildOptions,
FlutterWebRenderer,
FlutterFirebaseWebAppBuilder;
33 changes: 32 additions & 1 deletion packages/firebase_build/lib/src/app_build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,31 @@ Future<void> flutterWebAppBuildAndServe(String directory,
deployDir: deployDir);
}

enum FlutterWebRenderer { html, canvasKit }

class FlutterWebAppBuildOptions {
FlutterWebRenderer? renderer;
FlutterWebAppBuildOptions({this.renderer});
}

/// Web app options
class FlutterFirebaseWebAppOptions {
final String path;
final FlutterWebAppBuildOptions? buildOptions;
final FirebaseDeployOptions deployOptions;

FlutterFirebaseWebAppOptions({this.path = '.', required this.deployOptions});
FlutterFirebaseWebAppOptions(
{this.path = '.', required this.deployOptions, this.buildOptions});

FlutterFirebaseWebAppOptions copyWith(
{String? path,
FlutterWebAppBuildOptions? buildOptions,
FirebaseDeployOptions? deployOptions}) {
return FlutterFirebaseWebAppOptions(
path: path ?? this.path,
buildOptions: buildOptions ?? this.buildOptions,
deployOptions: deployOptions ?? this.deployOptions);
}
}

/// Convenient builder.
Expand All @@ -53,6 +72,18 @@ class FlutterFirebaseWebAppBuilder {
FlutterFirebaseWebAppBuilder({required this.options});

Future<void> build() async {
var shell = Shell().cd(options.path);
var renderOptions = '';
switch (options.buildOptions?.renderer) {
case FlutterWebRenderer.html:
renderOptions = ' --web-renderer html';
break;
case FlutterWebRenderer.canvasKit:
renderOptions = ' --web-renderer canvaskit';
break;
default:
}
await shell.run('flutter build web$renderOptions');
await flutterWebAppBuild(options.path);
await firebaseWebAppBuildToDeploy(options.path);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/firebase_build/lib/src/firebase_deploy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class FirebaseDeployOptions {
required this.hostingId,
required this.target,
});

/// Copy with new values.
FirebaseDeployOptions copyWith({
String? projectId,
String? hostingId,
String? target,
}) {
return FirebaseDeployOptions(
projectId: projectId ?? this.projectId,
hostingId: hostingId ?? this.hostingId,
target: target ?? this.target,
);
}
}

String _fixFolder(String path, String folder) {
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_build/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tekartik_firebase_build
description: Firebase build and deploy helpers
version: 0.1.1
version: 0.1.2
publish_to: none

environment:
Expand Down

0 comments on commit 1b7aa63

Please sign in to comment.