oto/lib/oto/build/build_dart.dart
2023-11-19 17:21:35 +09:00

43 lines
1.5 KiB
Dart

import 'dart:async';
import 'package:dart_framework/platform/process.dart';
import 'package:dart_framework/utils/path.dart';
import 'package:oto_cli/oto/application.dart';
import 'package:oto_cli/oto/command.dart';
import 'package:oto_cli/oto/data/command_data.dart';
class BuildDart extends Command {
Function? get error => null;
Future<StringBuffer> appendShell(
StringBuffer shell, DataCommand command) async {
var c = Completer<StringBuffer>();
c.complete(shell);
return c.future;
}
@override
Future execute(DataCommand command) async {
Completer<bool> c = Completer<bool>();
var data = DataBuildDart.fromJson(command.param);
var workspace = Path.getNormal(Application.instance.jenkinsData!.workspace);
var targetPath =
Path.getNormal(Command.replaceTag(data.targetPath ?? workspace));
var shell = StringBuffer();
shell.write('cd $targetPath');
shell.write(' && flutter clean');
shell.write(' && flutter pub upgrade --major-versions');
shell.write(' && flutter packages upgrade');
shell.write(' && flutter pub get');
if (data.executeBuildRunner == null ? true : data.executeBuildRunner!) {
shell.write(
' && flutter pub run build_runner build --delete-conflicting-outputs');
}
var process = await ProcessExecutor.start(await appendShell(shell, command),
workspace: workspace, printStderr: false);
return await complete(await process.process.exitCode, command,
errorMessage: process.stderr.toString());
}
}