diff --git a/assets/pipeline-test.yaml b/assets/pipeline-test.yaml index 7b6c425..ae44499 100644 --- a/assets/pipeline-test.yaml +++ b/assets/pipeline-test.yaml @@ -1,15 +1,17 @@ --- property: workspace: . - revision: c65a8bb + revision: 24c9423 + valueTest: 15.3 pipeline: id: main workflow: # - async: git - - exe: git + - exe: set-value + - exe: print - - exe: buildDart + # - exe: buildDart # - exe: json-reader @@ -29,6 +31,7 @@ pipeline: # - async: git-count + # - wait-until-seconds: 10 # - wait-until-string: != complete # - async: git-rev @@ -53,6 +56,25 @@ pipeline: # - exe: zip commands: +### 파이프라인 실행도중 값 세팅 +- command: SetValue + id: set-value + param: + values-string: + stringTest: Test! + values-int: + intTest: 12 + values-float: + floatTest: + values-bool: + boolTest: true + +### Print +- command: Print + id: print + param: + message: this is test message / / / / + ### 콜백이 필요없는 단순 Git 명령 호출 - command: Git id: git @@ -70,6 +92,19 @@ commands: - fetch origin - reset --hard origin/master +### Git 로컬로 체크아웃 +- command: GitCheckout + id: git-checkout + param: + branch: main + execute-pull: true + +### Git Push +- command: GitPush + id: git-push + param: + branch: main + ### 깃 리비전 정보 저장 - command: GitRev id: git-rev @@ -86,14 +121,10 @@ commands: - command: JsonReader id: json-reader param: - path: ./assets/data/app_data.json + json: pair: - - from: gitHash - to: - - from: version - to: - - from: gitCount - to: + - from: deleted + setValue: <@property.deleted> ### Version 쓰기 - command: CreateAppData @@ -117,3 +148,28 @@ commands: zipFile: "/release/oto_win_v.zip" zipList: - "/release/oto_cli.exe" + +- command: AwsCli + id: aws-cli + param: + sub-command: s3api get-object + args: + - --profile vo-stage + - --bucket vo-stage-deploy + - --key stage/webserver/revision/api.jar + - api-0.0.1.jar + +- command: Docker + id: docker + param: + sub-command: stop + args: + - web + +- command: Gradle + id: gradle + param: + args: + - -p backend + - clean + - build \ No newline at end of file diff --git a/assets/pipeline-test2.yaml b/assets/pipeline-test2.yaml new file mode 100644 index 0000000..e69de29 diff --git a/assets/script/batch/build.bat b/assets/script/batch/build.bat index 1f569ce..55adb36 100644 --- a/assets/script/batch/build.bat +++ b/assets/script/batch/build.bat @@ -9,10 +9,15 @@ for /F "skip=2 tokens=1,2*" %%G in ('%SystemRoot%\System32\reg.exe query "HKCU\E if /I "%%H" == "REG_EXPAND_SZ" (set "PathExpand=1" & set "PathUser=%%I") else if /I "%%H" == "REG_SZ" set "PathUser=%%I" ) -PATH=%PathSystem%;%PathUser% +PATH=%PathSystem%;%PathUser%;%SystemRoot%\System32 echo %PATH% -SET BuildData > build_data.conf +IF [%1]==[] ( + SET BuildData > build_data.conf +) ELSE ( + SET %1 > build_data.conf +) + SET BUILDER=%~dp0 cd "%BUILDER%..\..\.." diff --git a/assets/script/batch/check_package_update.bat b/assets/script/batch/check_package_update.bat index c4ca799..6132d9b 100644 --- a/assets/script/batch/check_package_update.bat +++ b/assets/script/batch/check_package_update.bat @@ -11,7 +11,7 @@ for /F "skip=2 tokens=1,2*" %%G in ('%SystemRoot%\System32\reg.exe query "HKCU\E if /I "%%H" == "REG_EXPAND_SZ" (set "PathExpand=1" & set "PathUser=%%I") else if /I "%%H" == "REG_SZ" set "PathUser=%%I" ) -PATH=%PathSystem%;%PathUser% +PATH=%PathSystem%;%PathUser%;%SystemRoot%\System32 echo %PATH% : cd ../dart_framework && git pull origin master : cd "../%JOB_NAME%" diff --git a/assets/script/shell/build.sh b/assets/script/shell/build.sh index 9b8fc3b..4cb3cc8 100644 --- a/assets/script/shell/build.sh +++ b/assets/script/shell/build.sh @@ -1,3 +1,5 @@ +source ~/.zshrc +echo $PATH BASEDIR=$(dirname $0) echo "===> Script location: ${BASEDIR}" cd ${BASEDIR}/../../.. diff --git a/assets/script/shell/check_package_update.sh b/assets/script/shell/check_package_update.sh index 77c861c..2092d65 100644 --- a/assets/script/shell/check_package_update.sh +++ b/assets/script/shell/check_package_update.sh @@ -1,3 +1,4 @@ +source ~/.zshrc echo $PATH echo "Current workspace: ${PWD}" diff --git a/assets/yaml/example/command/copy.yaml b/assets/yaml/example/command/copy.yaml new file mode 100644 index 0000000..0b13829 --- /dev/null +++ b/assets/yaml/example/command/copy.yaml @@ -0,0 +1,40 @@ +--- +property: + workspace: C:/jenkins/workspace/VirtualOffice_PlayServer/Server/MetaVServer/Server/Src + deployPath: C:/Server + enviroment: devClient + + +pipeline: + id: main + workflow: + - exe: msbuild + - exe: print + - exe: copy + + +commands: +### MSBuild +- command: BuildMSBuild + id: msbuild + param: + projectFile: Server.sln + config: Release + type: Rebuild + +### Print +- command: Print + id: print + param: + message: build complete + +### Copy +- command: Copy + id: copy + param: + ignorePattern: + - servercfg.ini + - StartServer.bat + - StopServer.bat + copyMap: + "/Release64/*": "/" \ No newline at end of file diff --git a/assets/yaml/example/foreach.yaml b/assets/yaml/example/foreach.yaml new file mode 100644 index 0000000..db0771c --- /dev/null +++ b/assets/yaml/example/foreach.yaml @@ -0,0 +1,59 @@ +--- +property: + workspace: . + arr1: + - This is message 1 + - This is message 2 + - This is message 3 + - This is message 4 + map: + test1: This is message 1 + test2: This is message 2 + test3: This is message 3 + test4: This is message 4 + arr2: + - innter arr message 1 + - innter arr message 2 + - innter arr message 3 + - innter arr message 4 + +pipeline: + id: main + workflow: + # list foreach + - foreach: + iterator: + setValue: <@property.element1> + on-do: + - exe: print1 + # innter foreach + - foreach: + iterator: + setValue: <@property.element2> + on-do: + - exe: print2 + + # map foreach + - foreach: + iterator: + # setKey is optional + setKey: <@property.keyName> + setValue: <@property.element> + on-do: + - exe: print3 + +commands: +- command: Print + id: print1 + param: + message: + +- command: Print + id: print2 + param: + message: + +- command: Print + id: print3 + param: + message: - \ No newline at end of file diff --git a/assets/yaml/example/pipeline/foreach.yaml b/assets/yaml/example/pipeline/foreach.yaml new file mode 100644 index 0000000..db0771c --- /dev/null +++ b/assets/yaml/example/pipeline/foreach.yaml @@ -0,0 +1,59 @@ +--- +property: + workspace: . + arr1: + - This is message 1 + - This is message 2 + - This is message 3 + - This is message 4 + map: + test1: This is message 1 + test2: This is message 2 + test3: This is message 3 + test4: This is message 4 + arr2: + - innter arr message 1 + - innter arr message 2 + - innter arr message 3 + - innter arr message 4 + +pipeline: + id: main + workflow: + # list foreach + - foreach: + iterator: + setValue: <@property.element1> + on-do: + - exe: print1 + # innter foreach + - foreach: + iterator: + setValue: <@property.element2> + on-do: + - exe: print2 + + # map foreach + - foreach: + iterator: + # setKey is optional + setKey: <@property.keyName> + setValue: <@property.element> + on-do: + - exe: print3 + +commands: +- command: Print + id: print1 + param: + message: + +- command: Print + id: print2 + param: + message: + +- command: Print + id: print3 + param: + message: - \ No newline at end of file diff --git a/build_osx.yaml b/build_osx.yaml index cf3bf77..a10c0bb 100644 --- a/build_osx.yaml +++ b/build_osx.yaml @@ -9,8 +9,8 @@ commands: scm: Git name: OTO relativeAssetPath: assets/data - returnVersion: "" - returnHash: "" + return-version: "" + return-hash: "" ### 프로젝트 패키지 업데이트 - command: BuildDart @@ -26,6 +26,6 @@ commands: ### 최종 zip 파일 형태로 저장 - command: Zip param: - zipFile: "/release/oto_osx_v.zip" + zipFile: "/release/oto_osx_v.zip" zipList: - - "/release/oto_service_cli" + - "/release/oto_service_cli" diff --git a/build_win.yaml b/build_win.yaml index 463fb7c..2273c71 100644 --- a/build_win.yaml +++ b/build_win.yaml @@ -9,8 +9,8 @@ commands: scm: Git name: OTO relativeAssetPath: assets/data - returnVersion: "" - returnHash: "" + return-version: "" + return-hash: "" ### 실행가능한 파일로 빌드 - command: BuildDartCompile @@ -21,6 +21,6 @@ commands: ### 최종 zip 파일 형태로 저장 - command: Zip param: - zipFile: "/release/oto_win_v.zip" + zipFile: "/release/oto_win_v.zip" zipList: - - "/release/oto_cli.exe" + - "/release/oto_cli.exe" diff --git a/lib/cli/cli.dart b/lib/cli/cli.dart index 2f273e6..e3b698a 100644 --- a/lib/cli/cli.dart +++ b/lib/cli/cli.dart @@ -310,7 +310,8 @@ class _PrinterUnix extends Printer { } var temp = await getTempFile(message.toString(), 'sh'); - await Process.run('zsh', [temp.path]).then((ProcessResult result) { + var shellExe = Platform.isMacOS ? 'zsh' : 'bash'; + await Process.run(shellExe, [temp.path]).then((ProcessResult result) { print(result.stdout); }); await temp.delete(); diff --git a/lib/oto/application.dart b/lib/oto/application.dart index 89b15e8..e07ca05 100644 --- a/lib/oto/application.dart +++ b/lib/oto/application.dart @@ -12,6 +12,7 @@ import 'package:oto_cli/oto/data/command_data.dart'; import 'package:oto_cli/oto/data/jenkins_data.dart'; import 'package:oto_cli/oto/core/data_composer.dart'; import 'package:yaml/yaml.dart'; +import 'package:path/path.dart' as pathlib; enum BuildType { jenkins, test, file } @@ -21,6 +22,16 @@ class Application { Application._privateConstructor(); static final Application _instance = Application._privateConstructor(); static Application get instance => _instance; + static String get current { + if(Application.instance.buildType == BuildType.jenkins) + { + return Platform.environment['WORKSPACE']!; + } + else + { + return pathlib.current; + } + } final Map _mapComposer = { BuildType.test: () => DataComposerTest(), @@ -28,13 +39,19 @@ class Application { BuildType.file: () => DataComposerFile() }; - DataJenkins? jenkinsData; + DataCommon? commonData; Map property = {}; Map commandStates = {}; Map dataCommandMap = {}; late Pipeline pipeline; + late BuildType _buildType; + get buildType + { + return _buildType; + } Future build(BuildType buildType, {String? yamlContent}) async { + _buildType = buildType; setUTF8(); // var envArgs = envArguments(arguments); @@ -42,7 +59,7 @@ class Application { try { var composer = _mapComposer[buildType]!(); await composer.compose(yamlContent, printBuildStep); - jenkinsData = composer.jenkinsData; + commonData = composer.commonData; DataBuild? build = DataBuild.fromJson(getMapFromYamlA(composer.buildYaml)!); await CLI.println( @@ -50,34 +67,38 @@ class Application { color: Color.magenta); print(composer.buildYaml); - property = build.property; + property = build.property ?? {}; + if(!property.containsKey('workspace')) + { + property['workspace'] = current; + } + property = Command.replaceAllTagsMap(property, replace: true); //set command in dic, 중복 커맨드 id 필터 - for (var command in build.commands) { - if (dataCommandMap.containsKey(command.id)) { - var ex = ExceptionData(); - ex.phase = 'Validate command list'; - ex.message = 'Duplicate command id exists: "${command.id}"'; - throw Exception(ex); - } else { - dataCommandMap[command.id] = command; - } - } - - //Parse pipeline & validate - var validateResult = - Pipeline.pipelineInitialize(build.pipeline!.workflow); - if (!validateResult.enable) { + for (var command in build.commands) { + if (dataCommandMap.containsKey(command.id)) { var ex = ExceptionData(); - ex.phase = 'Validate Pipeline'; - ex.message = validateResult.message; + ex.phase = 'Validate command list'; + ex.message = 'Duplicate command id exists: "${command.id}"'; throw Exception(ex); + } else { + dataCommandMap[command.id] = command; } - pipeline = validateResult.pipeline!; + } - //start build - await pipeline.execute(); + //Parse pipeline & validate + var validateResult = + Pipeline.pipelineInitialize(build.pipeline!.workflow); + if (!validateResult.enable) { + var ex = ExceptionData(); + ex.phase = 'Validate Pipeline'; + ex.message = validateResult.message; + throw Exception(ex); + } + pipeline = validateResult.pipeline!; + //start build + await pipeline.execute(); } on Exception catch (e, stacktace) { await CLI.printString(e.toString(), color: Color.redStrong); await CLI.printString(stacktace.toString(), color: Color.yellowStrong); diff --git a/lib/oto/commands/aws/awscli.dart b/lib/oto/commands/aws/awscli.dart new file mode 100644 index 0000000..316c71c --- /dev/null +++ b/lib/oto/commands/aws/awscli.dart @@ -0,0 +1,25 @@ + +import 'package:dart_framework/platform/process.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class AwsCli extends Command { + + @override + Future execute(DataCommand command) async { + DataAwsCli data = DataAwsCli.fromJson(getParam(command)); + String subCommand = data.subCommand; + List args = data.args; + + + StringBuffer shell = StringBuffer(getCDPath(workspace)); + shell.write(' && aws $subCommand'); + for (String arg in args) { + shell.write(' $arg'); + } + var process = await ProcessExecutor.start(shell); + + return await completeProcess(process, command); + } + +} \ No newline at end of file diff --git a/lib/oto/commands/build/app_data_creator.dart b/lib/oto/commands/build/app_data_creator.dart index 4eb5c0d..644dc8a 100644 --- a/lib/oto/commands/build/app_data_creator.dart +++ b/lib/oto/commands/build/app_data_creator.dart @@ -9,13 +9,14 @@ class CreateAppData extends Command { @override Future execute(DataCommand command) async { - var data = DataAppDataCreator.fromJson(command.param); - var workspace = getWorkspace(data.workspace); + var data = DataAppDataCreator.fromJson(getParam(command)); var appData = await AppDataManager.to .create(data.scm, workspace, data.relativeAssetPath, data.name); - await setReturn(data.return_version, appData.version); - await setReturn(data.return_hash, appData.gitHash.substring(0, 7)); + await setProperty(data.setVersion, appData.version); + await setProperty(data.setHash, appData.gitHash.substring(0, 7)); + if(data.setCount != null) await setProperty(data.setCount!, appData.gitCount.toString()); + if(data.setDate != null) await setProperty(data.setDate!, appData.buildDate); return complete(0, command); } } diff --git a/lib/oto/commands/build/build_dart.dart b/lib/oto/commands/build/build_dart.dart index 9371f8c..273f8ae 100644 --- a/lib/oto/commands/build/build_dart.dart +++ b/lib/oto/commands/build/build_dart.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:dart_framework/platform/process.dart'; +import 'package:dart_framework/utils/system_util.dart'; import 'package:oto_cli/oto/commands/command.dart'; import 'package:oto_cli/oto/data/command_data.dart'; @@ -8,15 +9,12 @@ class BuildDart extends Command { Future appendShell( StringBuffer shell, DataCommand command) async { - var c = Completer(); - c.complete(shell); - return c.future; + return dataFutrue(shell); } @override Future execute(DataCommand command) async { - var data = DataBuildDart.fromJson(command.param); - var workspace = getWorkspace(data.workspace); + var data = DataBuildDart.fromJson(getParam(command)); var shell = StringBuffer(getCDPath(workspace)); shell.write(' && flutter clean'); @@ -31,7 +29,6 @@ class BuildDart extends Command { var process = await ProcessExecutor.start(await appendShell(shell, command), printStderr: false); - return await complete(await process.process.exitCode, command, - errorMessage: process.stderr.toString()); + return await completeProcess(process, command); } } diff --git a/lib/oto/commands/build/build_dart_compile.dart b/lib/oto/commands/build/build_dart_compile.dart index 262e8fd..f37d7cc 100644 --- a/lib/oto/commands/build/build_dart_compile.dart +++ b/lib/oto/commands/build/build_dart_compile.dart @@ -10,9 +10,8 @@ class BuildDartCompile extends BuildDart { Future appendShell( StringBuffer shell, DataCommand command) async { var c = Completer(); - var data = DataBuildDartCompile.fromJson(command.param); + var data = DataBuildDartCompile.fromJson(getParam(command)); var extension = getExeExtension(); - var workspace = getWorkspace(data.workspace); var binPath = path.join(workspace, 'bin'); //find build target @@ -24,7 +23,7 @@ class BuildDartCompile extends BuildDart { break; } findedDartFile = path.join(workspace, 'bin', findedDartFile); - var targetDartFile = replaceTag(data.targetDartFile ?? findedDartFile); + var targetDartFile = data.targetDartFile ?? findedDartFile; //clear build path var buildFolderName = 'release'; diff --git a/lib/oto/commands/build/build_dot_net.dart b/lib/oto/commands/build/build_dot_net.dart index c79aa87..03240d2 100644 --- a/lib/oto/commands/build/build_dot_net.dart +++ b/lib/oto/commands/build/build_dot_net.dart @@ -8,8 +8,7 @@ class BuildDotNet extends Command { @override Future execute(DataCommand command) async { - var data = DataBuildDotNet.fromJson(command.param); - var workspace = getWorkspace(data.workspace); + var data = DataBuildDotNet.fromJson(getParam(command)); var shell = StringBuffer(getCDPath(workspace)); shell.write( @@ -18,7 +17,6 @@ class BuildDotNet extends Command { var process = await ProcessExecutor.start(shell, workspace: workspace, printStderr: false); - return complete(await process.process.exitCode, command, - errorMessage: process.stderr.toString()); + return await completeProcess(process, command); } } diff --git a/lib/oto/commands/build/build_ios.dart b/lib/oto/commands/build/build_ios.dart index e745f63..b11f140 100644 --- a/lib/oto/commands/build/build_ios.dart +++ b/lib/oto/commands/build/build_ios.dart @@ -1,74 +1,213 @@ import 'dart:async'; +import 'dart:io'; +import 'package:oto_cli/oto/commands/build/build_flutter.dart'; import 'package:oto_cli/oto/commands/command.dart'; import 'package:oto_cli/oto/data/command_data.dart'; import 'package:dart_framework/platform/process.dart'; +import 'package:path/path.dart' as path; class BuildiOS extends Command { Function? get error => null; @override Future execute(DataCommand command) async { - var data = DataBuildiOS.fromJson(command.param); - var workspace = getWorkspace(data.workspace); - var xcworkspaceFilePath = getPathNormal(data.xcworkspaceFilePath); - var destination = data.destination ?? 'generic/platform=iOS build'; + var data = DataBuildiOS.fromJson(getParam(command)); + var xcodeProjectPath = data.xcworkspaceFilePath ?? data.xcodeProjectFilePath; + if(xcodeProjectPath == null) throw Exception('"xcodeProjectFilePath" or "xcworkspaceFilePath" must set at least one.'); + var xcworkspaceFilePath = Command.getPathNormal(xcodeProjectPath); + + var os = 'iOS'; + if(data.os != null) + { + if(data.os == BuildPlatform.Macos) + { + os = 'macOS'; + } + } + var destination = "'generic/platform=$os'"; var cleanPod = data.cleanPod ?? false; + var xcodeProjectParentPath = Directory(xcworkspaceFilePath).parent.path; + var podFile = File('$xcodeProjectParentPath/PodFile'); + + var project = ''; + if(data.xcworkspaceFilePath != null) { + project = '-workspace $xcodeProjectPath'; + } else { + project = '-project $xcodeProjectPath'; + } + + var configuration = ''; + if(data.configuration != null) + { + configuration = ' -configuration ${data.configuration}'; + } + var derivedDataPath = ''; + if(data.derivedDataPath != null) + { + derivedDataPath = ' -derivedDataPath ${data.configuration}'; + } + var settings = ''; + if(data.settings != null) + { + var map = data.settings!; + for(var item in map.entries) + { + settings += ' ${item.key}="${item.value}"'; + } + } var shell = StringBuffer(); - shell.write('security unlock-keychain -pr0bins'); - shell.write(' && cd $workspace/ios'); + shell.write('security unlock-keychain -p${data.macPassword}'); + shell.write(' && cd $xcodeProjectParentPath'); shell.write(' && export LANG=en_US.UTF-8'); - shell.write(' && rm -rf Pods'); - shell.write(' && rm -rf Podfile.lock'); - if (cleanPod) { - shell.write(' && pod cache clean --all'); - shell.write(' && pod repo update'); - shell.write(' && pod install --repo-update'); - } else { - shell.write(' && pod install'); + if(podFile.existsSync()) + { + shell.write(' && rm -rf Pods'); + shell.write(' && rm -rf Podfile.lock'); + if (cleanPod) { + shell.write(' && pod cache clean --all'); + shell.write(' && pod repo update'); + shell.write(' && pod install --repo-update'); + } else { + shell.write(' && pod install'); + } } shell.write( - ' && xcodebuild -workspace $xcworkspaceFilePath -scheme ${data.scheme} -destination $destination'); + ' && xcodebuild $project -scheme ${data.scheme} -destination $destination$configuration$derivedDataPath$settings clean build'); - var processData = await ProcessExecutor.start(shell, - workspace: workspace, printStderr: false); - var exitCode = await processData.process.exitCode; + var process = await ProcessExecutor.start(shell, printStderr: false); + var exitCode = await process.process.exitCode; var success = exitCode == 0; if (success) { - return complete(0, command); + return await completeProcess(process, command); } else { if (exitCode == 31) { data.cleanPod = true; command.param = data.toJson(); return await execute(command); } else { - return complete(exitCode, command, - errorMessage: processData.stderr.toString()); + return await completeProcess(process, command); } } } } +class CodeSign extends Command { + Function? get error => null; + + @override + Future execute(DataCommand command) async { + var data = DataCodeSign.fromJson(getParam(command)); + var entitlement = ''; + if(data.entitlementPath == null) + { + entitlement = ' --entitlements "${data.entitlementPath}"'; + } + var shell = StringBuffer(getCDPath(workspace)); + shell.write( + ' && codesign --deep --force --verify --verbose --timestamp --options runtime$entitlement --sign "${data.certificationName}" "${data.appPath}"'); + + var process = await ProcessExecutor.start(shell, + workspace: workspace, printStderr: false); + + return await completeProcess(process, command); + } +} + +class CodeSignVerify extends Command { + Function? get error => null; + + @override + Future execute(DataCommand command) async { + var data = DataCodeSignVerify.fromJson(getParam(command)); + var shell = StringBuffer(getCDPath(workspace)); + shell.write(' && codesign -verify -verbose "${data.appPath}"'); + shell.write(' && spctl --assess --verbose "${data.appPath}"'); + + var process = await ProcessExecutor.start(shell, + workspace: workspace, printStderr: false); + + return await completeProcess(process, command); + } +} + +class ProductBuild extends Command { + Function? get error => null; + + @override + Future execute(DataCommand command) async { + var data = DataProductBuild.fromJson(getParam(command)); + var shell = StringBuffer(getCDPath(workspace)); + if(data.scripts != null) { + shell.write(' && chmod a+x "${data.scripts}/postinstall"'); + shell.write(' && pkgbuild --identifier "${data.identifier}" --scripts "${data.scripts}" --component "${data.appPath}" --sign "${data.installCertificationName}" --install-location "/Applications" "${data.unsignedResultPath}"'); + } else { + shell.write(' && productbuild --component "${data.appPath}" /Applications --sign "${data.installCertificationName}" "${data.unsignedResultPath}"'); + } + shell.write(' && productsign --sign "${data.installCertificationName}" "${data.unsignedResultPath}" "${data.signedResultPath}"'); + + var process = await ProcessExecutor.start(shell, + workspace: workspace, printStderr: false); + + return await completeProcess(process, command); + } +} + +class Notarize extends Command { + Function? get error => null; + + @override + Future execute(DataCommand command) async { + var data = DataNotarize.fromJson(getParam(command)); + var isApp = path.extension(data.resultPath).toLowerCase().contains('app'); + var shell = StringBuffer(getCDPath(workspace)); + shell.write(' && security unlock-keychain -p${data.macPassword}'); + shell.write(' && xcrun notarytool store-credentials "${data.bundleName}" --apple-id "${data.appleAccount}" --team-id "${data.teamId}" --password "${data.applePassword}"'); + var notaryTarget = data.resultPath; + var appFileName = ''; + var zipFileName = ''; + if(isApp) { + var dir = Directory(data.resultPath).parent; + appFileName = path.basename(data.resultPath); + zipFileName = '${path.basenameWithoutExtension(data.resultPath)}.zip'; + notaryTarget = '${dir.path}/$zipFileName'; + shell.write(' && cd ${dir.path}'); + shell.write(' && ditto -c -k --sequesterRsrc --keepParent "$appFileName" "$zipFileName"'); + } + shell.write(' && xcrun notarytool submit "$notaryTarget" --keychain-profile "${data.bundleName}" --wait'); + shell.write(' && xcrun stapler staple "${data.resultPath}"'); + if(isApp) { + shell.write(' && rm $zipFileName'); + shell.write(' && ditto -c -k --sequesterRsrc --keepParent "$appFileName" "$zipFileName"'); + } + + var process = await ProcessExecutor.start(shell, + workspace: workspace, printStderr: false); + + return await completeProcess(process, command); + } +} + + class ArchiveiOS extends Command { Function? get error => null; @override Future execute(DataCommand command) async { - var data = DataArchiveiOS.fromJson(command.param); - var workspace = getWorkspace(data.workspace); - var workspacePath = getPathNormal(data.xcworkspaceFilePath); - var archivePath = getPathNormal(data.archivePath); + var data = DataArchiveiOS.fromJson(getParam(command)); + var workspacePath = Command.getPathNormal(data.xcworkspaceFilePath); + var archivePath = Command.getPathNormal(data.archivePath); + var destination = data.destination ?? "'generic/platform=iOS'"; var shell = StringBuffer(); shell.write( - 'xcodebuild -workspace $workspacePath -scheme ${data.scheme} -archivePath $archivePath archive'); + 'xcodebuild -workspace $workspacePath -scheme ${data.scheme} -destination $destination -archivePath $archivePath archive'); - var processData = await ProcessExecutor.start(shell, + var process = await ProcessExecutor.start(shell, workspace: workspace, printStderr: false); - return complete(await processData.process.exitCode, command, - errorMessage: processData.stderr.toString()); + return await completeProcess(process, command); } } @@ -77,20 +216,19 @@ class ExportiOS extends Command { @override Future execute(DataCommand command) async { - var data = DataExportiOS.fromJson(command.param); - var workspace = getWorkspace(data.workspace); - var archivePath = getPathNormal(data.archivePath); - var exportPath = getPathNormal(data.exportPath); - var exportOptionPlistPath = getPathNormal(data.exportOptionPlistPath); + var data = DataExportiOS.fromJson(getParam(command)); + var archivePath = Command.getPathNormal(data.archivePath); + var exportPath = Command.getPathNormal(data.exportPath); + var exportOptionPlistPath = + Command.getPathNormal(data.exportOptionPlistPath); var shell = StringBuffer(); shell.write( 'xcodebuild -exportArchive -archivePath $archivePath -exportPath $exportPath -exportOptionsPlist $exportOptionPlistPath'); - var processData = await ProcessExecutor.start(shell, + var process = await ProcessExecutor.start(shell, workspace: workspace, printStderr: false); - return complete(await processData.process.exitCode, command, - errorMessage: processData.stderr.toString()); + return await completeProcess(process, command); } } diff --git a/lib/oto/commands/build/build_msbuild.dart b/lib/oto/commands/build/build_msbuild.dart new file mode 100644 index 0000000..7a8bc32 --- /dev/null +++ b/lib/oto/commands/build/build_msbuild.dart @@ -0,0 +1,30 @@ +// ignore_for_file: constant_identifier_names + +import 'dart:async'; +import 'dart:io'; +import 'package:dart_framework/platform/process.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +enum MSBuildType { Clean, Build, Rebuild } + +enum MSBuildConfig { Debug, Release } + +class BuildMSBuild extends Command { + Function? get error => null; + + @override + Future execute(DataCommand command) async { + var data = DataBuildMSBuild.fromJson(getParam(command)); + + var param = + '${data.projectFile} /p:Configuration=${data.config.name} /p:Platform=x64 /t:${data.type.name}'; + + var shell = StringBuffer(getCDPath(workspace)); + shell.write(' && msbuild $param'); + + var process = await ProcessExecutor.start(shell, + decoder: SystemEncoding().decoder, printStderr: false); + return await completeProcess(process, command); + } +} diff --git a/lib/oto/commands/command.dart b/lib/oto/commands/command.dart index f0f5057..cbee057 100644 --- a/lib/oto/commands/command.dart +++ b/lib/oto/commands/command.dart @@ -1,9 +1,10 @@ -// ignore_for_file: constant_identifier_names, depend_on_referenced_packages +// ignore_for_file: constant_identifier_names, depend_on_referenced_packages, avoid_init_to_null +import 'dart:async'; import 'dart:io'; +import 'package:dart_framework/platform/process.dart'; import 'package:dart_framework/utils/path.dart'; import 'package:dart_framework/utils/system_util.dart'; -import 'package:oto_cli/cli/cli.dart'; import 'package:oto_cli/oto/application.dart'; import 'package:oto_cli/oto/commands/build/app_data_creator.dart'; import 'package:oto_cli/oto/commands/build/build_dart.dart'; @@ -11,92 +12,220 @@ import 'package:oto_cli/oto/commands/build/build_dart_compile.dart'; import 'package:oto_cli/oto/commands/build/build_dot_net.dart'; import 'package:oto_cli/oto/commands/build/build_flutter.dart'; import 'package:oto_cli/oto/commands/build/build_ios.dart'; +import 'package:oto_cli/oto/commands/build/build_msbuild.dart'; +import 'package:oto_cli/oto/commands/file/directory.dart'; +import 'package:oto_cli/oto/commands/file/file.dart'; +import 'package:oto_cli/oto/commands/file/file_diff_check.dart'; import 'package:oto_cli/oto/commands/git/git.dart'; -import 'package:oto_cli/oto/commands/util/jira.dart'; +import 'package:oto_cli/oto/commands/aws/awscli.dart'; +import 'package:oto_cli/oto/commands/docker/docker.dart'; +import 'package:oto_cli/oto/commands/git/git_hub.dart'; +import 'package:oto_cli/oto/commands/gradle/gradle.dart'; +import 'package:oto_cli/oto/commands/jira/jira.dart'; +import 'package:oto_cli/oto/commands/process/process.dart'; +import 'package:oto_cli/oto/commands/proto/protobuf.dart'; import 'package:oto_cli/oto/commands/util/json.dart'; +import 'package:oto_cli/oto/commands/util/print.dart'; +import 'package:oto_cli/oto/commands/util/set_value.dart'; +import 'package:oto_cli/oto/commands/util/string_util.dart'; +import 'package:oto_cli/oto/commands/web/web.dart'; import 'package:oto_cli/oto/data/command_data.dart'; import 'package:oto_cli/oto/data/jenkins_data.dart'; import 'package:oto_cli/oto/commands/file/delete.dart'; import 'package:oto_cli/oto/commands/file/rename.dart'; import 'package:oto_cli/oto/commands/shell/shell.dart'; import 'package:oto_cli/oto/commands/file/copy.dart'; -import 'package:oto_cli/oto/commands/util/execute_app.dart'; import 'package:oto_cli/oto/commands/util/publish_ios.dart'; import 'package:oto_cli/oto/commands/util/slack.dart'; import 'package:oto_cli/oto/commands/util/zip.dart'; import 'package:oto_cli/oto/commands/uploader/uploader.dart'; -import 'package:path/path.dart' as pathlib; +import 'package:oto_cli/oto/pipeline/pipeline_exe_handle.dart'; enum CommandType { SimpleCommand, + Print, + SetValue, CreateAppData, BuildDart, BuildFlutter, BuildDartCompile, BuildDotNet, BuildiOS, + BuildMSBuild, + CodeSign, + CodeSignVerify, + ProductBuild, + Notarize, ArchiveiOS, ExportiOS, PublishiOS, - ExecuteApp, Upload, Copy, Rename, Delete, + FileDiffCheck, + FileRead, + FileWrite, + DirectoryCreate, Slack, SlackBuild, + StringSub, + StringReplace, Jira, Zip, Shell, + ShellFile, Git, + GitPush, + GitCheckout, GitRev, GitCount, - JsonReader + GitHub, + GitHubPullRequestCreate, + GitHubPullRequestList, + GitHubPullRequestClose, + Protobuf, + JsonReader, + JsonReaderFile, + AwsCli, + Docker, + Gradle, + WebRequest, + WebFile, + ProcessPortUse, + ProcessRun, + ProcessKill } abstract class Command { - static final Map _commandMap = { - CommandType.SimpleCommand: SimpleCommand(), - CommandType.CreateAppData: CreateAppData(), - CommandType.BuildDart: BuildDart(), - CommandType.BuildFlutter: BuildFlutter(), - CommandType.BuildDartCompile: BuildDartCompile(), - CommandType.BuildDotNet: BuildDotNet(), - CommandType.BuildiOS: BuildiOS(), - CommandType.ArchiveiOS: ArchiveiOS(), - CommandType.ExportiOS: ExportiOS(), - CommandType.PublishiOS: PublishiOS(), - CommandType.ExecuteApp: ExecuteApp(), - CommandType.Upload: Uploader(), - CommandType.Copy: Copy(), - CommandType.Rename: Rename(), - CommandType.Delete: Delete(), - CommandType.Slack: Slack(), - CommandType.SlackBuild: SlackBuild(), - CommandType.Jira: Jira(), - CommandType.Zip: Zip(), - CommandType.Shell: Shell(), - CommandType.Git: Git(), - CommandType.GitRev: GitRev(), - CommandType.GitCount: GitCount(), - CommandType.JsonReader: JsonReader() + static final Map _commandMap = { + CommandType.SimpleCommand: () => SimpleCommand(), + CommandType.Print: () => PrintCommand(), + CommandType.SetValue: () => SetValueCommand(), + CommandType.CreateAppData: () => CreateAppData(), + CommandType.BuildDart: () => BuildDart(), + CommandType.BuildFlutter: () => BuildFlutter(), + CommandType.BuildDartCompile: () => BuildDartCompile(), + CommandType.BuildDotNet: () => BuildDotNet(), + CommandType.BuildiOS: () => BuildiOS(), + CommandType.BuildMSBuild: () => BuildMSBuild(), + CommandType.CodeSign: () => CodeSign(), + CommandType.CodeSignVerify: () => CodeSignVerify(), + CommandType.ProductBuild: () => ProductBuild(), + CommandType.Notarize: () => Notarize(), + CommandType.ArchiveiOS: () => ArchiveiOS(), + CommandType.ExportiOS: () => ExportiOS(), + CommandType.PublishiOS: () => PublishiOS(), + CommandType.Upload: () => Uploader(), + CommandType.Copy: () => Copy(), + CommandType.Rename: () => Rename(), + CommandType.Delete: () => Delete(), + CommandType.FileDiffCheck: () => FileDiffCheck(), + CommandType.FileRead: () => FileRead(), + CommandType.FileWrite: () => FileWrite(), + CommandType.DirectoryCreate: () => DirectoryCreate(), + CommandType.Slack: () => Slack(), + CommandType.SlackBuild: () => SlackBuild(), + CommandType.StringSub: () => StringSub(), + CommandType.StringReplace: () => StringReplace(), + CommandType.Jira: () => Jira(), + CommandType.Zip: () => Zip(), + CommandType.Shell: () => Shell(), + CommandType.ShellFile: () => ShellFile(), + CommandType.Git: () => Git(), + CommandType.GitPush: () => GitPush(), + CommandType.GitCheckout: () => GitCheckout(), + CommandType.GitRev: () => GitRev(), + CommandType.GitCount: () => GitCount(), + CommandType.GitHub: () => GitHub(), + CommandType.GitHubPullRequestCreate: () => GitHubPullRequestCreate(), + CommandType.GitHubPullRequestList: () => GitHubPullRequestList(), + CommandType.GitHubPullRequestClose: () => GitHubPullRequestClose(), + CommandType.Protobuf: () => Protobuf(), + CommandType.JsonReader: () => JsonReader(), + CommandType.JsonReaderFile: () => JsonReaderFile(), + CommandType.AwsCli: () => AwsCli(), + CommandType.Docker: () => Docker(), + CommandType.Gradle: () => Gradle(), + CommandType.WebRequest: () => WebRequest(), + CommandType.WebFile: () => WebFile(), + CommandType.ProcessPortUse: () => ProcessPortUse(), + CommandType.ProcessRun: () => ProcessRun(), + CommandType.ProcessKill: () => ProcessKill() }; factory Command.byType(CommandType type) { - return _commandMap[type]!; + return _commandMap[type]!(); } Command(); + late String id; static RegExp regEx = RegExp(r'()'); + static RegExp regSetEx = RegExp(r'(<@)([_a-zA-Z0-9.-]+)(>)'); - static Future setReturnValue(String tag, dynamic value) async { - var match = regEx.firstMatch(tag); + static Map replaceAllTagsMap(Map map, + {bool replace = false}) { + var newMap = {}; + var deleteKeys = []; + for (var pair in map.entries) { + var key = pair.key; + var keyReplacedTag = Command.replaceTagValue(key); + if (keyReplacedTag != key) { + deleteKeys.add(key); + } + if (map[key] is String) { + newMap[keyReplacedTag] = Command.replaceTagValue(map[key]); + } else if (map[key] is List) { + newMap[keyReplacedTag] = replaceAllTagsList(map[key], replace: replace); + } else if (map[key] is Map) { + newMap[keyReplacedTag] = replaceAllTagsMap(map[key], replace: replace); + } else { + newMap[keyReplacedTag] = map[key]; + } + if (replace) { + map[keyReplacedTag] = newMap[keyReplacedTag]; + } + } + if (replace) { + for (var key in deleteKeys) { + map.remove(key); + } + return map; + } + return newMap; + } + + static List replaceAllTagsList(List list, {bool replace = false}) { + var newList = []; + for (var i = 0; i < list.length; ++i) { + if (list[i] is String) { + newList.add(Command.replaceTagValue(list[i])); + } else if (list[i] is List) { + newList.add(replaceAllTagsList(list[i])); + } else if (list[i] is Map) { + newList.add(replaceAllTagsMap(list[i])); + } else { + newList.add(list[i]); + } + if (replace) { + list[i] = newList[i]; + } + } + if (replace) { + return newList; + } + return newList; + } + + static Future setPropertyValue(String tag, dynamic value) async { + var match = regSetEx.firstMatch(tag); tag = match!.group(2)!; if (tag.startsWith('property')) { var key = tag.replaceFirst('property.', ''); Application.instance.property[key] = value; - await CLI.println('[Return] $key : $value', color: Color.yellowStrong); + // await CLI.println('[Return] $key : $value', color: Color.yellowStrong); + print('[Return] $key : $value'); } return simpleFuture; } @@ -136,8 +265,32 @@ abstract class Command { return data; } - static String replaceTagValue(String raw) { + static String getAbs(String path) { + path = getPathNormal(path); + if (path == '.' || path.startsWith('./') || path.startsWith('.\\')) { + path = path.replaceFirst('.', getPathNormal(Application.current)); + } + if (path == '..' || path.startsWith('../') || path.startsWith('..\\')) { + path = + path.replaceFirst('..', '${getPathNormal(Application.current)}/..'); + } + return File(path).absolute.path; + } + + static String getPathNormal(String path) { + return replaceTagValue(Path.getNormal(path)); + } + + static dynamic replaceTagValue(String raw) { var list = regEx.allMatches(raw); + if (list.length == 1) { + var item = list.first; + var sub = list.first.input.substring(item.start, item.end); + if (sub == raw) { + return replaceSingleTagValue(raw); + } + } + for (var match in list) { var param = match.group(2); var target = ''; @@ -156,27 +309,34 @@ abstract class Command { return value; } + late ExeHandleData? exeHandle = null; + + late String _workspace; + String get workspace { + return _workspace; + } + Map get property { return Application.instance.property; } - DataJenkins? get jenkinsData { - return Application.instance.jenkinsData; + DataCommon? get commonData { + return Application.instance.commonData; } String getWorkspace(String? dataWorkspace) { - return getAbs(dataWorkspace ?? jenkinsData!.workspace); - } - - String getAbs(String path) { - path = getPathNormal(path); - if (path == '.' || path.startsWith('./') || path.startsWith('.\\')) { - path = path.replaceFirst('.', getPathNormal(pathlib.current)); + if (dataWorkspace == null) { + //모델에 정의된 workspace가 없을경우 property에 설정된 workspace 우선 + if (property.containsKey('workspace')) { + return getAbs(property['workspace']); + } + //property에도 설정이 되어 있지 않으면 현재 실행 프로젝트 기준으로 workspace 설정 + else { + return getAbs(commonData!.workspace); + } + } else { + return getAbs(dataWorkspace); } - if (path == '..' || path.startsWith('../') || path.startsWith('..\\')) { - path = path.replaceFirst('..', '${getPathNormal(pathlib.current)}/..'); - } - return path; } String getCDPath(String path) { @@ -187,10 +347,6 @@ abstract class Command { return '${drive}cd $path'; } - String getPathNormal(String path) { - return replaceTag(Path.getNormal(path)); - } - String replaceTag(String raw) { return Command.replaceTagValue(raw); } @@ -199,25 +355,98 @@ abstract class Command { return Command.replaceSingleTagValue(raw); } - Future setReturn(String tag, dynamic value) async { - await Command.setReturnValue(tag, value); + Future setProperty(String tag, dynamic value) async { + await Command.setPropertyValue(tag, value); + } + + Map getParam(DataCommand command) { + var map = Command.replaceAllTagsMap(command.param); + map['workspace'] = _workspace = getWorkspace(map['workspace']); + return map; } Future execute(DataCommand command) async { return simpleFuture; } - Future complete(int exitCode, DataCommand command, - {String? errorMessage, List? passCode}) { - passCode ??= [0]; - if (passCode.contains(exitCode)) { - return simpleFuture; - } else { - print('Exit Code: $exitCode'); - var data = ExceptionData(); - data.phase = command.name; - data.message = errorMessage; - throw Exception(data); + Future executeHandle(DataCommand command, ExeHandleData handleData) async { + exeHandle = handleData; + try + { + return await execute(command); + } + on Exception catch (e) + { + return await exeHandle!.pipelineFail!.execute(); + } + } + + Future> getMergedPassExitCode( + Map? param, List? passExitCodes) async { + var c = Completer>(); + var passExitCodesMerged = [0]; + if (param != null) { + var data = DataParam.fromJson(param); + if (data.passExitCodes != null) { + passExitCodesMerged.addAll(data.passExitCodes!); + } + } + if (passExitCodes != null) { + passExitCodesMerged.addAll(passExitCodes); + } + c.complete(passExitCodesMerged); + return c.future; + } + + Future completeProcess(ProcessData processData, DataCommand command, + {List? passExitCodes}) async { + var exitCode = await processData.process.exitCode; + var passExitCodesMerge = + await getMergedPassExitCode(command.param, passExitCodes); + String? resultMessage = null; + if (exitCode != 0 && passExitCodesMerge.contains(exitCode)) { + resultMessage = processData.stderr.toString(); + } + return await complete(exitCode, command, + errorMessage: processData.stderr.toString(), + passExitCodes: passExitCodes, + resultMessage: resultMessage); + } + + Future complete(int exitCode, DataCommand command, + {String? errorMessage, + List? passExitCodes, + String? resultMessage}) async { + var passExitCodesMerge = + await getMergedPassExitCode(command.param, passExitCodes); + if (command.param != null) { + var data = DataParam.fromJson(command.param); + if (data.setExitCode != null) { + await setProperty(data.setExitCode!, exitCode); + } + if (data.setResult != null) { + await setProperty(data.setResult!, resultMessage); + } + } + if(exeHandle == null) + { + if (passExitCodesMerge.contains(exitCode)) { + return simpleFuture; + } else { + print('Exit Code: $exitCode'); + var data = ExceptionData(); + data.phase = command.name; + data.message = errorMessage; + throw Exception(data); + } + } + else + { + if (passExitCodesMerge.contains(exitCode)) { + return await exeHandle!.pipelineSuccess!.execute(); + } else { + return await exeHandle!.pipelineFail!.execute(); + } } } } diff --git a/lib/oto/commands/docker/docker.dart b/lib/oto/commands/docker/docker.dart new file mode 100644 index 0000000..d26a6fd --- /dev/null +++ b/lib/oto/commands/docker/docker.dart @@ -0,0 +1,25 @@ + +import 'package:dart_framework/platform/process.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class Docker extends Command { + + @override + Future execute(DataCommand command) async { + DataDocker data = DataDocker.fromJson(getParam(command)); + String dockerCommand = data.command; + List args = data.args; + + StringBuffer shell = StringBuffer(getCDPath(workspace)); + shell.write(' && docker $dockerCommand'); + + for (String arg in args) { + shell.write(' $arg'); + } + var process = await ProcessExecutor.start(shell); + + return await completeProcess(process, command); + } + +} \ No newline at end of file diff --git a/lib/oto/commands/file/copy.dart b/lib/oto/commands/file/copy.dart index 5b45bd0..c9b1df4 100644 --- a/lib/oto/commands/file/copy.dart +++ b/lib/oto/commands/file/copy.dart @@ -8,20 +8,23 @@ import 'package:oto_cli/oto/data/command_data.dart'; class Copy extends Command { @override Future execute(DataCommand command) async { - var data = DataCopy.fromJson(command.param); + var data = DataCopy.fromJson(getParam(command)); var isMove = data.isMove == null ? false : data.isMove!; + var isOverwrite = data.isOverwrite == null ? true : data.isOverwrite!; var entries = data.copyMap.entries; try { var ignoredList = []; for (var entry in entries) { - var start = getPathNormal(entry.key); - var dest = getPathNormal(entry.value); + var start = Command.getPathNormal(entry.key); + var dest = Command.getPathNormal(entry.value); var destDir = Directory(dest); var name = Path.getName(start); if (name == "*") { //Delete & recreate dest folder - if (destDir.existsSync()) destDir.deleteSync(recursive: true); - destDir.createSync(recursive: true); + if (!destDir.existsSync()) + { + destDir.createSync(recursive: true); + } var startParentStr = Path.getParent(start); if (startParentStr != null) { var startParent = Directory(startParentStr); @@ -37,7 +40,7 @@ class Copy extends Command { await Path.copy(file.path, dest, true, ignorePattern: data.ignorePattern, ignoredList: ignoredList, - isMove: isMove); + isMove: isMove, isOverwrite: isOverwrite); } } } else { @@ -68,6 +71,7 @@ class Copy extends Command { } } on Exception catch (e) { print('Copy General Exception: $e'); + rethrow; } return complete(0, command); } diff --git a/lib/oto/commands/file/delete.dart b/lib/oto/commands/file/delete.dart index 49205fe..f66c9b5 100644 --- a/lib/oto/commands/file/delete.dart +++ b/lib/oto/commands/file/delete.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io'; import 'package:dart_framework/utils/path.dart'; import 'package:oto_cli/oto/commands/command.dart'; @@ -7,15 +8,41 @@ import 'package:oto_cli/oto/data/command_data.dart'; class Delete extends Command { @override Future execute(DataCommand command) async { - var data = DataDelete.fromJson(command.param); + var data = DataDelete.fromJson(getParam(command)); try { - var ignoredList = []; + var ignoredList = data.ignorePattern ??= []; for (var item in data.list) { - var path = getPathNormal(item); + var path = Command.getPathNormal(item); var name = Path.getName(path); if (name == "*") { //Delete & recreate dest folder - } else {} + var dir = Directory(Path.getParent(path)!); + if(dir.existsSync()) + { + await dir.delete(recursive: true); + } + } else { + var deletable = true; + for(var ignoreItem in ignoredList) + { + if(name.contains(ignoreItem)) { + deletable = false; + } + } + + if(deletable) { + var file = File(path); + if(file.existsSync()) { + await file.delete(recursive: true); + print('Deleted File: ${file.path}'); + } + var dir = Directory(path); + if(dir.existsSync()) { + await dir.delete(recursive: true); + print('Deleted Directory: ${dir.path}'); + } + } + } } if (ignoredList.isNotEmpty) { @@ -26,7 +53,7 @@ class Delete extends Command { print('======================================================'); } } on Exception catch (e) { - print('Copy General Exception: $e'); + rethrow; } return complete(0, command); } diff --git a/lib/oto/commands/file/directory.dart b/lib/oto/commands/file/directory.dart new file mode 100644 index 0000000..8a69173 --- /dev/null +++ b/lib/oto/commands/file/directory.dart @@ -0,0 +1,19 @@ +// ignore_for_file: depend_on_referenced_packages + +import 'dart:async'; +import 'dart:io'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class DirectoryCreate extends Command { + @override + Future execute(DataCommand command) async { + var data = DataDirectoryCreate.fromJson(getParam(command)); + var dir = Directory(data.path); + if(!dir.existsSync()) { + await dir.create(recursive: true); + print('Directory Created: ${data.path}'); + } + return complete(0, command); + } +} \ No newline at end of file diff --git a/lib/oto/commands/file/file.dart b/lib/oto/commands/file/file.dart new file mode 100644 index 0000000..0a7c307 --- /dev/null +++ b/lib/oto/commands/file/file.dart @@ -0,0 +1,34 @@ +// ignore_for_file: depend_on_referenced_packages + +import 'dart:async'; +import 'dart:io'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class FileRead extends Command { + @override + Future execute(DataCommand command) async { + var data = DataFileRead.fromJson(getParam(command)); + var file = File(data.path); + var content = ''; + if(file.existsSync()) { + content = file.readAsStringSync(); + } else { + throw Exception('File not exist - ${data.path}'); + } + setProperty(data.setContent, content); + return complete(0, command); + } +} + +class FileWrite extends Command { + @override + Future execute(DataCommand command) async { + var data = DataFileWrite.fromJson(getParam(command)); + var file = File(data.path); + if(file.existsSync()) file.deleteSync(); + + await file.writeAsString(data.content); + return complete(0, command); + } +} diff --git a/lib/oto/commands/file/file_diff_check.dart b/lib/oto/commands/file/file_diff_check.dart new file mode 100644 index 0000000..92a3f62 --- /dev/null +++ b/lib/oto/commands/file/file_diff_check.dart @@ -0,0 +1,146 @@ +// ignore_for_file: depend_on_referenced_packages + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; + +import 'package:dart_framework/utils/system_util.dart'; +import 'package:file_hasher/file_hasher.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; +import 'package:convert/convert.dart'; +import 'package:crypto/crypto.dart' as crypto; + +class FileDiffCheck extends Command { + @override + Future execute(DataCommand command) async { + var data = DataFileDiffCheck.fromJson(getParam(command)); + var exitCode = 0; + var diff = false; + + var currentDir = Directory(workspace); + var fileName = getUniqueFileName(data.paths.join(';')); + + var tempDir = Directory.systemTemp; + var cacheFolder = Directory('${tempDir.path}/oto/${getUniqueFileName(currentDir.path)}'); + if(!cacheFolder.existsSync()) + { + cacheFolder.createSync(recursive: true); + } + var cacheFile = File('${cacheFolder.path}/$fileName'); + var paths = data.paths; + print('Cache Path: ${cacheFile.path}, Exist: ${cacheFile.existsSync()}'); + + if(paths.isEmpty) + { + throw Exception('The paths is Empty.'); + } + else + { + if(cacheFile.existsSync()) + { + var cachedMap = jsonDecode(cacheFile.readAsStringSync()) as Map; + var filesHashMap = await getFilesHashMap(paths); + if(cachedMap.length == filesHashMap.length) + { + for(var pair in filesHashMap.entries) + { + if(cachedMap.containsKey(pair.key)) + { + var cachedHash = cachedMap[pair.key]; + if(cachedHash != pair.value) + { + await saveDiffData(cacheFile, paths); + diff = true; + break; + } + } + else + { + await saveDiffData(cacheFile, paths); + diff = true; + break; + } + } + } + else + { + await saveDiffData(cacheFile, paths); + diff = true; + } + } + else + { + await saveDiffData(cacheFile, paths); + diff = true; + } + } + + await setProperty(data.setDiff, diff); + return await complete(exitCode, command); + } + + Future saveDiffData(File cacheFile, List paths) async + { + var cachedMap = await getFilesHashMap(paths); + var jsonString = jsonEncode(cachedMap); + await cacheFile.writeAsString(jsonString); + return simpleFuture; + } + + String getUniqueFileName(String seed) + { + var fileName = generateMd5(seed); + if(fileName.length > 150) + { + fileName = fileName.substring(0, 150); + } + return fileName; + } + + Future> getFilesHashMap(List paths) async + { + var c = Completer>(); + var cachedMap = {}; + for(var path in paths) + { + var file = File(path); + var type = file.statSync().type; + switch(type) + { + case FileSystemEntityType.directory: + var dir = Directory(path); + var files = dir.listSync(); + for(var child in files) + { + if(child is File) + { + await setCachedMapHash(cachedMap, File(child.path)); + } + } + break; + case FileSystemEntityType.file: + await setCachedMapHash(cachedMap, file); + break; + default: + throw Exception('File or Directory are not exists: $path'); + } + } + c.complete(cachedMap); + return c.future; + } + + Future setCachedMapHash(Map cachedMap, File file) async + { + cachedMap[file.path] = await FileHasher.hash(file); + return simpleFuture; + } + + ///Generate MD5 hash + String generateMd5(String data) { + var content = Utf8Encoder().convert(data); + var md5 = crypto.md5; + var digest = md5.convert(content); + return hex.encode(digest.bytes); + } +} \ No newline at end of file diff --git a/lib/oto/commands/file/rename.dart b/lib/oto/commands/file/rename.dart index 6ae4960..3986af1 100644 --- a/lib/oto/commands/file/rename.dart +++ b/lib/oto/commands/file/rename.dart @@ -11,12 +11,12 @@ import 'package:oto_cli/oto/data/command_data.dart'; class Rename extends Command { @override Future execute(DataCommand command) async { - var data = DataRename.fromJson(command.param); + var data = DataRename.fromJson(getParam(command)); var entries = data.renameMap.entries; try { for (var entry in entries) { - var start = getPathNormal(entry.key); - var targetName = replaceTag(entry.value); + var start = Command.getPathNormal(entry.key); + var targetName = entry.value; var type = Path.getType(start); var parentPath = Path.getParent(start)!; var newPath = path.join(parentPath, targetName); diff --git a/lib/oto/commands/git/git.dart b/lib/oto/commands/git/git.dart index e7bae1b..1d8148b 100644 --- a/lib/oto/commands/git/git.dart +++ b/lib/oto/commands/git/git.dart @@ -5,55 +5,108 @@ import 'package:dart_framework/platform/process.dart'; class Git extends Command { @override Future execute(DataCommand command) async { - var data = DataGit.fromJson(command.param); - var workspace = getWorkspace(data.workspace); + var data = DataGit.fromJson(getParam(command)); + print(workspace); var shell = StringBuffer(getCDPath(workspace)); var commands = data.commands; for (var item in commands) { - shell.write(' && git ${getPathNormal(item)}'); + shell.write(' && git ${Command.getPathNormal(item)}'); } var process = await ProcessExecutor.start(shell); - - return complete(await process.process.exitCode, command, - errorMessage: process.stderr.toString()); + return await completeProcess(process, command); } } +//무시가가능한 에러 무시 +class GitPush extends Command { + @override + Future execute(DataCommand command) async { + var data = DataGitPush.fromJson(getParam(command)); + + var shell = StringBuffer(getCDPath(workspace)); + if(data.branch == null) + { + shell.write(' && git push'); + } + else + { + shell.write(' && git push origin ${data.branch!}'); + } + + var process = await ProcessExecutor.start(shell); + return await completeProcess(process, command, passExitCodes: [1 /*Everything up-to-date*/]); + } +} + +//로컬에 체크아웃이 없을시 체크아웃하고, 체크아웃이 있을시 이동, 원할시 pull수행 +class GitCheckout extends Git { + @override + Future execute(DataCommand command) async { + var data = DataGitCheckout.fromJson(getParam(command)); + var branch = data.branch; + + var shell = StringBuffer(getCDPath(workspace)); + shell.write(' && git checkout origin/$branch'); + shell.write(' && git checkout -b $branch'); + + var process = await ProcessExecutor.start(shell); + var exitCode = await process.process.exitCode; + var ignores = [128/*Already exists*/]; + if(ignores.contains(exitCode)) + { + exitCode = 0; + } + + if(exitCode == 0) + { + shell = StringBuffer(getCDPath(workspace)); + shell.write(' && git checkout $branch'); + + if(data.executePull == null ? true : data.executePull!) + { + shell.write(' && git pull origin $branch'); + } + + process = await ProcessExecutor.start(shell); + exitCode = await process.process.exitCode; + } + + return await completeProcess(process, command); + } +} + +//Git commit에 대한 count 값을 리턴 해준다 class GitCount extends Command { @override Future execute(DataCommand command) async { - var data = DataGitCount.fromJson(command.param); - var workspace = getWorkspace(data.workspace); + var data = DataGitCount.fromJson(getParam(command)); var shell = StringBuffer(getCDPath(workspace)); shell.write(' && git rev-list --all HEAD --all --count'); var process = await ProcessExecutor.start(shell, printStderr: false); - var exitCode = await process.process.exitCode; var number = int.parse(process.stdoutArr.last); - await setReturn(data.result_value, number); + await setProperty(data.setValue, number); - return complete(exitCode, command, errorMessage: process.stderr.toString()); + return await completeProcess(process, command); } } +//git의 리비전에 대해 돌려준다 class GitRev extends Command { @override Future execute(DataCommand command) async { - var data = DataGitRev.fromJson(command.param); - var workspace = getWorkspace(data.workspace); + var data = DataGitRev.fromJson(getParam(command)); var shell = StringBuffer(getCDPath(workspace)); var target = data.branch ?? 'HEAD'; - target = replaceTag(target); shell.write(' && git fetch origin'); shell.write(' && git rev-parse $target'); var process = await ProcessExecutor.start(shell, printStderr: false); - var exitCode = await process.process.exitCode; var hash = process.stdoutArr.last; - await setReturn(data.result_value, hash); + await setProperty(data.setValue, hash); - return complete(exitCode, command, errorMessage: process.stderr.toString()); + return await completeProcess(process, command); } } diff --git a/lib/oto/commands/git/git_hub.dart b/lib/oto/commands/git/git_hub.dart new file mode 100644 index 0000000..10d70da --- /dev/null +++ b/lib/oto/commands/git/git_hub.dart @@ -0,0 +1,131 @@ +// ignore_for_file: avoid_init_to_null + +import 'dart:convert'; +import 'dart:io'; + +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; +import 'package:dart_framework/platform/process.dart'; + +class GitHub extends Command { + @override + Future execute(DataCommand command) async { + var data = DataGitHub.fromJson(getParam(command)); + + var shell = StringBuffer(getCDPath(workspace)); + var commands = data.commands; + for (var item in commands) { + shell.write(' && gh ${Command.getPathNormal(item)}'); + } + + var process = await ProcessExecutor.start(shell); + + return await completeProcess(process, command); + } +} + +class GitHubPullRequestCreate extends Command { + @override + Future execute(DataCommand command) async { + var data = DataGitHubPullRequestCreate.fromJson(getParam(command)); + + var shell = StringBuffer(getCDPath(workspace)); + shell.write(' && gh pr create --title "${data.title}" --body "${data.body}" -B ${data.branch}'); + + var process = await ProcessExecutor.start(shell); + var passExitCodes = [0, 1 /*already exists*/]; + var exitCode = await process.process.exitCode; + if(passExitCodes.contains(exitCode)) + { + var resultMessage = ''; + if(exitCode == 1) + { + resultMessage = process.stderr.toString().replaceAll('\n', ''); + var startIndex = resultMessage.indexOf(':') + 1; + resultMessage = resultMessage.substring(startIndex); + } + else + { + resultMessage = process.stdout.toString().replaceAll('\n', ''); + } + + String? url = null; + String? number = null; + if(!resultMessage.contains('GraphQL: No commits')) + { + var num = resultMessage.substring(resultMessage.lastIndexOf('/') + 1); + url = resultMessage; + number = num.toString(); + } + await setProperty(data.setURL, url); + await setProperty(data.setNumber, number); + } + + return await completeProcess(process, command, passExitCodes: passExitCodes); + } +} + +class GitHubPullRequestList extends Command { + @override + Future execute(DataCommand command) async { + var data = DataGitHubPullRequestList.fromJson(getParam(command)); + + if(data.keys.isEmpty) throw Exception('keys not exist'); + var keysString = data.keys.join(','); + + var shell = StringBuffer(getCDPath(workspace)); + shell.write(' && gh pr list --json $keysString'); + + var decorder = Platform.isWindows ? SystemEncoding().decoder : utf8.decoder; + var process = await ProcessExecutor.start(shell, decoder: decorder); + var exitCode = await process.process.exitCode; + + if(exitCode == 0) + { + Map? target = null; + var jsonRaw = process.stdout.toString(); + jsonRaw = jsonRaw.substring(jsonRaw.indexOf('[')); + List list = jsonDecode(jsonRaw) as List; + for(Map item in list) + { + if(item.containsKey(data.targetKey)) + { + if(item[data.targetKey] == data.targetValue) + { + target = item; + break; + } + } + } + + if(target == null) + { + await setProperty(data.setValue, null); + } + else + { + await setProperty(data.setValue, jsonEncode(target)); + } + } + else + { + await setProperty(data.setValue, null); + } + return await completeProcess(process, command); + } +} + + +class GitHubPullRequestClose extends Command { + @override + Future execute(DataCommand command) async { + var data = DataGitHubPullRequestClose.fromJson(getParam(command)); + + var shell = StringBuffer(getCDPath(workspace)); + shell.write(' && gh pr close ${data.number}'); + + var decorder = Platform.isWindows ? SystemEncoding().decoder : utf8.decoder; + var process = await ProcessExecutor.start(shell, decoder: decorder); + return await completeProcess(process, command); + } +} \ No newline at end of file diff --git a/lib/oto/commands/gradle/gradle.dart b/lib/oto/commands/gradle/gradle.dart new file mode 100644 index 0000000..dcf7497 --- /dev/null +++ b/lib/oto/commands/gradle/gradle.dart @@ -0,0 +1,24 @@ + +import 'package:dart_framework/platform/process.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class Gradle extends Command { + + @override + Future execute(DataCommand command) async { + DataGradle data = DataGradle.fromJson(getParam(command)); + List args = data.args; + + StringBuffer shell = StringBuffer(getCDPath(workspace)); + shell.write(' && gradle'); + + for (String arg in args) { + shell.write(' $arg'); + } + var process = await ProcessExecutor.start(shell); + + return await completeProcess(process, command); + } + +} \ No newline at end of file diff --git a/lib/oto/commands/jira/jira.dart b/lib/oto/commands/jira/jira.dart new file mode 100644 index 0000000..66826a9 --- /dev/null +++ b/lib/oto/commands/jira/jira.dart @@ -0,0 +1,123 @@ + +// ignore_for_file: prefer_function_declarations_over_variables, avoid_init_to_null + +import 'dart:convert'; + +import 'package:dart_framework/utils/slack/slack_data.dart'; +import 'package:dart_framework/utils/system_util.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; +import 'package:http/http.dart' as http; +import 'package:oto_cli/oto/data/jira_data.dart'; + +class Jira extends Command { + String? findContent(DataJiraContent? data) { + if(data != null) { + if(data.text != null) { + return data.text; + } else { + if(data.content != null && data.content!.isNotEmpty) { + return findContent(data.content!.first); + } else { + return null; + } + } + } else { + return null; + } + } + + @override + Future execute(DataCommand command) async { + var data = DataJira.fromJson(getParam(command)); + var text = '${data.id}:${data.token}'; + var base64 = base64Encode(utf8.encode(text)); + var header = + { + 'Content-Type': 'application/json', + 'Authorization': 'Basic $base64' + }; + var url = 'https://${data.domain}/rest/api/3/issue/${data.issue}'; + print(url); + var response = await http.get(Uri.parse(url), headers: header); + + if(response.statusCode < 300 && response.statusCode >= 200) + { + print(response.body); + var issue = DataJiraIssue.fromJson(jsonDecode(response.body)); + var targetUser = issue.fields?.assignee?.emailAddress; + if(targetUser != null) + { + var slackID = ''; + for(var user in data.users) { + if(targetUser.contains(user.mail!)) { + slackID = user.slackID!; + break; + } + } + + if(slackID.isNotEmpty) { + var arr = issue.fields?.description?.content; + var summary = issue.fields?.summary; + if((arr != null && arr.isNotEmpty) || summary != null) { + String? content = ""; + if(arr != null && arr.isNotEmpty) { + content = findContent(arr.first); + content ??= summary!; + } else { + content = summary!; + } + var browseUrl = 'https://${data.domain}/browse/${data.issue}'; + DataSlack Function(String) getData = (channel) { + var slackData = DataSlack(channel); + + slackData.attachments = []; + var attachment = SlackAttachment(); + slackData.blocks = []; + var blockSection = SlackBlockSection(); + blockSection.text = SlackBlockText(); + blockSection.text!.text = ':jira: 새 Jira 업무가 할당되었습니다.'; + slackData.blocks!.add(blockSection); + + attachment.blocks = []; + + blockSection = SlackBlockSection(); + blockSection.text = SlackBlockText(); + blockSection.text!.type = SlackTextType.mrkdwn; + blockSection.text!.text = '*<$browseUrl|${data.issue}> ${issue.fields?.summary}*'; + attachment.blocks!.add(blockSection); + + blockSection = SlackBlockSection(); + blockSection.text = SlackBlockText(); + blockSection.text!.text = content; + blockSection.accessory = SlackAccessory(); + blockSection.accessory!.type = SlackActionType.button; + blockSection.accessory!.url = browseUrl; + blockSection.accessory!.text = SlackBlockText(); + blockSection.accessory!.text!.type = SlackTextType.plain_text; + blockSection.accessory!.text!.text = 'Open'; + attachment.blocks!.add(blockSection); + + slackData.attachments!.add(attachment); + return slackData; + }; + await setProperty(data.setSlackData, getData(slackID)); + + if(data.subChannel != null) { + await setProperty(data.setSlackChannel, getData(data.subChannel!)); + } + } + } else { + print('User not found'); + } + } + + } + else + { + throw Exception('Request Jira API Faile: $url'); + } + + return simpleFuture; + } +} \ No newline at end of file diff --git a/lib/oto/commands/process/process.dart b/lib/oto/commands/process/process.dart new file mode 100644 index 0000000..c27189b --- /dev/null +++ b/lib/oto/commands/process/process.dart @@ -0,0 +1,57 @@ +import 'dart:async'; +import 'dart:io'; + +import 'package:dart_framework/platform/process.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class ProcessPortUse extends Command { + @override + Future execute(DataCommand command) async { + var data = DataProcessPortUse.fromJson(getParam(command)); + try { + var process = await findUsePortPid(int.parse(data.port)); + var pid = process?.pid.toString(); + setProperty(data.setPid, pid); + } on Exception catch (e) { + rethrow; + } + return complete(0, command); + } +} + +class ProcessRun extends Command { + @override + Future execute(DataCommand command) async { + var data = DataProcessRun.fromJson(getParam(command)); + + var exe = data.executable; + print('Process Start: $exe'); + var shell = StringBuffer(getCDPath(data.workspace!)); + var dontKillme = + Platform.isWindows ? 'SET BUILD_ID=dontKillMe' : 'BUILD_ID=dontKillMe'; + var param = data.param == null ? '' : ' ${data.param}'; + shell.writeln(' && $dontKillme && $exe$param'); + var file = + File('${Directory.systemTemp.path}/${ProcessExecutor.tempFileName}'); + await file.writeAsString(shell.toString()); + await Process.start(file.path, [], + runInShell: true, + workingDirectory: data.workspace, + mode: ProcessStartMode.detached); + return complete(0, command); + } +} + +class ProcessKill extends Command { + @override + Future execute(DataCommand command) async { + var data = DataProcessKill.fromJson(getParam(command)); + if (Process.killPid(int.parse(data.pid))) { + print('Process killed'); + } else { + print('Process not exist'); + } + return complete(0, command); + } +} diff --git a/lib/oto/commands/proto/protobuf.dart b/lib/oto/commands/proto/protobuf.dart new file mode 100644 index 0000000..c9c444e --- /dev/null +++ b/lib/oto/commands/proto/protobuf.dart @@ -0,0 +1,20 @@ +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; +import 'package:dart_framework/platform/process.dart'; + +class Protobuf extends Command { + @override + Future execute(DataCommand command) async { + var data = DataProtobuf.fromJson(getParam(command)); + + var shell = StringBuffer(getCDPath(workspace)); + var commands = data.commands; + for (var item in commands) { + shell.write(' && protoc ${Command.getPathNormal(item)}'); + } + + var process = await ProcessExecutor.start(shell); + + return await completeProcess(process, command); + } +} \ No newline at end of file diff --git a/lib/oto/commands/shell/shell.dart b/lib/oto/commands/shell/shell.dart index 0089ed5..6d5295b 100644 --- a/lib/oto/commands/shell/shell.dart +++ b/lib/oto/commands/shell/shell.dart @@ -7,21 +7,32 @@ import 'package:oto_cli/oto/data/command_data.dart'; class Shell extends Command { @override Future execute(DataCommand command) async { - var data = DataShell.fromJson(command.param); - print(command.param); - //Start here - var workspace = getWorkspace(data.workspace); - var path = getPathNormal(data.path); + var data = DataShell.fromJson(getParam(command)); + var shell = StringBuffer(getCDPath(workspace)); + var commands = data.commands; + for (var item in commands) { + shell.write(' && $item'); + } + + var process = await ProcessExecutor.start(shell); + return await completeProcess(process, command); + } +} + +class ShellFile extends Command { + @override + Future execute(DataCommand command) async { + var data = DataShellFile.fromJson(getParam(command)); + var path = Command.getPathNormal(data.path); var shell = StringBuffer(); if (Platform.isWindows) { shell.writeln('call $path'); } else { shell.writeln('source $path'); } - var processData = await ProcessExecutor.start(shell, workspace: workspace); + var process = await ProcessExecutor.start(shell, workspace: workspace); - return complete(await processData.process.exitCode, command, - errorMessage: processData.stderr.toString()); + return await completeProcess(process, command); } bool isSuccess(int exitCode) { diff --git a/lib/oto/commands/uploader/uploader.dart b/lib/oto/commands/uploader/uploader.dart index e1edb09..2414c79 100644 --- a/lib/oto/commands/uploader/uploader.dart +++ b/lib/oto/commands/uploader/uploader.dart @@ -12,7 +12,7 @@ import 'package:dart_framework/utils/path.dart'; class Uploader extends Command { @override Future execute(DataCommand command) async { - var data = DataUploader.fromJson(command.param); + var data = DataUploader.fromJson(getParam(command)); //Check asterisk var uploadMap = {}; @@ -30,7 +30,7 @@ class Uploader extends Command { var entries = map.entries; for (var entry in entries) { var local = - path.join(Application.instance.jenkinsData!.workspace, entry.key); + path.join(Application.instance.commonData!.workspace, entry.key); var remote = entry.value; print('[Upload]: $local ====> $remote'); diff --git a/lib/oto/commands/util/json.dart b/lib/oto/commands/util/json.dart index 892c9bb..38c0048 100644 --- a/lib/oto/commands/util/json.dart +++ b/lib/oto/commands/util/json.dart @@ -8,9 +8,36 @@ import 'package:oto_cli/oto/data/command_data.dart'; class JsonReader extends Command { @override Future execute(DataCommand command) async { - var data = DataJsonReader.fromJson(command.param); - var workspace = getWorkspace(data.workspace); - var path = getAbs(data.path); + var data = DataJsonReader.fromJson(getParam(command)); + try { + Map temp = data.json is String ? jsonDecode(data.json) : data.json as Map; + for (var item in data.pair) { + var keys = item.from.split('.'); + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; + if (temp.containsKey(key)) { + if (i == keys.length - 1) { + await setProperty(item.setValue, temp[keys[i]].toString()); + break; + } else { + temp = temp[keys[i]]; + } + } else { + throw Exception('Not exist key: "$key" in $item'); + } + } + } + } on Exception catch (e) { + throw Exception('Json parsing error: $e'); + } + } +} + +class JsonReaderFile extends Command { + @override + Future execute(DataCommand command) async { + var data = DataJsonReaderFile.fromJson(getParam(command)); + var path = Command.getAbs(data.path); var file = File(path); if (file.existsSync()) { var content = await file.readAsString(); @@ -23,7 +50,7 @@ class JsonReader extends Command { var key = keys[i]; if (temp.containsKey(key)) { if (i == keys.length - 1) { - await setReturn(item.to, temp[keys[i]].toString()); + await setProperty(item.setValue, temp[keys[i]].toString()); break; } else { temp = temp[keys[i]]; @@ -37,7 +64,7 @@ class JsonReader extends Command { throw Exception('Json parsing error: $e'); } } else { - await CLI.println('Json "$path" file not exit. Resturn value to be null.', + await CLI.println('Json "$path" file not exit. Return value to be null.', color: Color.red); } } diff --git a/lib/oto/commands/util/print.dart b/lib/oto/commands/util/print.dart new file mode 100644 index 0000000..6c61f33 --- /dev/null +++ b/lib/oto/commands/util/print.dart @@ -0,0 +1,17 @@ + +import 'package:oto_cli/cli/cli.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class PrintCommand extends Command { + Function? get error => null; + + @override + Future execute(DataCommand command) async { + var data = DataPrint.fromJson(getParam(command)); + // await CLI.println(data.message, color: Color.red); + print(data.message); + + return complete(0, command); + } +} diff --git a/lib/oto/commands/util/publish_ios.dart b/lib/oto/commands/util/publish_ios.dart index 4cd5c5d..dcf8d56 100644 --- a/lib/oto/commands/util/publish_ios.dart +++ b/lib/oto/commands/util/publish_ios.dart @@ -11,9 +11,9 @@ class PublishiOS extends Command { @override Future execute(DataCommand command) async { - var data = DataPublishiOS.fromJson(command.param); - var menifestURL = replaceTag(data.menifestURL); - var destinationPath = replaceTag(data.destinationPath); + var data = DataPublishiOS.fromJson(getParam(command)); + var menifestURL = data.menifestURL; + var destinationPath = data.destinationPath; var templatePath = path.normalize( '${path.dirname(Platform.script.toFilePath())}/../assets/template'); @@ -32,12 +32,12 @@ class PublishiOS extends Command { var menifestContent = await File('$templatePath/manifest.plist').readAsString(); menifestContent = menifestContent - .replaceFirst('IPA_URL', replaceTag(data.ipaURL)) - .replaceFirst('BUNDLE_ID', replaceTag(data.bundleID)) - .replaceFirst('VERSION', replaceTag(data.version)) - .replaceFirst('APP_NAME', replaceTag(data.appName)) - .replaceFirst('DISPLAY_IMAGE_URL', replaceTag(data.displayImageURL)) - .replaceFirst('FULL_SIZE_IMAGE_URL', replaceTag(data.fullSizeImageURL)); + .replaceFirst('IPA_URL', data.ipaURL) + .replaceFirst('BUNDLE_ID', data.bundleID) + .replaceFirst('VERSION', data.version) + .replaceFirst('APP_NAME', data.appName) + .replaceFirst('DISPLAY_IMAGE_URL', data.displayImageURL) + .replaceFirst('FULL_SIZE_IMAGE_URL', data.fullSizeImageURL); var menifestFile = File('$destinationPath/manifest.plist'); await menifestFile.writeAsString(menifestContent); diff --git a/lib/oto/commands/util/set_value.dart b/lib/oto/commands/util/set_value.dart new file mode 100644 index 0000000..13481ac --- /dev/null +++ b/lib/oto/commands/util/set_value.dart @@ -0,0 +1,113 @@ +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class SetValueCommand extends Command { + Function? get error => null; + + @override + Future execute(DataCommand command) async { + var data = DataSetValue.fromJson(getParam(command)); + + if(data.values_bool != null) + { + for(var pair in data.values_bool!.entries) + { + bool value = false; + if(pair.value is bool) + { + value = pair.value; + } + else if(pair.value is String) + { + var resultTag = replaceSingleTag(pair.value); + if(resultTag is String) + { + var toLow = resultTag.toLowerCase(); + if(toLow == 'true' || toLow == 'false') + { + value = toLow == 'true'; + } + } + else if(resultTag is bool) + { + value = resultTag; + } + } + await setProperty(getTag(pair.key), value); + } + } + + if(data.values_float != null) + { + for(var pair in data.values_float!.entries) + { + double value = 0; + if(pair.value is double) + { + value = pair.value; + } + else if(pair.value is String) + { + var resultTag = replaceSingleTag(pair.value); + if(resultTag is String) + { + value = double.parse(resultTag); + } + else if(resultTag is double) + { + value = resultTag; + } + else if(resultTag is int) + { + value = resultTag + 0.0; + } + } + await setProperty(getTag(pair.key), value); + } + } + + if(data.values_int != null) + { + for(var pair in data.values_int!.entries) + { + var value = 0; + if(pair.value is int) + { + value = pair.value; + } + else if(pair.value is String) + { + var resultTag = replaceSingleTag(pair.value); + if(resultTag is String) + { + value = int.parse(resultTag); + } + else if(resultTag is int) + { + value = resultTag; + } + else if(resultTag is double) + { + value = resultTag.round(); + } + } + await setProperty(getTag(pair.key), value); + } + } + + if(data.values_string != null) + { + for(var pair in data.values_string!.entries) + { + await setProperty(getTag(pair.key), pair.value); + } + } + + return complete(0, command); + } + + String getTag(String key) + { + return '<@property.$key>'; + } +} diff --git a/lib/oto/commands/util/slack.dart b/lib/oto/commands/util/slack.dart index 13c6d7c..c0e5e73 100644 --- a/lib/oto/commands/util/slack.dart +++ b/lib/oto/commands/util/slack.dart @@ -1,6 +1,7 @@ // ignore_for_file: avoid_init_to_null import 'dart:async'; +import 'dart:convert'; import 'package:dart_framework/utils/slack/slack_data.dart'; import 'package:dart_framework/utils/system_util.dart'; @@ -12,21 +13,24 @@ import 'package:dart_framework/utils/slack/slack_sender.dart'; class Slack extends Command { @override Future execute(DataCommand command) async { - var data = DataSlackSender.fromJson(command.param); + var data = DataSlackSender.fromJson(getParam(command)); var sender = SlackSender(data.token); - DataSlack? message = null; if (data.property != null) { - var value = replaceSingleTag(data.property!); + var value = data.property as DataSlack?; if (value != null) { - message = value as DataSlack; + await sender.sendData(value); + } + else + { + throw Exception('The property is null.'); } - } else { - message = data.message; } - - if (message != null) { - await sender.send(message); - } else { + else if(data.message != null) + { + await sender.send(jsonEncode(data.message)); + } + else + { throw Exception('property or message field should not be null'); } @@ -37,15 +41,9 @@ class Slack extends Command { class SlackBuild extends Command { @override Future execute(DataCommand command) async { - var data = DataSlackBuild.fromJson(command.param); + var data = DataSlackBuild.fromJson(getParam(command)); - var token = replaceTag(data.token); - var version = replaceTag(data.version); - var download = replaceTag(data.downloadURL); - var color = Color.hex(data.color); - var sender = SlackSender(token); - - await sender.sendBuild(data.appName, data.type, color, version, download); + await SlackSender(data.token).sendBuild(data.appName, data.type, Color.hex(data.color), data.version, data.downloadURL); return complete(0, command); } diff --git a/lib/oto/commands/util/string_util.dart b/lib/oto/commands/util/string_util.dart new file mode 100644 index 0000000..69e2e13 --- /dev/null +++ b/lib/oto/commands/util/string_util.dart @@ -0,0 +1,46 @@ +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; + +class StringSub extends Command { + @override + Future execute(DataCommand command) async { + var data = DataStringSub.fromJson(getParam(command)); + var text = data.text; + var exitCode = 0; + + try + { + int startIndex = data.startIndex == null ? 0 : data.startIndex!; + int lastIndex = data.lastIndex == null ? text.length - startIndex : data.lastIndex!; + text = text.substring(startIndex, lastIndex); + await setProperty(data.setValue, text); + } + on Exception catch(e) + { + rethrow; + } + + return await complete(exitCode, command); + } +} + +class StringReplace extends Command { + @override + Future execute(DataCommand command) async { + var data = DataStringReplace.fromJson(getParam(command)); + var text = data.text; + var exitCode = 0; + + try + { + text = text.replaceAll(data.from, data.to); + await setProperty(data.setValue, text); + } + on Exception catch(e) + { + rethrow; + } + + return await complete(exitCode, command); + } +} \ No newline at end of file diff --git a/lib/oto/commands/util/zip.dart b/lib/oto/commands/util/zip.dart index 1807f33..8d005b4 100644 --- a/lib/oto/commands/util/zip.dart +++ b/lib/oto/commands/util/zip.dart @@ -11,9 +11,9 @@ import 'package:oto_cli/oto/data/command_data.dart'; class Zip extends Command { @override Future execute(DataCommand command) async { - var data = DataZip.fromJson(command.param); + var data = DataZip.fromJson(getParam(command)); try { - var zipFilePath = Path.getNormal(replaceTag(data.zipFile)); + var zipFilePath = Path.getNormal(data.zipFile); print('Start Compress...'); var parent = Directory(Path.getParent(zipFilePath)!); if (!parent.existsSync()) parent.createSync(recursive: true); @@ -25,7 +25,7 @@ class Zip extends Command { encoder.create(zipFilePath); var list = data.zipList; for (var path in list) { - path = Path.getNormal(replaceTag(path)); + path = Path.getNormal(path); var name = Path.getName(path); if (name == '*') { parent = Directory(Path.getParent(path)!); diff --git a/lib/oto/commands/web/web.dart b/lib/oto/commands/web/web.dart new file mode 100644 index 0000000..bf40942 --- /dev/null +++ b/lib/oto/commands/web/web.dart @@ -0,0 +1,84 @@ +import 'dart:async'; + +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; +import 'dart:io'; +import 'package:http/http.dart' as http; +import 'package:http_parser/src/media_type.dart'; + +class WebBase extends Command { + Future request(DataWebBase data, http.BaseRequest request) async + { + var c = Completer(); + if(data.headers != null) + { + for(var head in data.headers!.entries) + { + request.headers[head.key] = head.value; + } + } + var response = await request.send(); + var exitCode = 0; + data.successCodes ??= []; + if ((response.statusCode < 300 && response.statusCode >= 200) || + data.successCodes!.contains(response.statusCode)) { + exitCode = 0; + } else { + exitCode = response.statusCode; + } + c.complete(exitCode); + return c.future; + } +} + +class WebRequest extends WebBase { + @override + Future execute(DataCommand command) async { + var data = DataWebBase.fromJson(getParam(command)); + print('Request URL: ${data.url}'); + data.method ??= 'GET'; + var request = http.Request(data.method!, Uri.parse(data.url)); + if(data.fields != null) + { + for(var field in data.fields!.entries) + { + request.bodyFields[field.key] = field.value; + } + } + return await complete(await super.request(data, request), command); + } +} + +class WebFile extends WebBase { + @override + Future execute(DataCommand command) async { + var data = DataWebFile.fromJson(getParam(command)); + print('Upload URL: ${data.url}'); + + var form = http.MultipartRequest('POST', Uri.parse(data.url)); + if(data.fields != null) + { + for(var field in data.fields!.entries) + { + form.fields[field.key] = field.value; + } + } + if(data.filePart != null && data.fileMimeType != null && data.files != null) + { + for(var filePath in data.files!) + { + var file = File(filePath); + if(file.existsSync()) + { + form.files.add(await http.MultipartFile.fromPath(data.filePart!, file.path, + contentType: MediaType(HttpHeaders.contentTypeHeader, data.fileMimeType!))); + } + else + { + throw Exception('File not found: $filePath'); + } + } + } + return await complete(await super.request(data, form), command); + } +} diff --git a/lib/oto/core/data_composer.dart b/lib/oto/core/data_composer.dart index 5ef9515..279b504 100644 --- a/lib/oto/core/data_composer.dart +++ b/lib/oto/core/data_composer.dart @@ -8,7 +8,7 @@ import 'package:oto_cli/oto/data/jenkins_data.dart'; import 'package:oto_cli/oto/core/defined_data.dart'; abstract class DataComposer { - DataJenkins? jenkinsData; + DataCommon? commonData; String buildYaml = ''; Future compose(String? yaml, Future Function(String, Color?) printer) async { @@ -19,7 +19,7 @@ abstract class DataComposer { class DataComposerTest extends DataComposer { @override Future compose(String? yaml, Future Function(String, Color?) printer) async { - jenkinsData = DataJenkins.fromJson(TestData.jenkinsMap!); + commonData = DataCommon.fromJson(TestData.jenkinsMap!); buildYaml = TestData.buildYaml; return simpleFuture; } @@ -28,7 +28,7 @@ class DataComposerTest extends DataComposer { class DataComposerFile extends DataComposer { @override Future compose(String? yaml, Future Function(String, Color?) printer) async { - jenkinsData = DataJenkins.fromJson(FileData.jenkinsMap!); + commonData = DataCommon.fromJson(FileData.jenkinsMap!); buildYaml = yaml ?? '---'; return simpleFuture; } @@ -44,7 +44,8 @@ class DataComposerJenkins extends DataComposer { print('Start build...'); String jsonStr = ''; if (Platform.isMacOS || Platform.isLinux) { - await Process.run('zsh', [ + var shellExe = Platform.isMacOS ? 'zsh' : 'bash'; + await Process.run(shellExe, [ '${Directory.current.path}/assets/script/shell/jenkins_env_params.sh' ]).then((ProcessResult result) => jsonStr = result.stdout); jenkinsMap = getMapFromJson(jsonStr)!; @@ -66,7 +67,7 @@ class DataComposerJenkins extends DataComposer { await printer('Jenkins Variables', Color.green); print(jsonStr); } - jenkinsData = DataJenkins.fromJson(jenkinsMap!); + commonData = DataCommon.fromJson(jenkinsMap!); buildYaml = await getBuildData(); return simpleFuture; @@ -74,13 +75,14 @@ class DataComposerJenkins extends DataComposer { Future getBuildData() async { var c = Completer(); - var file = File('${jenkinsData!.workspace}/build_data.conf'); + var file = File('${commonData!.workspace}/build_data.conf'); var content = ''; if (Platform.isWindows) { content = file .readAsStringSync(encoding: utf8) - .replaceAll('BuildData=', '') .replaceAll('\\', '/'); + var index = content.indexOf('='); + content = content.substring(index + 1); var regEx = RegExp(r'(%)([a-zA-Z0-9]+)(%)'); var list = regEx.allMatches(content); var params = []; @@ -91,7 +93,7 @@ class DataComposerJenkins extends DataComposer { } } - var temp = File('${jenkinsData!.workspace}/param_temp.bat'); + var temp = File('${commonData!.workspace}/param_temp.bat'); var bat = ''; for (var param in params) { bat += '@echo %$param%\n'; diff --git a/lib/oto/data/command_data.dart b/lib/oto/data/command_data.dart index 2e3814f..cf28706 100644 --- a/lib/oto/data/command_data.dart +++ b/lib/oto/data/command_data.dart @@ -3,7 +3,8 @@ import 'package:dart_framework/utils/slack/slack_sender.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:dart_framework/core/app_data_manager.dart'; -import 'package:dart_framework/utils/slack/slack_data.dart'; +import 'package:oto_cli/oto/commands/build/build_flutter.dart'; +import 'package:oto_cli/oto/commands/build/build_msbuild.dart'; import 'package:oto_cli/oto/commands/command.dart'; import 'package:oto_cli/oto/data/pipeline_data.dart'; part 'command_data.g.dart'; @@ -11,7 +12,7 @@ part 'command_data.g.dart'; /// ***************************** Base Data ****************************/// @JsonSerializable() class DataBuild { - late Map property; + late Map? property; late DataPipeline? pipeline; late List commands; @@ -44,6 +45,13 @@ class DataParam { DataParam(); late String? workspace; + late List? passExitCodes; + late String? setResult; + late String? setExitCode; + + factory DataParam.fromJson(Map json) => + _$DataParamFromJson(json); + Map toJson() => _$DataParamToJson(this); } /// ***************************** Command List ****************************/// @@ -59,6 +67,37 @@ class DataSimpleCommand extends DataParam { Map toJson() => _$DataSimpleCommandToJson(this); } +//Print +@JsonSerializable() +class DataPrint extends DataParam { + DataPrint(); + + late String message; + + factory DataPrint.fromJson(Map json) => + _$DataPrintFromJson(json); + Map toJson() => _$DataPrintToJson(this); +} + +//SetValue +@JsonSerializable() +class DataSetValue extends DataParam { + DataSetValue(); + + @JsonKey(name: 'values-int') + late Map? values_int; + @JsonKey(name: 'values-float') + late Map? values_float; + @JsonKey(name: 'values-string') + late Map? values_string; + @JsonKey(name: 'values-bool') + late Map? values_bool; + + factory DataSetValue.fromJson(Map json) => + _$DataSetValueFromJson(json); + Map toJson() => _$DataSetValueToJson(this); +} + //AppDataCreator @JsonSerializable() class DataAppDataCreator extends DataParam { @@ -66,10 +105,10 @@ class DataAppDataCreator extends DataParam { late SCMType scm; late String relativeAssetPath; - @JsonKey(name: 'return-version') - late String return_version; - @JsonKey(name: 'return-hash') - late String return_hash; + late String setVersion; + late String setHash; + late String? setCount; + late String? setDate; late String name; factory DataAppDataCreator.fromJson(Map json) => @@ -77,6 +116,20 @@ class DataAppDataCreator extends DataParam { Map toJson() => _$DataAppDataCreatorToJson(this); } +//BuildDart +@JsonSerializable() +class DataBuildMSBuild extends DataParam { + DataBuildMSBuild(); + + late String projectFile; + late MSBuildType type; + late MSBuildConfig config; + + factory DataBuildMSBuild.fromJson(Map json) => + _$DataBuildMSBuildFromJson(json); + Map toJson() => _$DataBuildMSBuildToJson(this); +} + //BuildDart @JsonSerializable() class DataBuildDart extends DataParam { @@ -134,16 +187,81 @@ class DataBuildDotNet extends DataParam { class DataBuildiOS extends DataParam { DataBuildiOS(); + late String macPassword; late String scheme; - late String? destination; - late String xcworkspaceFilePath; + late BuildPlatform? os; + late String? xcodeProjectFilePath; + late String? xcworkspaceFilePath; + late String? derivedDataPath; late bool? cleanPod; + late String? configuration; + late Map? settings; factory DataBuildiOS.fromJson(Map json) => _$DataBuildiOSFromJson(json); Map toJson() => _$DataBuildiOSToJson(this); } +//CodeSign +@JsonSerializable() +class DataCodeSign extends DataParam { + DataCodeSign(); + + late String appPath; + late String certificationName; + late String? entitlementPath; + + factory DataCodeSign.fromJson(Map json) => + _$DataCodeSignFromJson(json); + Map toJson() => _$DataCodeSignToJson(this); +} + +//CodeSignVerify +@JsonSerializable() +class DataCodeSignVerify extends DataParam { + DataCodeSignVerify(); + + late String appPath; + + factory DataCodeSignVerify.fromJson(Map json) => + _$DataCodeSignVerifyFromJson(json); + Map toJson() => _$DataCodeSignVerifyToJson(this); +} + +//ProductBuild +@JsonSerializable() +class DataProductBuild extends DataParam { + DataProductBuild(); + + late String appPath; + late String identifier; + late String? scripts; + late String installCertificationName; + late String unsignedResultPath; + late String signedResultPath; + + factory DataProductBuild.fromJson(Map json) => + _$DataProductBuildFromJson(json); + Map toJson() => _$DataProductBuildToJson(this); +} + +//Notarize +@JsonSerializable() +class DataNotarize extends DataParam { + DataNotarize(); + + late String macPassword; + late String bundleName; + late String teamId; + late String appleAccount; + late String applePassword; + late String resultPath; + + factory DataNotarize.fromJson(Map json) => + _$DataNotarizeFromJson(json); + Map toJson() => _$DataNotarizeToJson(this); +} + //ArchiveiOS @JsonSerializable() class DataArchiveiOS extends DataParam { @@ -152,6 +270,7 @@ class DataArchiveiOS extends DataParam { late String xcworkspaceFilePath; late String scheme; late String archivePath; + late String? destination; factory DataArchiveiOS.fromJson(Map json) => _$DataArchiveiOSFromJson(json); @@ -191,19 +310,6 @@ class DataPublishiOS extends DataParam { Map toJson() => _$DataPublishiOSToJson(this); } -//ExecuteApp -@JsonSerializable() -class DataExecuteApp extends DataParam { - DataExecuteApp(); - - late String executable; - late String desktopServicePath; - - factory DataExecuteApp.fromJson(Map json) => - _$DataExecuteAppFromJson(json); - Map toJson() => _$DataExecuteAppToJson(this); -} - //Uploader @JsonSerializable() class DataUploader extends DataParam { @@ -232,6 +338,7 @@ class DataCopy extends DataFile { DataCopy(); late bool? isMove; + late bool? isOverwrite = true; late Map copyMap; factory DataCopy.fromJson(Map json) => @@ -263,14 +370,65 @@ class DataRename extends DataFile { Map toJson() => _$DataRenameToJson(this); } +//File Diff Check +@JsonSerializable() +class DataFileDiffCheck extends DataParam { + DataFileDiffCheck(); + + late List paths; + late String setDiff; + + factory DataFileDiffCheck.fromJson(Map json) => + _$DataFileDiffCheckFromJson(json); + Map toJson() => _$DataFileDiffCheckToJson(this); +} + +//File Read +@JsonSerializable() +class DataFileRead extends DataParam { + DataFileRead(); + + late String path; + late String setContent; + + factory DataFileRead.fromJson(Map json) => + _$DataFileReadFromJson(json); + Map toJson() => _$DataFileReadToJson(this); +} + +//File Write +@JsonSerializable() +class DataFileWrite extends DataParam { + DataFileWrite(); + + late String path; + late String content; + + factory DataFileWrite.fromJson(Map json) => + _$DataFileWriteFromJson(json); + Map toJson() => _$DataFileWriteToJson(this); +} + +//Directory Create +@JsonSerializable() +class DataDirectoryCreate extends DataParam { + DataDirectoryCreate(); + + late String path; + + factory DataDirectoryCreate.fromJson(Map json) => + _$DataDirectoryCreateFromJson(json); + Map toJson() => _$DataDirectoryCreateToJson(this); +} + //Slack @JsonSerializable() class DataSlackSender extends DataParam { DataSlackSender(); late String token; - late String? property; - late DataSlack? message; + late dynamic property; + late Map? message; factory DataSlackSender.fromJson(Map json) => _$DataSlackSenderFromJson(json); @@ -303,13 +461,10 @@ class DataJira extends DataParam { late String token; late String domain; late String issue; - @JsonKey(name: 'sub-channel') - late String? sub_channel; + late String? subChannel; late List users; - @JsonKey(name: 'return-slack-data') - late String return_slack_data; - @JsonKey(name: 'return-slack-channel') - late String return_slack_channel; + late String setSlackData; + late String setSlackChannel; factory DataJira.fromJson(Map json) => _$DataJiraFromJson(json); @@ -347,13 +502,24 @@ class DataZip extends DataParam { class DataShell extends DataParam { DataShell(); - late String path; + late List commands; factory DataShell.fromJson(Map json) => _$DataShellFromJson(json); Map toJson() => _$DataShellToJson(this); } +@JsonSerializable() +class DataShellFile extends DataParam { + DataShellFile(); + + late String path; + + factory DataShellFile.fromJson(Map json) => + _$DataShellFileFromJson(json); + Map toJson() => _$DataShellFileToJson(this); +} + //Git @JsonSerializable() class DataGit extends DataParam { @@ -366,13 +532,37 @@ class DataGit extends DataParam { Map toJson() => _$DataGitToJson(this); } +//GitPush +@JsonSerializable() +class DataGitPush extends DataParam { + DataGitPush(); + + late String? branch; + + factory DataGitPush.fromJson(Map json) => + _$DataGitPushFromJson(json); + Map toJson() => _$DataGitPushToJson(this); +} + +//GitCheckout +@JsonSerializable() +class DataGitCheckout extends DataParam { + DataGitCheckout(); + + late String branch; + late bool? executePull; + + factory DataGitCheckout.fromJson(Map json) => + _$DataGitCheckoutFromJson(json); + Map toJson() => _$DataGitCheckoutToJson(this); +} + //GitCount @JsonSerializable() class DataGitCount extends DataParam { DataGitCount(); - @JsonKey(name: 'result-value') - late String result_value; + late String setValue; factory DataGitCount.fromJson(Map json) => _$DataGitCountFromJson(json); @@ -387,20 +577,90 @@ class DataGitRev extends DataParam { //null will be show local HEAD. Get last revision must be set branch late String? branch; - @JsonKey(name: 'result-value') - late String result_value; + late String setValue; factory DataGitRev.fromJson(Map json) => _$DataGitRevFromJson(json); Map toJson() => _$DataGitRevToJson(this); } -//GitRev +//GitHub +@JsonSerializable() +class DataGitHub extends DataParam { + DataGitHub(); + + late List commands; + + factory DataGitHub.fromJson(Map json) => + _$DataGitHubFromJson(json); + Map toJson() => _$DataGitHubToJson(this); +} + +//GitHub Pull Request Create +//https://cli.github.com/manual/gh_codespace_create +@JsonSerializable() +class DataGitHubPullRequestCreate extends DataParam { + DataGitHubPullRequestCreate(); + + late String title; + late String body; + late String branch; + late String setURL; + late String setNumber; + + factory DataGitHubPullRequestCreate.fromJson(Map json) => + _$DataGitHubPullRequestCreateFromJson(json); + Map toJson() => _$DataGitHubPullRequestCreateToJson(this); +} + +//GitHub Pull Request List +//https://cli.github.com/manual/gh_pr_list +@JsonSerializable() +class DataGitHubPullRequestList extends DataParam { + DataGitHubPullRequestList(); + + late List keys; + late String targetKey; + late String targetValue; + late String setValue; + + factory DataGitHubPullRequestList.fromJson(Map json) => + _$DataGitHubPullRequestListFromJson(json); + Map toJson() => _$DataGitHubPullRequestListToJson(this); +} + +//GitHub Pull Request Close +//https://cli.github.com/manual/gh_pr_close +@JsonSerializable() +class DataGitHubPullRequestClose extends DataParam { + DataGitHubPullRequestClose(); + + late String number; + + factory DataGitHubPullRequestClose.fromJson(Map json) => + _$DataGitHubPullRequestCloseFromJson(json); + Map toJson() => _$DataGitHubPullRequestCloseToJson(this); +} + + +//Protobuf +@JsonSerializable() +class DataProtobuf extends DataParam { + DataProtobuf(); + + late List commands; + + factory DataProtobuf.fromJson(Map json) => + _$DataProtobufFromJson(json); + Map toJson() => _$DataProtobufToJson(this); +} + +//JsonReader @JsonSerializable() class DataJsonReader extends DataParam { DataJsonReader(); - late String path; + late dynamic json; late List pair; factory DataJsonReader.fromJson(Map json) => @@ -408,10 +668,23 @@ class DataJsonReader extends DataParam { Map toJson() => _$DataJsonReaderToJson(this); } +//JsonReaderFile +@JsonSerializable() +class DataJsonReaderFile extends DataParam { + DataJsonReaderFile(); + + late String path; + late List pair; + + factory DataJsonReaderFile.fromJson(Map json) => + _$DataJsonReaderFileFromJson(json); + Map toJson() => _$DataJsonReaderFileToJson(this); +} + @JsonSerializable() class DataPair { late String from; - late String to; + late String setValue; DataPair(); @@ -419,3 +692,140 @@ class DataPair { _$DataPairFromJson(json); Map toJson() => _$DataPairToJson(this); } + +//AwsCli +@JsonSerializable() +class DataAwsCli extends DataParam { + DataAwsCli(); + + @JsonKey(name: "sub-command") + late String subCommand; + late List args; + + factory DataAwsCli.fromJson(Map json) => + _$DataAwsCliFromJson(json); + Map toJson() => _$DataAwsCliToJson(this); +} + +//Docker +@JsonSerializable() +class DataDocker extends DataParam { + DataDocker(); + + late String command; + late List args; + + factory DataDocker.fromJson(Map json) => + _$DataDockerFromJson(json); + Map toJson() => _$DataDockerToJson(this); +} + +//Gradle +@JsonSerializable() +class DataGradle extends DataParam { + DataGradle(); + + late List args; + + factory DataGradle.fromJson(Map json) => + _$DataGradleFromJson(json); + Map toJson() => _$DataGradleToJson(this); +} + +//String Sub +@JsonSerializable() +class DataStringSub extends DataParam { + DataStringSub(); + + late int? startIndex; + late int? lastIndex; + late String text; + late String setValue; + + factory DataStringSub.fromJson(Map json) => + _$DataStringSubFromJson(json); + Map toJson() => _$DataStringSubToJson(this); +} + +//String Replace +@JsonSerializable() +class DataStringReplace extends DataParam { + DataStringReplace(); + + late String text; + late String setValue; + late String from; + late String to; + + factory DataStringReplace.fromJson(Map json) => + _$DataStringReplaceFromJson(json); + Map toJson() => _$DataStringReplaceToJson(this); +} + +//Web Base +@JsonSerializable() +class DataWebBase extends DataParam { + DataWebBase(); + + late String url; + late String? method; + late Map? headers = {}; + late Map? fields = {}; + late List? successCodes; + + factory DataWebBase.fromJson(Map json) => + _$DataWebBaseFromJson(json); + Map toJson() => _$DataWebBaseToJson(this); +} + +//Web File +@JsonSerializable() +class DataWebFile extends DataWebBase { + DataWebFile(); + + late String? filePart; + late String? fileMimeType; + late List? files = []; + + factory DataWebFile.fromJson(Map json) => + _$DataWebFileFromJson(json); + Map toJson() => _$DataWebFileToJson(this); +} + +//Process Using Port +@JsonSerializable() +class DataProcessPortUse extends DataParam { + DataProcessPortUse(); + + late String port; + late String setPid; + + factory DataProcessPortUse.fromJson(Map json) => + _$DataProcessPortUseFromJson(json); + Map toJson() => _$DataProcessPortUseToJson(this); +} + +//Process Run +@JsonSerializable() +class DataProcessRun extends DataParam { + DataProcessRun(); + + late String executable; + late String? param; + + factory DataProcessRun.fromJson(Map json) => + _$DataProcessRunFromJson(json); + Map toJson() => _$DataProcessRunToJson(this); +} + +//Process Kill +@JsonSerializable() +class DataProcessKill extends DataParam { + DataProcessKill(); + + late String pid; + + factory DataProcessKill.fromJson(Map json) => + _$DataProcessKillFromJson(json); + Map toJson() => _$DataProcessKillToJson(this); +} diff --git a/lib/oto/data/command_data.g.dart b/lib/oto/data/command_data.g.dart index 0e9093a..1270238 100644 --- a/lib/oto/data/command_data.g.dart +++ b/lib/oto/data/command_data.g.dart @@ -7,7 +7,7 @@ part of 'command_data.dart'; // ************************************************************************** DataBuild _$DataBuildFromJson(Map json) => DataBuild() - ..property = json['property'] as Map + ..property = json['property'] as Map? ..pipeline = json['pipeline'] == null ? null : DataPipeline.fromJson(json['pipeline'] as Map) @@ -35,65 +35,160 @@ Map _$DataCommandToJson(DataCommand instance) => const _$CommandTypeEnumMap = { CommandType.SimpleCommand: 'SimpleCommand', + CommandType.Print: 'Print', + CommandType.SetValue: 'SetValue', CommandType.CreateAppData: 'CreateAppData', CommandType.BuildDart: 'BuildDart', CommandType.BuildFlutter: 'BuildFlutter', CommandType.BuildDartCompile: 'BuildDartCompile', CommandType.BuildDotNet: 'BuildDotNet', CommandType.BuildiOS: 'BuildiOS', + CommandType.BuildMSBuild: 'BuildMSBuild', + CommandType.CodeSign: 'CodeSign', + CommandType.CodeSignVerify: 'CodeSignVerify', + CommandType.ProductBuild: 'ProductBuild', + CommandType.Notarize: 'Notarize', CommandType.ArchiveiOS: 'ArchiveiOS', CommandType.ExportiOS: 'ExportiOS', CommandType.PublishiOS: 'PublishiOS', - CommandType.ExecuteApp: 'ExecuteApp', CommandType.Upload: 'Upload', CommandType.Copy: 'Copy', CommandType.Rename: 'Rename', CommandType.Delete: 'Delete', + CommandType.FileDiffCheck: 'FileDiffCheck', + CommandType.FileRead: 'FileRead', + CommandType.FileWrite: 'FileWrite', + CommandType.DirectoryCreate: 'DirectoryCreate', CommandType.Slack: 'Slack', CommandType.SlackBuild: 'SlackBuild', + CommandType.StringSub: 'StringSub', + CommandType.StringReplace: 'StringReplace', CommandType.Jira: 'Jira', CommandType.Zip: 'Zip', CommandType.Shell: 'Shell', + CommandType.ShellFile: 'ShellFile', CommandType.Git: 'Git', + CommandType.GitPush: 'GitPush', + CommandType.GitCheckout: 'GitCheckout', CommandType.GitRev: 'GitRev', CommandType.GitCount: 'GitCount', + CommandType.GitHub: 'GitHub', + CommandType.GitHubPullRequestCreate: 'GitHubPullRequestCreate', + CommandType.GitHubPullRequestList: 'GitHubPullRequestList', + CommandType.GitHubPullRequestClose: 'GitHubPullRequestClose', + CommandType.Protobuf: 'Protobuf', CommandType.JsonReader: 'JsonReader', + CommandType.JsonReaderFile: 'JsonReaderFile', + CommandType.AwsCli: 'AwsCli', + CommandType.Docker: 'Docker', + CommandType.Gradle: 'Gradle', + CommandType.WebRequest: 'WebRequest', + CommandType.WebFile: 'WebFile', + CommandType.ProcessPortUse: 'ProcessPortUse', + CommandType.ProcessRun: 'ProcessRun', + CommandType.ProcessKill: 'ProcessKill', }; -DataParam _$DataParamFromJson(Map json) => - DataParam()..workspace = json['workspace'] as String?; +DataParam _$DataParamFromJson(Map json) => DataParam() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String?; Map _$DataParamToJson(DataParam instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, }; DataSimpleCommand _$DataSimpleCommandFromJson(Map json) => DataSimpleCommand() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..message = json['message'] as String; Map _$DataSimpleCommandToJson(DataSimpleCommand instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'message': instance.message, }; +DataPrint _$DataPrintFromJson(Map json) => DataPrint() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..message = json['message'] as String; + +Map _$DataPrintToJson(DataPrint instance) => { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'message': instance.message, + }; + +DataSetValue _$DataSetValueFromJson(Map json) => DataSetValue() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..values_int = json['values-int'] as Map? + ..values_float = json['values-float'] as Map? + ..values_string = json['values-string'] as Map? + ..values_bool = json['values-bool'] as Map?; + +Map _$DataSetValueToJson(DataSetValue instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'values-int': instance.values_int, + 'values-float': instance.values_float, + 'values-string': instance.values_string, + 'values-bool': instance.values_bool, + }; + DataAppDataCreator _$DataAppDataCreatorFromJson(Map json) => DataAppDataCreator() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..scm = $enumDecode(_$SCMTypeEnumMap, json['scm']) ..relativeAssetPath = json['relativeAssetPath'] as String - ..return_version = json['return-version'] as String - ..return_hash = json['return-hash'] as String + ..setVersion = json['setVersion'] as String + ..setHash = json['setHash'] as String + ..setCount = json['setCount'] as String? + ..setDate = json['setDate'] as String? ..name = json['name'] as String; Map _$DataAppDataCreatorToJson(DataAppDataCreator instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'scm': _$SCMTypeEnumMap[instance.scm]!, 'relativeAssetPath': instance.relativeAssetPath, - 'return-version': instance.return_version, - 'return-hash': instance.return_hash, + 'setVersion': instance.setVersion, + 'setHash': instance.setHash, + 'setCount': instance.setCount, + 'setDate': instance.setDate, 'name': instance.name, }; @@ -102,20 +197,67 @@ const _$SCMTypeEnumMap = { SCMType.Git: 'Git', }; +DataBuildMSBuild _$DataBuildMSBuildFromJson(Map json) => + DataBuildMSBuild() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..projectFile = json['projectFile'] as String + ..type = $enumDecode(_$MSBuildTypeEnumMap, json['type']) + ..config = $enumDecode(_$MSBuildConfigEnumMap, json['config']); + +Map _$DataBuildMSBuildToJson(DataBuildMSBuild instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'projectFile': instance.projectFile, + 'type': _$MSBuildTypeEnumMap[instance.type]!, + 'config': _$MSBuildConfigEnumMap[instance.config]!, + }; + +const _$MSBuildTypeEnumMap = { + MSBuildType.Clean: 'Clean', + MSBuildType.Build: 'Build', + MSBuildType.Rebuild: 'Rebuild', +}; + +const _$MSBuildConfigEnumMap = { + MSBuildConfig.Debug: 'Debug', + MSBuildConfig.Release: 'Release', +}; + DataBuildDart _$DataBuildDartFromJson(Map json) => DataBuildDart() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..executeBuildRunner = json['executeBuildRunner'] as bool?; Map _$DataBuildDartToJson(DataBuildDart instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'executeBuildRunner': instance.executeBuildRunner, }; DataBuildFlutter _$DataBuildFlutterFromJson(Map json) => DataBuildFlutter() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..executeBuildRunner = json['executeBuildRunner'] as bool? ..platform = json['platform'] as String ..additional = json['additional'] as String?; @@ -123,6 +265,9 @@ DataBuildFlutter _$DataBuildFlutterFromJson(Map json) => Map _$DataBuildFlutterToJson(DataBuildFlutter instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'executeBuildRunner': instance.executeBuildRunner, 'platform': instance.platform, 'additional': instance.additional, @@ -132,6 +277,11 @@ DataBuildDartCompile _$DataBuildDartCompileFromJson( Map json) => DataBuildDartCompile() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..executeBuildRunner = json['executeBuildRunner'] as bool? ..targetDartFile = json['targetDartFile'] as String? ..buildFileName = json['buildFileName'] as String?; @@ -140,6 +290,9 @@ Map _$DataBuildDartCompileToJson( DataBuildDartCompile instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'executeBuildRunner': instance.executeBuildRunner, 'targetDartFile': instance.targetDartFile, 'buildFileName': instance.buildFileName, @@ -148,48 +301,196 @@ Map _$DataBuildDartCompileToJson( DataBuildDotNet _$DataBuildDotNetFromJson(Map json) => DataBuildDotNet() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..projectFile = json['projectFile'] as String; Map _$DataBuildDotNetToJson(DataBuildDotNet instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'projectFile': instance.projectFile, }; DataBuildiOS _$DataBuildiOSFromJson(Map json) => DataBuildiOS() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..macPassword = json['macPassword'] as String ..scheme = json['scheme'] as String - ..destination = json['destination'] as String? - ..xcworkspaceFilePath = json['xcworkspaceFilePath'] as String - ..cleanPod = json['cleanPod'] as bool?; + ..os = $enumDecodeNullable(_$BuildPlatformEnumMap, json['os']) + ..xcodeProjectFilePath = json['xcodeProjectFilePath'] as String? + ..xcworkspaceFilePath = json['xcworkspaceFilePath'] as String? + ..derivedDataPath = json['derivedDataPath'] as String? + ..cleanPod = json['cleanPod'] as bool? + ..configuration = json['configuration'] as String? + ..settings = (json['settings'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ); Map _$DataBuildiOSToJson(DataBuildiOS instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'macPassword': instance.macPassword, 'scheme': instance.scheme, - 'destination': instance.destination, + 'os': _$BuildPlatformEnumMap[instance.os], + 'xcodeProjectFilePath': instance.xcodeProjectFilePath, 'xcworkspaceFilePath': instance.xcworkspaceFilePath, + 'derivedDataPath': instance.derivedDataPath, 'cleanPod': instance.cleanPod, + 'configuration': instance.configuration, + 'settings': instance.settings, + }; + +const _$BuildPlatformEnumMap = { + BuildPlatform.Windows: 'Windows', + BuildPlatform.Macos: 'Macos', + BuildPlatform.Web: 'Web', + BuildPlatform.Apk: 'Apk', + BuildPlatform.Appbundle: 'Appbundle', + BuildPlatform.iOS: 'iOS', + BuildPlatform.Linux: 'Linux', +}; + +DataCodeSign _$DataCodeSignFromJson(Map json) => DataCodeSign() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..appPath = json['appPath'] as String + ..certificationName = json['certificationName'] as String + ..entitlementPath = json['entitlementPath'] as String?; + +Map _$DataCodeSignToJson(DataCodeSign instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'appPath': instance.appPath, + 'certificationName': instance.certificationName, + 'entitlementPath': instance.entitlementPath, + }; + +DataCodeSignVerify _$DataCodeSignVerifyFromJson(Map json) => + DataCodeSignVerify() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..appPath = json['appPath'] as String; + +Map _$DataCodeSignVerifyToJson(DataCodeSignVerify instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'appPath': instance.appPath, + }; + +DataProductBuild _$DataProductBuildFromJson(Map json) => + DataProductBuild() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..appPath = json['appPath'] as String + ..identifier = json['identifier'] as String + ..scripts = json['scripts'] as String? + ..installCertificationName = json['installCertificationName'] as String + ..unsignedResultPath = json['unsignedResultPath'] as String + ..signedResultPath = json['signedResultPath'] as String; + +Map _$DataProductBuildToJson(DataProductBuild instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'appPath': instance.appPath, + 'identifier': instance.identifier, + 'scripts': instance.scripts, + 'installCertificationName': instance.installCertificationName, + 'unsignedResultPath': instance.unsignedResultPath, + 'signedResultPath': instance.signedResultPath, + }; + +DataNotarize _$DataNotarizeFromJson(Map json) => DataNotarize() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..macPassword = json['macPassword'] as String + ..bundleName = json['bundleName'] as String + ..teamId = json['teamId'] as String + ..appleAccount = json['appleAccount'] as String + ..applePassword = json['applePassword'] as String + ..resultPath = json['resultPath'] as String; + +Map _$DataNotarizeToJson(DataNotarize instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'macPassword': instance.macPassword, + 'bundleName': instance.bundleName, + 'teamId': instance.teamId, + 'appleAccount': instance.appleAccount, + 'applePassword': instance.applePassword, + 'resultPath': instance.resultPath, }; DataArchiveiOS _$DataArchiveiOSFromJson(Map json) => DataArchiveiOS() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..xcworkspaceFilePath = json['xcworkspaceFilePath'] as String ..scheme = json['scheme'] as String - ..archivePath = json['archivePath'] as String; + ..archivePath = json['archivePath'] as String + ..destination = json['destination'] as String?; Map _$DataArchiveiOSToJson(DataArchiveiOS instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'xcworkspaceFilePath': instance.xcworkspaceFilePath, 'scheme': instance.scheme, 'archivePath': instance.archivePath, + 'destination': instance.destination, }; DataExportiOS _$DataExportiOSFromJson(Map json) => DataExportiOS() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..archivePath = json['archivePath'] as String ..exportOptionPlistPath = json['exportOptionPlistPath'] as String ..exportPath = json['exportPath'] as String; @@ -197,6 +498,9 @@ DataExportiOS _$DataExportiOSFromJson(Map json) => Map _$DataExportiOSToJson(DataExportiOS instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'archivePath': instance.archivePath, 'exportOptionPlistPath': instance.exportOptionPlistPath, 'exportPath': instance.exportPath, @@ -205,6 +509,11 @@ Map _$DataExportiOSToJson(DataExportiOS instance) => DataPublishiOS _$DataPublishiOSFromJson(Map json) => DataPublishiOS() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..bundleID = json['bundleID'] as String ..version = json['version'] as String ..appName = json['appName'] as String @@ -217,6 +526,9 @@ DataPublishiOS _$DataPublishiOSFromJson(Map json) => Map _$DataPublishiOSToJson(DataPublishiOS instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'bundleID': instance.bundleID, 'version': instance.version, 'appName': instance.appName, @@ -227,21 +539,12 @@ Map _$DataPublishiOSToJson(DataPublishiOS instance) => 'destinationPath': instance.destinationPath, }; -DataExecuteApp _$DataExecuteAppFromJson(Map json) => - DataExecuteApp() - ..workspace = json['workspace'] as String? - ..executable = json['executable'] as String - ..desktopServicePath = json['desktopServicePath'] as String; - -Map _$DataExecuteAppToJson(DataExecuteApp instance) => - { - 'workspace': instance.workspace, - 'executable': instance.executable, - 'desktopServicePath': instance.desktopServicePath, - }; - DataUploader _$DataUploaderFromJson(Map json) => DataUploader() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..sftp = json['sftp'] as bool ..port = json['port'] as int ..host = json['host'] as String @@ -252,6 +555,9 @@ DataUploader _$DataUploaderFromJson(Map json) => DataUploader() Map _$DataUploaderToJson(DataUploader instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'sftp': instance.sftp, 'port': instance.port, 'host': instance.host, @@ -262,21 +568,34 @@ Map _$DataUploaderToJson(DataUploader instance) => DataCopy _$DataCopyFromJson(Map json) => DataCopy() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..ignorePattern = (json['ignorePattern'] as List?) ?.map((e) => e as String) .toList() ..isMove = json['isMove'] as bool? + ..isOverwrite = json['isOverwrite'] as bool? ..copyMap = Map.from(json['copyMap'] as Map); Map _$DataCopyToJson(DataCopy instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'ignorePattern': instance.ignorePattern, 'isMove': instance.isMove, + 'isOverwrite': instance.isOverwrite, 'copyMap': instance.copyMap, }; DataDelete _$DataDeleteFromJson(Map json) => DataDelete() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..ignorePattern = (json['ignorePattern'] as List?) ?.map((e) => e as String) .toList() @@ -285,12 +604,19 @@ DataDelete _$DataDeleteFromJson(Map json) => DataDelete() Map _$DataDeleteToJson(DataDelete instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'ignorePattern': instance.ignorePattern, 'list': instance.list, }; DataRename _$DataRenameFromJson(Map json) => DataRename() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..ignorePattern = (json['ignorePattern'] as List?) ?.map((e) => e as String) .toList() @@ -299,22 +625,113 @@ DataRename _$DataRenameFromJson(Map json) => DataRename() Map _$DataRenameToJson(DataRename instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'ignorePattern': instance.ignorePattern, 'renameMap': instance.renameMap, }; +DataFileDiffCheck _$DataFileDiffCheckFromJson(Map json) => + DataFileDiffCheck() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..paths = + (json['paths'] as List).map((e) => e as String).toList() + ..setDiff = json['setDiff'] as String; + +Map _$DataFileDiffCheckToJson(DataFileDiffCheck instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'paths': instance.paths, + 'setDiff': instance.setDiff, + }; + +DataFileRead _$DataFileReadFromJson(Map json) => DataFileRead() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..path = json['path'] as String + ..setContent = json['setContent'] as String; + +Map _$DataFileReadToJson(DataFileRead instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'path': instance.path, + 'setContent': instance.setContent, + }; + +DataFileWrite _$DataFileWriteFromJson(Map json) => + DataFileWrite() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..path = json['path'] as String + ..content = json['content'] as String; + +Map _$DataFileWriteToJson(DataFileWrite instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'path': instance.path, + 'content': instance.content, + }; + +DataDirectoryCreate _$DataDirectoryCreateFromJson(Map json) => + DataDirectoryCreate() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..path = json['path'] as String; + +Map _$DataDirectoryCreateToJson( + DataDirectoryCreate instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'path': instance.path, + }; + DataSlackSender _$DataSlackSenderFromJson(Map json) => DataSlackSender() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..token = json['token'] as String - ..property = json['property'] as String? - ..message = json['message'] == null - ? null - : DataSlack.fromJson(json['message'] as Map); + ..property = json['property'] + ..message = json['message'] as Map?; Map _$DataSlackSenderToJson(DataSlackSender instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'token': instance.token, 'property': instance.property, 'message': instance.message, @@ -323,11 +740,14 @@ Map _$DataSlackSenderToJson(DataSlackSender instance) => DataSlackBuild _$DataSlackBuildFromJson(Map json) => DataSlackBuild() ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..token = json['token'] as String - ..property = json['property'] as String? - ..message = json['message'] == null - ? null - : DataSlack.fromJson(json['message'] as Map) + ..property = json['property'] + ..message = json['message'] as Map? ..appName = json['appName'] as String ..type = $enumDecode(_$SlackBuildTypeEnumMap, json['type']) ..color = json['color'] as String @@ -337,6 +757,9 @@ DataSlackBuild _$DataSlackBuildFromJson(Map json) => Map _$DataSlackBuildToJson(DataSlackBuild instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'token': instance.token, 'property': instance.property, 'message': instance.message, @@ -357,98 +780,323 @@ const _$SlackBuildTypeEnumMap = { DataJira _$DataJiraFromJson(Map json) => DataJira() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..id = json['id'] as String ..token = json['token'] as String ..domain = json['domain'] as String ..issue = json['issue'] as String - ..sub_channel = json['sub-channel'] as String? + ..subChannel = json['subChannel'] as String? ..users = (json['users'] as List) .map((e) => DataJiraUser.fromJson(e as Map)) .toList() - ..return_slack_data = json['return-slack-data'] as String - ..return_slack_channel = json['return-slack-channel'] as String; + ..setSlackData = json['setSlackData'] as String + ..setSlackChannel = json['setSlackChannel'] as String; Map _$DataJiraToJson(DataJira instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'id': instance.id, 'token': instance.token, 'domain': instance.domain, 'issue': instance.issue, - 'sub-channel': instance.sub_channel, + 'subChannel': instance.subChannel, 'users': instance.users, - 'return-slack-data': instance.return_slack_data, - 'return-slack-channel': instance.return_slack_channel, + 'setSlackData': instance.setSlackData, + 'setSlackChannel': instance.setSlackChannel, }; DataJiraUser _$DataJiraUserFromJson(Map json) => DataJiraUser() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..mail = json['mail'] as String? ..slackID = json['slackID'] as String?; Map _$DataJiraUserToJson(DataJiraUser instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'mail': instance.mail, 'slackID': instance.slackID, }; DataZip _$DataZipFromJson(Map json) => DataZip() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..zipFile = json['zipFile'] as String ..zipList = (json['zipList'] as List).map((e) => e as String).toList(); Map _$DataZipToJson(DataZip instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'zipFile': instance.zipFile, 'zipList': instance.zipList, }; DataShell _$DataShellFromJson(Map json) => DataShell() ..workspace = json['workspace'] as String? - ..path = json['path'] as String; + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..commands = + (json['commands'] as List).map((e) => e as String).toList(); Map _$DataShellToJson(DataShell instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'commands': instance.commands, + }; + +DataShellFile _$DataShellFileFromJson(Map json) => + DataShellFile() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..path = json['path'] as String; + +Map _$DataShellFileToJson(DataShellFile instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'path': instance.path, }; DataGit _$DataGitFromJson(Map json) => DataGit() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..commands = (json['commands'] as List).map((e) => e as String).toList(); Map _$DataGitToJson(DataGit instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'commands': instance.commands, }; +DataGitPush _$DataGitPushFromJson(Map json) => DataGitPush() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..branch = json['branch'] as String?; + +Map _$DataGitPushToJson(DataGitPush instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'branch': instance.branch, + }; + +DataGitCheckout _$DataGitCheckoutFromJson(Map json) => + DataGitCheckout() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..branch = json['branch'] as String + ..executePull = json['executePull'] as bool?; + +Map _$DataGitCheckoutToJson(DataGitCheckout instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'branch': instance.branch, + 'executePull': instance.executePull, + }; + DataGitCount _$DataGitCountFromJson(Map json) => DataGitCount() ..workspace = json['workspace'] as String? - ..result_value = json['result-value'] as String; + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..setValue = json['setValue'] as String; Map _$DataGitCountToJson(DataGitCount instance) => { 'workspace': instance.workspace, - 'result-value': instance.result_value, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'setValue': instance.setValue, }; DataGitRev _$DataGitRevFromJson(Map json) => DataGitRev() ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? ..branch = json['branch'] as String? - ..result_value = json['result-value'] as String; + ..setValue = json['setValue'] as String; Map _$DataGitRevToJson(DataGitRev instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'branch': instance.branch, - 'result-value': instance.result_value, + 'setValue': instance.setValue, + }; + +DataGitHub _$DataGitHubFromJson(Map json) => DataGitHub() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..commands = + (json['commands'] as List).map((e) => e as String).toList(); + +Map _$DataGitHubToJson(DataGitHub instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'commands': instance.commands, + }; + +DataGitHubPullRequestCreate _$DataGitHubPullRequestCreateFromJson( + Map json) => + DataGitHubPullRequestCreate() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..title = json['title'] as String + ..body = json['body'] as String + ..branch = json['branch'] as String + ..setURL = json['setURL'] as String + ..setNumber = json['setNumber'] as String; + +Map _$DataGitHubPullRequestCreateToJson( + DataGitHubPullRequestCreate instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'title': instance.title, + 'body': instance.body, + 'branch': instance.branch, + 'setURL': instance.setURL, + 'setNumber': instance.setNumber, + }; + +DataGitHubPullRequestList _$DataGitHubPullRequestListFromJson( + Map json) => + DataGitHubPullRequestList() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..keys = (json['keys'] as List).map((e) => e as String).toList() + ..targetKey = json['targetKey'] as String + ..targetValue = json['targetValue'] as String + ..setValue = json['setValue'] as String; + +Map _$DataGitHubPullRequestListToJson( + DataGitHubPullRequestList instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'keys': instance.keys, + 'targetKey': instance.targetKey, + 'targetValue': instance.targetValue, + 'setValue': instance.setValue, + }; + +DataGitHubPullRequestClose _$DataGitHubPullRequestCloseFromJson( + Map json) => + DataGitHubPullRequestClose() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..number = json['number'] as String; + +Map _$DataGitHubPullRequestCloseToJson( + DataGitHubPullRequestClose instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'number': instance.number, + }; + +DataProtobuf _$DataProtobufFromJson(Map json) => DataProtobuf() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..commands = + (json['commands'] as List).map((e) => e as String).toList(); + +Map _$DataProtobufToJson(DataProtobuf instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'commands': instance.commands, }; DataJsonReader _$DataJsonReaderFromJson(Map json) => DataJsonReader() ..workspace = json['workspace'] as String? - ..path = json['path'] as String + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..json = json['json'] ..pair = (json['pair'] as List) .map((e) => DataPair.fromJson(e as Map)) .toList(); @@ -456,15 +1104,271 @@ DataJsonReader _$DataJsonReaderFromJson(Map json) => Map _$DataJsonReaderToJson(DataJsonReader instance) => { 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'json': instance.json, + 'pair': instance.pair, + }; + +DataJsonReaderFile _$DataJsonReaderFileFromJson(Map json) => + DataJsonReaderFile() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..path = json['path'] as String + ..pair = (json['pair'] as List) + .map((e) => DataPair.fromJson(e as Map)) + .toList(); + +Map _$DataJsonReaderFileToJson(DataJsonReaderFile instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, 'path': instance.path, 'pair': instance.pair, }; DataPair _$DataPairFromJson(Map json) => DataPair() ..from = json['from'] as String - ..to = json['to'] as String; + ..setValue = json['setValue'] as String; Map _$DataPairToJson(DataPair instance) => { + 'from': instance.from, + 'setValue': instance.setValue, + }; + +DataAwsCli _$DataAwsCliFromJson(Map json) => DataAwsCli() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..subCommand = json['sub-command'] as String + ..args = (json['args'] as List).map((e) => e as String).toList(); + +Map _$DataAwsCliToJson(DataAwsCli instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'sub-command': instance.subCommand, + 'args': instance.args, + }; + +DataDocker _$DataDockerFromJson(Map json) => DataDocker() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..command = json['command'] as String + ..args = (json['args'] as List).map((e) => e as String).toList(); + +Map _$DataDockerToJson(DataDocker instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'command': instance.command, + 'args': instance.args, + }; + +DataGradle _$DataGradleFromJson(Map json) => DataGradle() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..args = (json['args'] as List).map((e) => e as String).toList(); + +Map _$DataGradleToJson(DataGradle instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'args': instance.args, + }; + +DataStringSub _$DataStringSubFromJson(Map json) => + DataStringSub() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..startIndex = json['startIndex'] as int? + ..lastIndex = json['lastIndex'] as int? + ..text = json['text'] as String + ..setValue = json['setValue'] as String; + +Map _$DataStringSubToJson(DataStringSub instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'startIndex': instance.startIndex, + 'lastIndex': instance.lastIndex, + 'text': instance.text, + 'setValue': instance.setValue, + }; + +DataStringReplace _$DataStringReplaceFromJson(Map json) => + DataStringReplace() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..text = json['text'] as String + ..setValue = json['setValue'] as String + ..from = json['from'] as String + ..to = json['to'] as String; + +Map _$DataStringReplaceToJson(DataStringReplace instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'text': instance.text, + 'setValue': instance.setValue, 'from': instance.from, 'to': instance.to, }; + +DataWebBase _$DataWebBaseFromJson(Map json) => DataWebBase() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..url = json['url'] as String + ..method = json['method'] as String? + ..headers = (json['headers'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..fields = (json['fields'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..successCodes = json['successCodes'] as List?; + +Map _$DataWebBaseToJson(DataWebBase instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'url': instance.url, + 'method': instance.method, + 'headers': instance.headers, + 'fields': instance.fields, + 'successCodes': instance.successCodes, + }; + +DataWebFile _$DataWebFileFromJson(Map json) => DataWebFile() + ..workspace = json['workspace'] as String? + ..passExitCodes = + (json['passExitCodes'] as List?)?.map((e) => e as int).toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..url = json['url'] as String + ..method = json['method'] as String? + ..headers = (json['headers'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..fields = (json['fields'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..successCodes = json['successCodes'] as List? + ..filePart = json['filePart'] as String? + ..fileMimeType = json['fileMimeType'] as String? + ..files = (json['files'] as List?)?.map((e) => e as String).toList(); + +Map _$DataWebFileToJson(DataWebFile instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'url': instance.url, + 'method': instance.method, + 'headers': instance.headers, + 'fields': instance.fields, + 'successCodes': instance.successCodes, + 'filePart': instance.filePart, + 'fileMimeType': instance.fileMimeType, + 'files': instance.files, + }; + +DataProcessPortUse _$DataProcessPortUseFromJson(Map json) => + DataProcessPortUse() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..port = json['port'] as String + ..setPid = json['setPid'] as String; + +Map _$DataProcessPortUseToJson(DataProcessPortUse instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'port': instance.port, + 'setPid': instance.setPid, + }; + +DataProcessRun _$DataProcessRunFromJson(Map json) => + DataProcessRun() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..executable = json['executable'] as String + ..param = json['param'] as String?; + +Map _$DataProcessRunToJson(DataProcessRun instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'executable': instance.executable, + 'param': instance.param, + }; + +DataProcessKill _$DataProcessKillFromJson(Map json) => + DataProcessKill() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => e as int) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..pid = json['pid'] as String; + +Map _$DataProcessKillToJson(DataProcessKill instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'pid': instance.pid, + }; diff --git a/lib/oto/data/jenkins_data.dart b/lib/oto/data/jenkins_data.dart index 2f881d3..4530f8f 100644 --- a/lib/oto/data/jenkins_data.dart +++ b/lib/oto/data/jenkins_data.dart @@ -2,7 +2,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'jenkins_data.g.dart'; @JsonSerializable() -class DataJenkins { +class DataCommon { late String workspace; late String jenkinsHome; late String jenkinsUrl; @@ -16,9 +16,9 @@ class DataJenkins { late String gitBranch; late String buildTag; - DataJenkins(); + DataCommon(); - factory DataJenkins.fromJson(Map json) => - _$DataJenkinsFromJson(json); - Map toJson() => _$DataJenkinsToJson(this); + factory DataCommon.fromJson(Map json) => + _$DataCommonFromJson(json); + Map toJson() => _$DataCommonToJson(this); } diff --git a/lib/oto/data/jenkins_data.g.dart b/lib/oto/data/jenkins_data.g.dart index d8df864..921400c 100644 --- a/lib/oto/data/jenkins_data.g.dart +++ b/lib/oto/data/jenkins_data.g.dart @@ -6,7 +6,7 @@ part of 'jenkins_data.dart'; // JsonSerializableGenerator // ************************************************************************** -DataJenkins _$DataJenkinsFromJson(Map json) => DataJenkins() +DataCommon _$DataCommonFromJson(Map json) => DataCommon() ..workspace = json['workspace'] as String ..jenkinsHome = json['jenkinsHome'] as String ..jenkinsUrl = json['jenkinsUrl'] as String @@ -20,7 +20,7 @@ DataJenkins _$DataJenkinsFromJson(Map json) => DataJenkins() ..gitBranch = json['gitBranch'] as String ..buildTag = json['buildTag'] as String; -Map _$DataJenkinsToJson(DataJenkins instance) => +Map _$DataCommonToJson(DataCommon instance) => { 'workspace': instance.workspace, 'jenkinsHome': instance.jenkinsHome, diff --git a/lib/oto/data/pipeline_data.dart b/lib/oto/data/pipeline_data.dart index e6761fc..bcebefb 100644 --- a/lib/oto/data/pipeline_data.dart +++ b/lib/oto/data/pipeline_data.dart @@ -76,6 +76,27 @@ class DataCondition implements DataValidator { Map toJson() => _$DataConditionToJson(this); } +@JsonSerializable() +class DataExeHandle implements DataValidator { + late String id; + @JsonKey(name: 'on-success') + late List on_success; + @JsonKey(name: 'on-fail') + late List on_fail; + + DataExeHandle(); + + @override + PipelineValidateResult validate() { + var result = PipelineValidateResult(); + return result; + } + + factory DataExeHandle.fromJson(Map json) => _$DataExeHandleFromJson(json); + @override + Map toJson() => _$DataExeHandleToJson(this); +} + @JsonSerializable() class DataIf extends DataCondition { @JsonKey(name: 'on-true') @@ -105,6 +126,40 @@ class DataIf extends DataCondition { Map toJson() => _$DataIfToJson(this); } +@JsonSerializable() +class DataContain extends DataValidator { + late dynamic list; + late String target; + @JsonKey(name: 'on-true') + late List? on_true; + @JsonKey(name: 'on-false') + late List? on_false; + + DataContain(); + + @override + PipelineValidateResult validate() { + var result = PipelineValidateResult(); + if(!(list is List || list is String)) + { + result.message = 'list field Must be type of "List" or "String".'; + result.enable = false; + return result; + } + + if (on_true == null && on_false == null) { + result.message = 'If syntax requires on-true or on-false.'; + result.enable = false; + return result; + } + return result; + } + + factory DataContain.fromJson(Map json) => _$DataContainFromJson(json); + @override + Map toJson() => _$DataContainToJson(this); +} + @JsonSerializable() class DataWhile extends DataCondition { @JsonKey(name: 'on-do') @@ -133,6 +188,43 @@ class DataWhile extends DataCondition { Map toJson() => _$DataWhileToJson(this); } +@JsonSerializable() +class DataForeach extends DataValidator { + + late String iterator; + late dynamic setKey; + late dynamic setValue; + + @JsonKey(name: 'on-do') + late List? on_do; + + DataForeach(); + + @override + PipelineValidateResult validate() { + var result = PipelineValidateResult(); + + if(setValue == null) + { + result.message = 'Syntax requires a settable element name.'; + result.enable = false; + return result; + } + + if (on_do == null) { + result.message = 'foreach syntax requires on-do.'; + result.enable = false; + return result; + } + return result; + } + + factory DataForeach.fromJson(Map json) => + _$DataForeachFromJson(json); + @override + Map toJson() => _$DataForeachToJson(this); +} + @JsonSerializable() class DataSwitch extends DataCondition { late List cases = []; diff --git a/lib/oto/data/pipeline_data.g.dart b/lib/oto/data/pipeline_data.g.dart index 1c7a8c2..ea3e9b7 100644 --- a/lib/oto/data/pipeline_data.g.dart +++ b/lib/oto/data/pipeline_data.g.dart @@ -39,6 +39,19 @@ Map _$DataConditionToJson(DataCondition instance) => 'condition-object': instance.condition_object, }; +DataExeHandle _$DataExeHandleFromJson(Map json) => + DataExeHandle() + ..id = json['id'] as String + ..on_success = json['on-success'] as List + ..on_fail = json['on-fail'] as List; + +Map _$DataExeHandleToJson(DataExeHandle instance) => + { + 'id': instance.id, + 'on-success': instance.on_success, + 'on-fail': instance.on_fail, + }; + DataIf _$DataIfFromJson(Map json) => DataIf() ..condition = json['condition'] as String? ..type = json['type'] as String? @@ -64,6 +77,20 @@ Map _$DataIfToJson(DataIf instance) => { 'on-false': instance.on_false, }; +DataContain _$DataContainFromJson(Map json) => DataContain() + ..list = json['list'] + ..target = json['target'] as String + ..on_true = json['on-true'] as List? + ..on_false = json['on-false'] as List?; + +Map _$DataContainToJson(DataContain instance) => + { + 'list': instance.list, + 'target': instance.target, + 'on-true': instance.on_true, + 'on-false': instance.on_false, + }; + DataWhile _$DataWhileFromJson(Map json) => DataWhile() ..condition = json['condition'] as String? ..type = json['type'] as String? @@ -87,6 +114,20 @@ Map _$DataWhileToJson(DataWhile instance) => { 'on-do': instance.on_do, }; +DataForeach _$DataForeachFromJson(Map json) => DataForeach() + ..iterator = json['iterator'] as String + ..setKey = json['setKey'] + ..setValue = json['setValue'] + ..on_do = json['on-do'] as List?; + +Map _$DataForeachToJson(DataForeach instance) => + { + 'iterator': instance.iterator, + 'setKey': instance.setKey, + 'setValue': instance.setValue, + 'on-do': instance.on_do, + }; + DataSwitch _$DataSwitchFromJson(Map json) => DataSwitch() ..condition = json['condition'] as String? ..type = json['type'] as String? diff --git a/lib/oto/pipeline/pipeline.dart b/lib/oto/pipeline/pipeline.dart index 3d8b320..251c234 100644 --- a/lib/oto/pipeline/pipeline.dart +++ b/lib/oto/pipeline/pipeline.dart @@ -1,5 +1,8 @@ import 'package:dart_framework/utils/system_util.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_contain.dart'; import 'package:oto_cli/oto/pipeline/pipeline_exe.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_exe_handle.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_foreach.dart'; import 'package:oto_cli/oto/pipeline/pipeline_if.dart'; import 'package:oto_cli/oto/pipeline/pipeline_switch.dart'; import 'package:oto_cli/oto/pipeline/pipeline_wait_until.dart'; @@ -8,12 +11,16 @@ import 'package:oto_cli/oto/pipeline/pipeline_while.dart'; class Pipeline { static Map exeMap = { 'exe': () => PipelineExe(), + 'exe-handle': () => PipelineExeHandle(), 'async': () => PipelineAsync(), 'if': () => PipelineIf(), + 'contain': () => PipelineContain(), 'while': () => PipelineWhile(), + 'foreach': () => PipelineForeach(), 'wait-until-int': () => PipelineWaitUntil('int'), 'wait-until-double': () => PipelineWaitUntil('double'), 'wait-until-string': () => PipelineWaitUntil('string'), + 'wait-until-seconds': () => PipelineWaitUntilSeconds(), 'switch': () => PipelineSwitch(), }; diff --git a/lib/oto/pipeline/pipeline_condition.dart b/lib/oto/pipeline/pipeline_condition.dart index 4eede5b..4375f05 100644 --- a/lib/oto/pipeline/pipeline_condition.dart +++ b/lib/oto/pipeline/pipeline_condition.dart @@ -25,25 +25,16 @@ abstract class PipelineCondition extends PipelineExecutor { ' != ': (v0, v1, caster) => caster(v0) != caster(v1), }; typeCaster = { - 'int': (value) => (value == 'null' || value == null) ? null : int.parse(value) as int?, - 'float': (value) => (value == 'null' || value == null) ? null : double.parse(value) as double?, + 'int': (value) => (value == 'null' || value == null) ? null : (value is String) ? int.parse(value) as int : value, + 'float': (value) => (value == 'null' || value == null) ? null : (value is String) ? double.parse(value) as double? : value, 'string': (value) => (value == 'null' || value == null) ? null : value, - 'bool': (value) => (value == 'null' || value == null) ? null : (value.toLowerCase() == 'true') as bool?, + 'bool': (value) => (value == 'null' || value == null) ? null : (value is String) ? (value.toLowerCase() == 'true') as bool? : value, 'version': (value) => (value == 'null' || value == null) ? null : AppDataManager.to.versionToNumber(value) as double?, 'object': (value) => (value == 'null' || value == null) ? null : value, }; return PipelineValidateResult(); } - Future printCondition(String syntax, String condition, String postfix, - ConditionCheckResult result) async { - await CLI.println('[Pipeline-$syntax]', color: Color.magentaStrong); - print( - ' - Condition: $condition\n - Values: ${result.conditionValue}\n - Result: ${result.result} ===> $postfix'); - - return simpleFuture; - } - ConditionCheckResult checkCondition(String condition) { var result = ConditionCheckResult(); for (var item in conditions.entries) { diff --git a/lib/oto/pipeline/pipeline_contain.dart b/lib/oto/pipeline/pipeline_contain.dart new file mode 100644 index 0000000..d6c3b85 --- /dev/null +++ b/lib/oto/pipeline/pipeline_contain.dart @@ -0,0 +1,74 @@ +import 'package:dart_framework/utils/system_util.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/pipeline_data.dart'; +import 'package:oto_cli/oto/pipeline/pipeline.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_condition.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_exe.dart'; + +class PipelineContain extends PipelineExecutor { + late DataContain data; + late Pipeline? _pipelineTrue; + late Pipeline? _pipelineFalse; + + @override + PipelineValidateResult initialize(Map set) { + var result = PipelineValidateResult(); + var data = DataContain.fromJson(set.values.first); + var dataValidateResult = data.validate(); + if (!dataValidateResult.enable) { + return dataValidateResult; + } + + //set true task + var validateResult = PipelineExecutor.validateTasks(data.on_true); + if (!validateResult.enable) { + return validateResult; + } + _pipelineTrue = validateResult.pipeline; + + //set false task + validateResult = PipelineExecutor.validateTasks(data.on_false); + if (!validateResult.enable) { + return validateResult; + } + _pipelineFalse = validateResult.pipeline; + this.data = data; + + return result; + } + + @override + Future execute() async { + List list; + var listRaw = data.list; + if(listRaw is String) { + list = Command.replaceSingleTagValue(listRaw); + } else { + list = listRaw as List; + } + var result = ConditionCheckResult(); + var value = Command.replaceSingleTagValue(data.target); + value ??= data.target; + result.conditionValue = 'Contain in "$value".'; + result.result = list.contains(value); + await PipelineExecutor.printCondition('Contain', 'Contain in "${data.target}"', getPostfix(result.result), result); + if (result.result) { + await _pipelineTrue?.execute(); + } else { + await _pipelineFalse?.execute(); + } + return simpleFuture; + } + + String getPostfix(bool condition) { + if (condition) { + return _pipelineTrue == null + ? 'on-true not exist. Passed' + : 'Execute: on-true '; + } else { + return _pipelineFalse == null + ? 'on-false not exist. Passed' + : 'Execute: on-false '; + } + } +} diff --git a/lib/oto/pipeline/pipeline_exe.dart b/lib/oto/pipeline/pipeline_exe.dart index d9d6a2b..d3066c9 100644 --- a/lib/oto/pipeline/pipeline_exe.dart +++ b/lib/oto/pipeline/pipeline_exe.dart @@ -4,6 +4,7 @@ import 'package:oto_cli/oto/application.dart'; import 'package:oto_cli/oto/commands/command.dart'; import 'package:oto_cli/oto/data/command_data.dart'; import 'package:oto_cli/oto/pipeline/pipeline.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_condition.dart'; abstract class PipelineExecutor { //set & validate data @@ -17,6 +18,15 @@ abstract class PipelineExecutor { } return result; } + + static Future printCondition(String syntax, String condition, String postfix, + ConditionCheckResult result) async { + await CLI.println('[Pipeline-$syntax]', color: Color.magentaStrong); + print( + ' - Condition: $condition\n - Values: ${result.conditionValue}\n - Result: ${result.result} ===> $postfix'); + + return simpleFuture; + } } class PipelineExe extends PipelineExecutor { @@ -57,7 +67,9 @@ class PipelineExe extends PipelineExecutor { // print('==================> [$time] Execute: $targetCommandID'); updateState(CommandState.progress); var data = await commandData; - await Command.byType(data.command).execute(data); + var command = Command.byType(data.command); + command.id = commandID; + await command.execute(data); updateState(CommandState.complete); return simpleFuture; } diff --git a/lib/oto/pipeline/pipeline_exe_handle.dart b/lib/oto/pipeline/pipeline_exe_handle.dart new file mode 100644 index 0000000..cb14441 --- /dev/null +++ b/lib/oto/pipeline/pipeline_exe_handle.dart @@ -0,0 +1,85 @@ +import 'package:dart_framework/utils/system_util.dart'; +import 'package:oto_cli/cli/cli.dart'; +import 'package:oto_cli/oto/application.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/command_data.dart'; +import 'package:oto_cli/oto/data/pipeline_data.dart'; +import 'package:oto_cli/oto/pipeline/pipeline.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_exe.dart'; + +class ExeHandleData { + late Pipeline? pipelineSuccess; + late Pipeline? pipelineFail; +} + +class PipelineExeHandle extends PipelineExecutor { + late DataExeHandle data; + late String commandID; + late ExeHandleData handleData; + + @override + PipelineValidateResult initialize(Map set) { + var result = PipelineValidateResult(); + if(set.values.first == null) + { + result.enable = false; + result.message = 'Yaml Syntex is not valid in "exe-handle"'; + return result; + } + var data = DataExeHandle.fromJson(set.values.first); + var dataValidateResult = data.validate(); + if (!dataValidateResult.enable) { + return dataValidateResult; + } + + commandID = data.id; + if (!Application.instance.dataCommandMap.containsKey(commandID)) { + result.enable = false; + result.message = + 'The "$commandID" command does not exist in the command list.'; + } + updateState(CommandState.ready); + + handleData = ExeHandleData(); + //set success task + var validateResult = PipelineExecutor.validateTasks(data.on_success); + if (!validateResult.enable) { + return validateResult; + } + handleData.pipelineSuccess = validateResult.pipeline; + + //set fail task + validateResult = PipelineExecutor.validateTasks(data.on_fail); + if (!validateResult.enable) { + return validateResult; + } + handleData.pipelineFail = validateResult.pipeline; + this.data = data; + + return result; + } + + Future get commandData async { + var commandID = data.id; + var commandData = Application.instance.dataCommandMap[commandID]!; + await Application.instance.printBuildStep( + 'Phase Start: ${commandData.name} ($commandID)', + Color.green); + return dataFutrue(commandData); + } + + @override + Future execute() async { + updateState(CommandState.progress); + var data = await commandData; + var command = Command.byType(data.command); + command.id = commandID; + await command.executeHandle(data, handleData); + updateState(CommandState.complete); + return simpleFuture; + } + + void updateState(CommandState state) { + Application.instance.updateCommandState(commandID, state); + } +} \ No newline at end of file diff --git a/lib/oto/pipeline/pipeline_foreach.dart b/lib/oto/pipeline/pipeline_foreach.dart new file mode 100644 index 0000000..6957f2c --- /dev/null +++ b/lib/oto/pipeline/pipeline_foreach.dart @@ -0,0 +1,67 @@ +import 'package:dart_framework/utils/system_util.dart'; +import 'package:oto_cli/cli/cli.dart'; +import 'package:oto_cli/oto/commands/command.dart'; +import 'package:oto_cli/oto/data/pipeline_data.dart'; +import 'package:oto_cli/oto/pipeline/pipeline.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_exe.dart'; + +class PipelineForeach extends PipelineExecutor { + late Pipeline? _pipelineOnDo; + late DataForeach data; + + @override + PipelineValidateResult initialize(Map set) { + data = DataForeach.fromJson(set.values.first); + var dataValidateResult = data.validate(); + if (!dataValidateResult.enable) { + return dataValidateResult; + } + + //set do task + var validateResult = PipelineExecutor.validateTasks(data.on_do); + if (!validateResult.enable) { + return validateResult; + } + _pipelineOnDo = validateResult.pipeline; + + return PipelineValidateResult(); + } + + @override + Future execute() async { + var iterator = Command.replaceTagValue(data.iterator); + var iteratorType = ''; + if(iterator != null) + { + if(iterator is List) + { + iteratorType = 'List'; + var elementTag = data.setValue; + for(var item in iterator) + { + await Command.setPropertyValue(elementTag, item); + await _pipelineOnDo?.execute(); + } + } + + if(iterator is Map) + { + iteratorType = 'Map'; + var keyTag = data.setKey; + var elementTag = data.setValue; + for(var pair in iterator.entries) + { + if(keyTag != null) + { + await Command.setPropertyValue(keyTag, pair.key); + } + await Command.setPropertyValue(elementTag, pair.value); + await _pipelineOnDo?.execute(); + } + } + await CLI.println('[Pipeline-Foreach ($iteratorType)]', color: Color.magentaStrong); + print(' - Foreach complete. Loop out'); + } + return simpleFuture; + } +} diff --git a/lib/oto/pipeline/pipeline_if.dart b/lib/oto/pipeline/pipeline_if.dart index 022bc43..38a0b56 100644 --- a/lib/oto/pipeline/pipeline_if.dart +++ b/lib/oto/pipeline/pipeline_if.dart @@ -39,7 +39,7 @@ class PipelineIf extends PipelineCondition { Future execute() async { var condition = data.condition!; var result = checkCondition(condition); - await printCondition('IF', condition, getPostfix(result.result), result); + await PipelineExecutor.printCondition('IF', condition, getPostfix(result.result), result); if (result.result) { await _pipelineTrue?.execute(); } else { diff --git a/lib/oto/pipeline/pipeline_switch.dart b/lib/oto/pipeline/pipeline_switch.dart index 11da571..44c876e 100644 --- a/lib/oto/pipeline/pipeline_switch.dart +++ b/lib/oto/pipeline/pipeline_switch.dart @@ -32,7 +32,7 @@ class PipelineSwitch extends PipelineCondition { executed = true; var validateResult = PipelineExecutor.validateTasks(item.tasks); _pipeline = validateResult.pipeline; - await printCondition('Switch', data.condition!, 'Start task', result); + await PipelineExecutor.printCondition('Switch', data.condition!, 'Start task', result); await _pipeline?.execute(); break; } @@ -41,7 +41,7 @@ class PipelineSwitch extends PipelineCondition { var result = ConditionCheckResult(); result.conditionValue = 'null'; result.result = false; - await printCondition( + await PipelineExecutor.printCondition( 'Switch', data.condition!, 'not exist Same condition', result); } return simpleFuture; diff --git a/lib/oto/pipeline/pipeline_wait_until.dart b/lib/oto/pipeline/pipeline_wait_until.dart index c5aedc1..eff7bf4 100644 --- a/lib/oto/pipeline/pipeline_wait_until.dart +++ b/lib/oto/pipeline/pipeline_wait_until.dart @@ -2,6 +2,7 @@ import 'package:dart_framework/utils/system_util.dart'; import 'package:oto_cli/oto/data/pipeline_data.dart'; import 'package:oto_cli/oto/pipeline/pipeline.dart'; import 'package:oto_cli/oto/pipeline/pipeline_condition.dart'; +import 'package:oto_cli/oto/pipeline/pipeline_exe.dart'; class PipelineWaitUntil extends PipelineCondition { PipelineWaitUntil(String type) { @@ -19,12 +20,38 @@ class PipelineWaitUntil extends PipelineCondition { Future execute() async { var condition = data.condition!; var result = checkCondition(condition); - await printCondition('Wait-Until', condition, 'Start wait.', result); + await PipelineExecutor.printCondition('Wait-Until', condition, 'Start wait.', result); while (result.result) { - await Future.delayed(const Duration(milliseconds: 500)); + await Future.delayed(const Duration(milliseconds: 200)); result = checkCondition(data.condition!); } - await printCondition('Wait-Until', condition, 'Loop escape.', result); + await PipelineExecutor.printCondition('Wait-Until', condition, 'Loop escape.', result); + return simpleFuture; + } +} + +class PipelineWaitUntilSeconds extends PipelineExecutor { + PipelineWaitUntilSeconds(); + + late int milliseconds; + + @override + PipelineValidateResult initialize(Map set) { + var value = set.values.first.toString(); + var seconds = double.tryParse(value); + if (seconds == null) { + var result = PipelineValidateResult(); + result.message = 'Failed to cast as double value: "$value"'; + result.enable = false; + return result; + } + milliseconds = (seconds * 1000).round(); + return PipelineValidateResult(); + } + + @override + Future execute() async { + await Future.delayed(Duration(milliseconds: milliseconds)); return simpleFuture; } } diff --git a/lib/oto/pipeline/pipeline_while.dart b/lib/oto/pipeline/pipeline_while.dart index 8d75093..8a9e13b 100644 --- a/lib/oto/pipeline/pipeline_while.dart +++ b/lib/oto/pipeline/pipeline_while.dart @@ -32,11 +32,11 @@ class PipelineWhile extends PipelineCondition { var condition = data.condition!; var result = checkCondition(condition); while (result.result) { - await printCondition('While', condition, 'Execute: on-do', result); + await PipelineExecutor.printCondition('While', condition, 'Execute: on-do', result); await _pipelineOnDo?.execute(); result = checkCondition(data.condition!); } - await printCondition('While', condition, 'Loop escaped.', result); + await PipelineExecutor.printCondition('While', condition, 'Loop escaped.', result); return simpleFuture; } } diff --git a/pubspec.yaml b/pubspec.yaml index 99a8bc2..009d371 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,22 +10,22 @@ environment: # Add regular dependencies here. dependencies: # path: ^1.8.0 - json_annotation: ^4.8.0 + json_annotation: ^4.8.1 resource_importer: ^0.2.0 dart_framework: - # path: '../dart_framework' + # path: ../dart_framework git: - url: toki@toki-labs.com:/Volumes/Data2/git/dart_framework.git - ref: master + url: git@github.com:virtualoffice-meta-dev/dart_framework.git + ref: main color: ^3.0.0 + file_hasher: ^0.1.0+0 dev_dependencies: - lints: ^3.0.0 + lints: ^4.0.0 test: ^1.24.9 build_runner: ^2.1.4 json_serializable: ^6.0.1 - resource_importer: resources: silentbatch: assets/bin/silentbatch.exe \ No newline at end of file