code refactoring
This commit is contained in:
parent
a4ebfad98b
commit
b326a7d3a4
16 changed files with 109 additions and 118 deletions
|
|
@ -48,6 +48,12 @@ class Application {
|
|||
'********************************* Build Data *************************************',
|
||||
color: Color.magenta);
|
||||
print(composer.buildYaml);
|
||||
|
||||
_property = build.common;
|
||||
for (var command in build.commands) {
|
||||
await printBuildStep('Phase Start: ${command.name}', Color.green);
|
||||
await Command.byType(command.command).execute(command);
|
||||
}
|
||||
} on Exception catch (e, stacktace) {
|
||||
await CLI.printString(e.toString(), color: Color.redStrong);
|
||||
await CLI.printString(stacktace.toString(), color: Color.yellowStrong);
|
||||
|
|
@ -55,16 +61,6 @@ class Application {
|
|||
return;
|
||||
}
|
||||
|
||||
_property = build.common;
|
||||
for (var command in build.commands) {
|
||||
String commandStr =
|
||||
command.command.toString().replaceAll('CommandType.', '');
|
||||
await printBuildStep('Phase Start: $commandStr', Color.green);
|
||||
if (!await Command(command.command).execute(command)) {
|
||||
exit(10);
|
||||
}
|
||||
}
|
||||
|
||||
await printBuildStep('Build Successfully Complete', Color.cyan);
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -111,7 +107,7 @@ class DataComposerFile extends DataComposer {
|
|||
@override
|
||||
Future compose(String? yaml, Future Function(String, Color?) printer) async {
|
||||
jenkinsData = DataJenkins.fromJson(FileData.jenkinsMap!);
|
||||
buildYaml = yaml ?? '';
|
||||
buildYaml = yaml ?? '---';
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class CreateAppData implements Command {
|
||||
class CreateAppData extends Command {
|
||||
Function? get error => null;
|
||||
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Future execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
var jenkins = Application.instance.jenkinsData!;
|
||||
var data = DataAppDataCreator.fromJson(command.param);
|
||||
|
|
@ -19,8 +19,6 @@ class CreateAppData implements Command {
|
|||
.create(data.scm, workspace, data.relativeAssetPath, data.name);
|
||||
Command.setReturnValue(data.returnVersion, appData.version);
|
||||
Command.setReturnValue(data.returnHash, appData.gitHash.substring(0, 7));
|
||||
|
||||
c.complete(true);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class BuildDart implements Command {
|
||||
class BuildDart extends Command {
|
||||
Function? get error => null;
|
||||
|
||||
Future<StringBuffer> appendShell(
|
||||
|
|
@ -16,7 +16,7 @@ class BuildDart implements Command {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Future execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
var data = DataBuildDart.fromJson(command.param);
|
||||
var workspace = Path.getNormal(Application.instance.jenkinsData!.workspace);
|
||||
|
|
@ -35,13 +35,9 @@ class BuildDart implements Command {
|
|||
}
|
||||
|
||||
var process = await ProcessExecutor.start(await appendShell(shell, command),
|
||||
workspace: workspace);
|
||||
var exitCode = await process.process.exitCode;
|
||||
print('#### Exit Code: ${exitCode.toString()}');
|
||||
var passCode = [0, 64];
|
||||
//exitCode 65: package not defiend in pubspec.yaml
|
||||
var success = passCode.contains(process.exitCode);
|
||||
c.complete(success);
|
||||
return c.future;
|
||||
workspace: workspace, enableStderr: false);
|
||||
|
||||
return await complete(await process.process.exitCode, command,
|
||||
errorMessage: process.stderr.toString(), passCode: [0, 64]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class BuildDotNet implements Command {
|
||||
class BuildDotNet extends Command {
|
||||
Function? get error => null;
|
||||
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Future execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
var data = DataBuildDotNet.fromJson(command.param);
|
||||
var workspace = Application.instance.jenkinsData!.workspace;
|
||||
|
|
@ -16,9 +16,10 @@ class BuildDotNet implements Command {
|
|||
shell.writeln('cd $workspace');
|
||||
shell.writeln(
|
||||
'MSBuild ${data.projectFile} /t:build /p:Configuration=Release;Platform=x86');
|
||||
var process = await ProcessExecutor.start(shell, workspace: workspace);
|
||||
var exitCode = await process.process.exitCode;
|
||||
c.complete(exitCode == 0);
|
||||
return c.future;
|
||||
var process = await ProcessExecutor.start(shell,
|
||||
workspace: workspace, enableStderr: false);
|
||||
|
||||
return complete(await process.process.exitCode, command,
|
||||
errorMessage: process.stderr.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import 'package:oto_cli/oto/data/data.dart';
|
|||
import 'package:dart_framework/platform/process.dart';
|
||||
import 'package:dart_framework/utils/path.dart';
|
||||
|
||||
class BuildiOS implements Command {
|
||||
class BuildiOS extends Command {
|
||||
Function? get error => null;
|
||||
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Future execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
var data = DataBuildiOS.fromJson(command.param);
|
||||
var workspace = Path.getNormal(Application.instance.jenkinsData!.workspace);
|
||||
|
|
@ -34,32 +34,30 @@ class BuildiOS implements Command {
|
|||
shell.write(
|
||||
' && xcodebuild -workspace $workspacePath -scheme ${data.scheme} -destination $destination');
|
||||
|
||||
// var process = await ProcessExecutor.run(shell, workspace: workspace);
|
||||
var processData = await ProcessExecutor.start(shell, workspace: workspace);
|
||||
var processData = await ProcessExecutor.start(shell,
|
||||
workspace: workspace, enableStderr: false);
|
||||
var exitCode = await processData.process.exitCode;
|
||||
print('#### Exit Code: $exitCode');
|
||||
var success = exitCode == 0;
|
||||
if (success) {
|
||||
c.complete(success);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
} else {
|
||||
if (exitCode == 31) {
|
||||
data.cleanPod = true;
|
||||
command.param = data.toJson();
|
||||
return await execute(command);
|
||||
} else {
|
||||
c.complete(success);
|
||||
return c.future;
|
||||
return complete(exitCode, command,
|
||||
errorMessage: processData.stderr.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ArchiveiOS implements Command {
|
||||
class ArchiveiOS extends Command {
|
||||
Function? get error => null;
|
||||
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Future execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
var data = DataArchiveiOS.fromJson(command.param);
|
||||
var workspace = Path.getNormal(Application.instance.jenkinsData!.workspace);
|
||||
|
|
@ -70,19 +68,19 @@ class ArchiveiOS implements Command {
|
|||
shell.write(
|
||||
'xcodebuild -workspace $workspacePath -scheme ${data.scheme} -archivePath $archivePath archive');
|
||||
|
||||
var processData = await ProcessExecutor.start(shell, workspace: workspace);
|
||||
var exitCode = await processData.process.exitCode;
|
||||
print('#### Exit Code: $exitCode');
|
||||
c.complete(exitCode == 0);
|
||||
return c.future;
|
||||
var processData = await ProcessExecutor.start(shell,
|
||||
workspace: workspace, enableStderr: false);
|
||||
|
||||
return complete(await processData.process.exitCode, command,
|
||||
errorMessage: processData.stderr.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class ExportiOS implements Command {
|
||||
class ExportiOS extends Command {
|
||||
Function? get error => null;
|
||||
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Future execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
var data = DataExportiOS.fromJson(command.param);
|
||||
var workspace = Path.getNormal(Application.instance.jenkinsData!.workspace);
|
||||
|
|
@ -95,10 +93,10 @@ class ExportiOS implements Command {
|
|||
shell.write(
|
||||
'xcodebuild -exportArchive -archivePath $archivePath -exportPath $exportPath -exportOptionsPlist $exportOptionPlistPath');
|
||||
|
||||
var processData = await ProcessExecutor.start(shell, workspace: workspace);
|
||||
var exitCode = await processData.process.exitCode;
|
||||
print('#### Exit Code: $exitCode');
|
||||
c.complete(exitCode == 0);
|
||||
return c.future;
|
||||
var processData = await ProcessExecutor.start(shell,
|
||||
workspace: workspace, enableStderr: false);
|
||||
|
||||
return complete(await processData.process.exitCode, command,
|
||||
errorMessage: processData.stderr.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// ignore_for_file: constant_identifier_names
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/oto/application.dart';
|
||||
import 'package:oto_cli/oto/build/app_data_creator.dart';
|
||||
import 'package:oto_cli/oto/build/build_dart.dart';
|
||||
|
|
@ -64,10 +65,12 @@ abstract class Command {
|
|||
CommandType.Shell: Shell()
|
||||
};
|
||||
|
||||
factory Command(CommandType type) {
|
||||
factory Command.byType(CommandType type) {
|
||||
return _commandMap[type]!;
|
||||
}
|
||||
|
||||
Command();
|
||||
|
||||
static final Map<String, dynamic> _cache = <String, dynamic>{};
|
||||
static String replaceTag(String raw) {
|
||||
var regEx = RegExp(r'(<!)([a-zA-Z0-9.]+)(>)');
|
||||
|
|
@ -116,24 +119,36 @@ abstract class Command {
|
|||
return data;
|
||||
}
|
||||
|
||||
// ignore: missing_return
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
var c = Completer<bool>();
|
||||
c.complete(true);
|
||||
return c.future;
|
||||
Future execute(DataCommand command) async {
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
Future complete(int exitCode, DataCommand command,
|
||||
{String? errorMessage, List<int>? passCode}) {
|
||||
passCode ??= [0];
|
||||
if (passCode.contains(exitCode)) {
|
||||
return simpleFuture;
|
||||
} else {
|
||||
var data = ExcpetionData();
|
||||
data.phase = command.name;
|
||||
data.message = errorMessage;
|
||||
throw Exception(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Templete
|
||||
class SimpleCommand implements Command {
|
||||
class SimpleCommand extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
print(command.param);
|
||||
//Start here
|
||||
c.complete(true);
|
||||
return c.future;
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
|
||||
class ExcpetionData {
|
||||
String? phase;
|
||||
String? message;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ class DataCommand {
|
|||
late CommandType command;
|
||||
late dynamic param;
|
||||
|
||||
String get name {
|
||||
return command.toString().replaceAll('CommandType.', '');
|
||||
}
|
||||
|
||||
factory DataCommand.fromJson(Map<String, dynamic> json) =>
|
||||
_$DataCommandFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DataCommandToJson(this);
|
||||
|
|
|
|||
|
|
@ -6,10 +6,9 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class Copy implements Command {
|
||||
class Copy extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
var data = DataCopy.fromJson(command.param);
|
||||
|
|
@ -75,7 +74,6 @@ class Copy implements Command {
|
|||
print('Copy General Exception: $e');
|
||||
result = false;
|
||||
}
|
||||
c.complete(result);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class Delete implements Command {
|
||||
class Delete extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
var data = DataDelete.fromJson(command.param);
|
||||
|
|
@ -34,7 +33,6 @@ class Delete implements Command {
|
|||
print('Copy General Exception: $e');
|
||||
result = false;
|
||||
}
|
||||
c.complete(result);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class Rename implements Command {
|
||||
class Rename extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
var data = DataRename.fromJson(command.param);
|
||||
|
|
@ -35,7 +34,6 @@ class Rename implements Command {
|
|||
print('Copy General Exception: $e');
|
||||
result = false;
|
||||
}
|
||||
c.complete(result);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class Shell implements Command {
|
||||
class Shell extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData!;
|
||||
var data = DataShell.fromJson(command.param);
|
||||
|
|
@ -22,9 +21,10 @@ class Shell implements Command {
|
|||
} else {
|
||||
shell.writeln('source $path');
|
||||
}
|
||||
var process = await ProcessExecutor.run(shell, workspace: workspace);
|
||||
c.complete(isSuccess(process.exitCode));
|
||||
return c.future;
|
||||
var processData = await ProcessExecutor.start(shell, workspace: workspace);
|
||||
|
||||
return complete(await processData.process.exitCode, command,
|
||||
errorMessage: processData.stderr.toString());
|
||||
}
|
||||
|
||||
bool isSuccess(int exitCode) {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ import 'package:oto_cli/oto/data/data.dart';
|
|||
import 'package:oto_cli/oto/uploader/ftp.dart';
|
||||
import 'package:dart_framework/utils/path.dart';
|
||||
|
||||
class Uploader implements Command {
|
||||
class Uploader extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var data = DataUploader.fromJson(command.param);
|
||||
|
||||
//Check asterisk
|
||||
|
|
@ -69,7 +68,6 @@ class Uploader implements Command {
|
|||
await ftp.disconnect();
|
||||
print(
|
||||
'========================= [Upload completed!] ======================');
|
||||
c.complete(true);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@ import 'package:oto_cli/oto/command.dart';
|
|||
import 'package:oto_cli/oto/data/data.dart';
|
||||
import 'package:dart_framework/platform/process.dart';
|
||||
|
||||
class ExecuteApp implements Command {
|
||||
class ExecuteApp extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
var data = DataExecuteApp.fromJson(command.param);
|
||||
|
|
@ -21,7 +20,6 @@ class ExecuteApp implements Command {
|
|||
var buffer = StringBuffer(content);
|
||||
var processData =
|
||||
await ProcessExecutor.run(buffer, workspace: data.desktopServicePath);
|
||||
c.complete(true);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,11 @@ import 'package:dart_framework/utils/path.dart';
|
|||
// ignore: depend_on_referenced_packages
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
class PublishiOS implements Command {
|
||||
class PublishiOS extends Command {
|
||||
Function? get error => null;
|
||||
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var data = DataPublishiOS.fromJson(command.param);
|
||||
var workspace = Path.getNormal(Application.instance.jenkinsData!.workspace);
|
||||
var menifestURL = Command.replaceTag(data.menifestURL);
|
||||
|
|
@ -49,7 +48,6 @@ class PublishiOS implements Command {
|
|||
|
||||
print('Created "manifest.plist" --> "$destinationPath/manifest.plist"');
|
||||
|
||||
c.complete(true);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/oto/application.dart';
|
||||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
import 'package:color/color.dart';
|
||||
import 'package:dart_framework/utils/slack/slack_sender.dart';
|
||||
|
||||
class Slack implements Command {
|
||||
class Slack extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
var data = DataSlack.fromJson(command.param);
|
||||
|
|
@ -17,15 +17,13 @@ class Slack implements Command {
|
|||
|
||||
//To-do: compose parameters
|
||||
|
||||
c.complete(result);
|
||||
return c.future;
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
|
||||
class SlackBuild implements Command {
|
||||
class SlackBuild extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
var data = DataSlackBuild.fromJson(command.param);
|
||||
|
|
@ -39,7 +37,6 @@ class SlackBuild implements Command {
|
|||
await sender.sendBuild(data.appName, data.type, color, version, download,
|
||||
channel: channel);
|
||||
|
||||
c.complete(result);
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@ import 'package:oto_cli/oto/application.dart';
|
|||
import 'package:oto_cli/oto/command.dart';
|
||||
import 'package:oto_cli/oto/data/data.dart';
|
||||
|
||||
class Zip implements Command {
|
||||
class Zip extends Command {
|
||||
@override
|
||||
Future<bool> execute(DataCommand command) async {
|
||||
Completer<bool> c = Completer<bool>();
|
||||
Future execute(DataCommand command) async {
|
||||
var common = Application.instance.property;
|
||||
var jenkins = Application.instance.jenkinsData;
|
||||
var data = DataZip.fromJson(command.param);
|
||||
|
|
@ -66,7 +65,6 @@ class Zip implements Command {
|
|||
}
|
||||
}
|
||||
encoder.close();
|
||||
c.complete(true);
|
||||
print('Compress success: $zipFilePath');
|
||||
} else {
|
||||
throw Exception('"${tempDir.path}" is Directory');
|
||||
|
|
@ -75,6 +73,6 @@ class Zip implements Command {
|
|||
print('Zip General Exception: $e');
|
||||
}
|
||||
|
||||
return c.future;
|
||||
return complete(0, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue