lib/cocoapods-flutter/command/flutter/archive.rb in cocoapods-flutter-dt-0.1.0 vs lib/cocoapods-flutter/command/flutter/archive.rb in cocoapods-flutter-dt-0.2.0

- old
+ new

@@ -18,11 +18,13 @@ ['--repo', 'podspec repo'], ['--sources', 'podspec sources'], ['--upgrade', 'pub upgrade'], ['--wrapper', 'Default is flutter'], ['--flutterversion', 'FlutterSDK version'], - ['--buildrun', 'run build-runner'] + ['--buildrun', 'run build-runner'], + ['--debug', 'debug mode'], + ['--release', 'release mode'], ].concat(Pod::Command::Repo::Push.options).concat(super).uniq end def initialize(argv) @module_name = argv.shift_argument @@ -50,24 +52,52 @@ versions << mid_v versions << last_v @version = versions.join "." end + + @build_modes = [] @pod_repo = argv.option('repo', 'master') @sources = argv.option('sources', 'https://github.com/CocoaPods/Specs.git').split(',') @flutter_wrapper = argv.option('wrapper', 'flutter') @pub_upgrade = argv.flag?('upgrade', true) - @flutter_version = argv.option('flutterversion', '1.12.13') + @flutter_version = argv.option('flutterversion', default_fluttter_version) @build_run = argv.flag?('buildrun', true) @working_dir = Dir.pwd + + if argv.flag?('debug', true) + @build_modes.append 'debug' + end + if argv.flag?('release', true) + @build_modes.append 'release' + end + super end def run - archiver = Archiver.new(@module_name, @version, @sources, @flutter_wrapper, @pub_upgrade, @flutter_version, @build_run, @working_dir,@pod_repo) + archiver = Archiver.new(@module_name, @version, @sources, @flutter_wrapper, @pub_upgrade, @flutter_version, @build_run, @working_dir,@pod_repo, @build_modes) archiver.archive end + def default_fluttter_version + flutter_version = '' + stdin, stdout_stderr, wait_thr = Open3.popen2e(@flutter_wrapper, '--version'); + stdout_stderr.each_line do |line| + if line.start_with?('Flutter ') + flutter_version = line.split(' • ').first.split(' ').last + end + end + exit_status = wait_thr.value + if exit_status.success? + puts stdout_stderr.gets + else + raise stdout_stderr.gets + end + stdout_stderr.close + stdin.close + flutter_version + end end end end end