diff --git a/tools/sz_repo_cli/lib/src/commands/src/build_website_command.dart b/tools/sz_repo_cli/lib/src/commands/src/build_website_command.dart new file mode 100644 index 000000000..88418d3d8 --- /dev/null +++ b/tools/sz_repo_cli/lib/src/commands/src/build_website_command.dart @@ -0,0 +1,70 @@ +// 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 'dart:io'; + +import 'package:sz_repo_cli/src/common/common.dart'; + +/// The different flavors of the website. +final _websiteFlavors = [ + 'prod', + 'dev', +]; + +class BuildWebsiteCommand extends CommandBase { + BuildWebsiteCommand(super.context) { + argParser.addOption( + flavorOptionName, + allowed: _websiteFlavors, + help: 'The flavor to build for.', + defaultsTo: 'prod', + ); + } + + static const flavorOptionName = 'flavor'; + + @override + String get description => 'Build the Sharezone website in release mode.'; + + @override + String get name => 'website'; + + @override + Future 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 _buildWebsite(); + stdout.writeln('Build finished 🎉 '); + } + + Future _buildWebsite() async { + try { + final flavor = argResults![flavorOptionName] as String; + await processRunner.runCommand( + [ + 'fvm', + 'flutter', + 'build', + 'web', + '--release', + '--dart-define', + 'FLAVOR=$flavor', + '--pwa-strategy', + 'none', + ], + workingDirectory: repo.sharezoneWebsite.location, + ); + } catch (e) { + throw Exception('Failed to build website: $e'); + } + } +} diff --git a/tools/sz_repo_cli/lib/src/main.dart b/tools/sz_repo_cli/lib/src/main.dart index 7dbc0c411..7c18cd82e 100644 --- a/tools/sz_repo_cli/lib/src/main.dart +++ b/tools/sz_repo_cli/lib/src/main.dart @@ -20,6 +20,7 @@ import 'package:sz_repo_cli/src/commands/src/build_macos_command.dart'; import 'package:sz_repo_cli/src/commands/src/build_runner_build_command.dart'; import 'package:sz_repo_cli/src/commands/src/build_runner_command.dart'; import 'package:sz_repo_cli/src/commands/src/build_web_command.dart'; +import 'package:sz_repo_cli/src/commands/src/build_website_command.dart'; import 'package:sz_repo_cli/src/commands/src/check_license_headers_command.dart'; import 'package:sz_repo_cli/src/commands/src/deploy_android_command.dart'; import 'package:sz_repo_cli/src/commands/src/deploy_ios_command.dart'; @@ -71,7 +72,8 @@ Future main(List args) async { ..addSubcommand(BuildAndroidCommand(context)) ..addSubcommand(BuildMacOsCommand(context)) ..addSubcommand(BuildWebCommand(context)) - ..addSubcommand(BuildIosCommand(context))) + ..addSubcommand(BuildIosCommand(context)) + ..addSubcommand(BuildWebsiteCommand(context))) ..addCommand( BuildRunnerCommand()..addSubcommand(BuildRunnerBuild(context)));