Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sz build web command to Sharezone Repo CLI #688

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions tools/sz_repo_cli/lib/src/commands/src/build_web_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:args/command_runner.dart';
import 'package:sz_repo_cli/src/common/common.dart';

final _webStages = [
'stable',
'beta',
'alpha',
];

/// The different flavors of the Web app.
final _webFlavors = [
'prod',
'dev',
];

class BuildWebCommand extends Command {
final SharezoneRepo _repo;

BuildWebCommand(this._repo) {
argParser
..addOption(
releaseStageOptionName,
abbr: 's',
allowed: _webStages,
defaultsTo: 'stable',
)
..addOption(
flavorOptionName,
allowed: _webFlavors,
help: 'The flavor to build for.',
defaultsTo: 'prod',
);
}

static const releaseStageOptionName = 'stage';
static const flavorOptionName = 'flavor';

@override
String get description => 'Build the Sharezone web app in release mode.';

@override
String get name => 'web';

@override
Future<void> run() async {
// Is used so that runProcess commands print the command that was run. Right
// now this can't be done via an argument.
//
// This workaround should be addressed in the future.
isVerbose = true;

await _buildApp();
print('Build finished 🎉 ');
}

Future<void> _buildApp() async {
try {
final flavor = argResults![flavorOptionName] as String;
final stage = argResults![releaseStageOptionName] as String;
await runProcessSucessfullyOrThrow(
'fvm',
[
'flutter',
'build',
'web',
'--target',
'lib/main_$flavor.dart',
'--release',
'--web-renderer',
'canvaskit',
'--dart-define',
'DEVELOPMENT_STAGE=${stage.toUpperCase()}'
],
workingDirectory: _repo.sharezoneFlutterApp.location.path,
);
} catch (e) {
throw Exception('Failed to build web app: $e');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,17 @@ class DeployWebAppCommand extends Command {
await runProcessSucessfullyOrThrow(
'fvm',
[
'flutter',
'dart',
'run',
'sz_repo_cli',
'build',
'web',
'--target',
'lib/main_${webAppConfig.flavor}.dart',
'--release',
'--web-renderer',
'canvaskit',
'--dart-define',
'DEVELOPMENT_STAGE=${releaseStage.toUpperCase()}'
'--flavor',
webAppConfig.flavor,
'--stage',
releaseStage
],
workingDirectory: _repo.sharezoneFlutterApp.location.path,
workingDirectory: _repo.sharezoneCiCdTool.path,
);

String? deployMessage;
Expand Down
5 changes: 4 additions & 1 deletion tools/sz_repo_cli/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:path/path.dart' as p;
import 'package:sz_repo_cli/src/commands/src/add_license_headers_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_android_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_web_command.dart';
import 'package:sz_repo_cli/src/commands/src/check_license_headers_command.dart';
import 'package:sz_repo_cli/src/commands/src/format_command.dart';
import 'package:sz_repo_cli/src/commands/src/license_headers_command.dart';
Expand Down Expand Up @@ -45,7 +46,9 @@ Future<void> main(List<String> args) async {
..addSubcommand(CheckLicenseHeadersCommand(repo))
..addSubcommand(AddLicenseHeadersCommand(repo)))
..addCommand(DeployCommand()..addSubcommand(DeployWebAppCommand(repo)))
..addCommand(BuildCommand()..addSubcommand(BuildAndroidCommand(repo)));
..addCommand(BuildCommand()
..addSubcommand(BuildAndroidCommand(repo))
..addSubcommand(BuildWebCommand(repo)));

await commandRunner.run(args).catchError((Object e) {
final toolExit = e as ToolExit;
Expand Down