Skip to content

Commit

Permalink
Add sz build website command
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsreichardt committed Mar 1, 2024
1 parent df8fbba commit 68da649
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
70 changes: 70 additions & 0 deletions tools/sz_repo_cli/lib/src/commands/src/build_website_command.dart
Original file line number Diff line number Diff line change
@@ -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<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 _buildWebsite();
stdout.writeln('Build finished 🎉 ');
}

Future<void> _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');
}
}
}
4 changes: 3 additions & 1 deletion tools/sz_repo_cli/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -71,7 +72,8 @@ Future<void> main(List<String> 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)));

Expand Down

0 comments on commit 68da649

Please sign in to comment.