diff --git a/.vscode/launch.json b/.vscode/launch.json index 4e21231..15fe8fc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,6 +18,13 @@ "program": "./bin/main.dart", "args": ["install", "-h"] }, + { + "name": "exe test", + "request": "launch", + "type": "dart", + "program": "./bin/main.dart", + "args": ["exe", "-t"] + }, { "name": "exe win", "request": "launch", diff --git a/assets/pipeline-test.yaml b/assets/pipeline-test.yaml index 99d311e..215aa22 100644 --- a/assets/pipeline-test.yaml +++ b/assets/pipeline-test.yaml @@ -7,10 +7,10 @@ pipeline: workflow: - async: git - - exe: json-reader + # - exe: json-reader #동기식 실행, 해당 수행이 끝나야만 다음 스텝실행, command일경우 해당 id 기입 - - exe: appData + # - exe: appData #비동기식 실행, 해당 수행이 완료됨과 관계없이 실행하고 다음 스텝을 실행한다 # - exe: buildDart @@ -84,14 +84,14 @@ commands: to: ### Version 쓰기 -- command: CreateAppData - id: appData - param: - scm: Git - name: OTO - relativeAssetPath: assets/data - return-version: "" - return-hash: "" +# - command: CreateAppData +# id: appData +# param: +# scm: Git +# name: OTO +# relativeAssetPath: assets/data +# return-version: "" +# return-hash: "" ### 실행가능한 파일로 빌드 - command: BuildDart diff --git a/bin/main.dart b/bin/main.dart index 410973c..ee30636 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -1,3 +1,4 @@ +import 'package:dart_framework/utils/system_util.dart'; import 'package:oto_cli/cli/cli.dart'; import 'package:oto_cli/cli/commands/command_template.dart'; import 'package:oto_cli/cli/commands/command_install.dart'; @@ -5,6 +6,7 @@ import 'package:oto_cli/cli/commands/command_exe.dart'; import 'package:oto_cli/cli/commands/command_start.dart'; void main(List arguments) async { + initialize(); CLI.initialize('OTO', arguments, [ CommandTemplate(), CommandInstall(), diff --git a/lib/cli/cli.dart b/lib/cli/cli.dart index 91a9308..2f273e6 100644 --- a/lib/cli/cli.dart +++ b/lib/cli/cli.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'dart:math'; import 'package:dart_framework/utils/system_util.dart'; import 'package:oto_cli/cli/commands/command_base.dart'; @@ -201,8 +202,8 @@ abstract class Printer { var now = DateTime.now(); var time = '${now.hour}${now.minute}${now.second}${now.millisecond}${now.microsecond}'; - var tempFile = - File(path.join(Directory.systemTemp.path, 'temp_$time.$extension')); + var tempFile = File(path.join(Directory.systemTemp.path, + 'temp_${time}_${Random().nextInt(1000)}.$extension')); await tempFile.writeAsString(content); c.complete(tempFile); return c.future; diff --git a/lib/cli/commands/command_exe.dart b/lib/cli/commands/command_exe.dart index d08c1dd..7daa39e 100644 --- a/lib/cli/commands/command_exe.dart +++ b/lib/cli/commands/command_exe.dart @@ -1,13 +1,20 @@ +// ignore_for_file: avoid_init_to_null + import 'dart:async'; import 'dart:io'; import 'package:dart_framework/charset/euc_kr.dart'; +import 'package:dart_framework/data/isolate_data.dart'; +import 'package:dart_framework/platform/isolate_manager.dart'; import 'package:oto_cli/cli/cli.dart'; import 'package:oto_cli/cli/commands/command_base.dart'; import 'package:dart_framework/utils/system_util.dart'; import 'package:oto_cli/oto/application.dart'; class CommandExe extends CommandBase { + late IsolateHandler _handler; + bool _complete = false; + @override Map> get arguments => { '-j': ["Used when it's a Jenkins build."], @@ -18,15 +25,17 @@ class CommandExe extends CommandBase { String get name => 'exe'; @override - Future execute(List parameters) { + Future execute(List parameters) async { for (var i = 0; i < parameters.length; ++i) { var item = parameters[i]; if (item.startsWith('-j')) { - Application.instance.build(BuildType.jenkins); + _handler = IsolateManager.create(IsolateExe(BuildType.jenkins)); + await isComplete(); break; } if (item.startsWith('-t')) { - Application.instance.build(BuildType.test); + _handler = IsolateManager.create(IsolateExe(BuildType.test)); + await isComplete(); } if (item.startsWith('-f')) { var file = ''; @@ -35,24 +44,34 @@ class CommandExe extends CommandBase { } else { file = item.replaceFirst('-f', '').trimLeft(); } - startYaml(file); + await startYaml(file); break; } } return simpleFuture; } - void startYaml(String target) { + Future isComplete() async { + _handler.addListener('complete', (data) => _complete = true); + while (!_complete) { + await Future.delayed(const Duration(milliseconds: 200)); + } + } + + Future startYaml(String target) async { var file = File(target); if (file.existsSync()) { - Application.instance.build(BuildType.file, + _handler = IsolateManager.create(IsolateExe(BuildType.file, yamlContent: file.readAsStringSync( - encoding: Platform.isWindows ? eucKr : systemEncoding)); + encoding: Platform.isWindows ? eucKr : systemEncoding))); + IsolateManager.create(IsolateExe(BuildType.test)); + await isComplete(); } else { - CLI.print([ + await CLI.print([ CLI.style('There are no files in path "$target"', color: Color.red) ]); } + return simpleFuture; } @override @@ -60,3 +79,17 @@ class CommandExe extends CommandBase { return ':::: Read documents written in yaml to do process task.'; } } + +class IsolateExe extends IsolateBase { + final BuildType _buildType; + String? _yamleContent = null; + IsolateExe(this._buildType, {String? yamlContent}) { + _yamleContent = yamlContent; + } + + @override + void onReady(Object? initData) async { + await Application.instance.build(_buildType, yamlContent: _yamleContent); + send(IsoMessege('complete')); + } +} diff --git a/lib/oto/core/defined_data.dart b/lib/oto/core/defined_data.dart index 71baa56..403fdc1 100644 --- a/lib/oto/core/defined_data.dart +++ b/lib/oto/core/defined_data.dart @@ -28,17 +28,23 @@ class TestData { if (Platform.isMacOS) { yaml = ''' --- -common: +property: workspace: ${Directory.current.path} +pipeline: + id: main + workflow: + - exe: createApp + commands: - command: CreateAppData + id: createApp param: scm: Git name: OTO relativeAssetPath: assets/data - returnVersion: "" - returnHash: "" + return-version: "" + return-hash: "" #- command: BuildDart # param: @@ -147,17 +153,18 @@ commands: } else if (Platform.isWindows) { yaml = ''' --- -common: +property: workspace: ${Directory.current.path} commands: - command: CreateAppData + id: createApp param: scm: Git name: Build Manager relativeAssetPath: assets/data - returnVersion: "" - returnHash: "" + return-version: "" + return-hash: "" #- command: BuildDart # param: