flow-cli 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39618a37200754a1da9175cdc5b385f5c98db0c4
4
- data.tar.gz: 25601c88ee90747b4558c48b3e934df7beef8491
3
+ metadata.gz: bbcb5bcae47d4673d9db2c6ccde08c12254061c9
4
+ data.tar.gz: bb10fb044569cac4a529197a0f171f6ec134dac1
5
5
  SHA512:
6
- metadata.gz: 08aa0177b1bb2f3b327d39150458cd87e5e32779a82b4530f222e39d65bcae4dcc624b9c62cddccc3735dc4739e6529abd9efc6a5378979d7829ea6cac9985ad
7
- data.tar.gz: e82b9396481f479325eeb1085d52b8ffdf75f4147b8d39f631667725b6bc3c802fcc65f282fdd28108fd142f4176385441775dabd08d939cb6063299ab6bf8f5
6
+ metadata.gz: d673f1c6c05b792493422c6313175a1e2626a1fca5a7a10e1179ca036f76d82de1af38750344cbe8ed4321859059c1459431438d0bbef463dda979d31b3b99d8
7
+ data.tar.gz: e90a96a7b7d56d34f93a34954b879ae7a7a9dbbed500db6a859bbd3c4b3a25d3f783420d5a7496103085b848aa6319d15df722ef34307a130debb0f88b6a3875
data/.gitignore CHANGED
@@ -18,3 +18,5 @@ test.xcworkspace
18
18
  test.gradle
19
19
  flow-cli-*.gem
20
20
  flow.yml
21
+ .flow.yml
22
+ .vscode/
data/.reek ADDED
@@ -0,0 +1,5 @@
1
+ IrresponsibleModule:
2
+ enabled: false
3
+
4
+ UncommunicativeVariableName:
5
+ enabled: false
data/README.md CHANGED
@@ -22,7 +22,8 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ flow-cli --help # help
26
+ flow-cli remote # flow ci operations.
26
27
 
27
28
  ## Development
28
29
 
@@ -7,14 +7,11 @@ module Flow::Cli
7
7
  class CmdManager < Thor
8
8
  def initialize(*args)
9
9
  super(*args)
10
- @prompt = TTY::Prompt.new
11
- @pastel = Pastel.new
12
- @error = @pastel.red.bold.detach
13
- @warning = @pastel.yellow.detach
14
10
  @db_manager = Utils::DbManager
11
+ @cmd_helper = Utils::CmdHelper.instance
15
12
  end
16
13
 
17
- desc "remote ...ARGS", "manage flow ci"
14
+ desc "remote ...ARGS", "operations about flow ci."
18
15
  subcommand "remote", Commands::Remote
19
16
 
20
17
  desc "build_yaml_file", "build flow ci project yaml"
@@ -24,12 +21,12 @@ module Flow::Cli
24
21
  # TODO: 优化点,以后放到其他地方
25
22
  config[:gym_config] = ask_gym_build_options if config[:flow_language] == "objc" && ENV["FLOW_CLI_TEST"] != "TRUE"
26
23
 
27
- str = FlowYamlBuilder.new(config).build_yaml
24
+ str = YamlBuilders::FlowYamlBuilder.init_yaml_builder(config).build_yaml
28
25
  raise YamlError, "存在 #{FLOW_YML_NAME}, 删除后才能重新生成" if File.file?(FLOW_YML_NAME)
29
26
  File.open(FLOW_YML_NAME, "wb") do |file|
30
27
  file.write(str)
31
28
  end
32
- @warning.call "yaml created...\n#{str}"
29
+ @cmd_helper.puts_warning "yaml created...\n#{str}"
33
30
  end
34
31
 
35
32
  desc "run_build_script", "run flow yml build script"
@@ -41,7 +38,7 @@ module Flow::Cli
41
38
  desc "show_build_script", "show flow yml build script"
42
39
  def show_build_script
43
40
  script = yml_build_script
44
- puts @warning.call "This is the build script in yaml"
41
+ puts @cmd_helper.puts_warning "This is the build script in yaml"
45
42
  print_line
46
43
  puts script
47
44
  print_line
@@ -62,7 +59,7 @@ module Flow::Cli
62
59
  map Thor::HELP_MAPPINGS => :help
63
60
  def help(command = nil, subcommand = false)
64
61
  print_line
65
- puts @error.call("VERSION ALPHA\n Support IOS project ONLY, temporarily.")
62
+ puts @cmd_helper.puts_error("VERSION ALPHA\n Support IOS project ONLY, temporarily.")
66
63
  print_line
67
64
  super
68
65
  end
@@ -96,7 +93,7 @@ module Flow::Cli
96
93
 
97
94
  def yml_build_script
98
95
  if File.file?(FLOW_YML_NAME) == false
99
- return unless @prompt.yes?('no flow.yml found, need to build . y/n')
96
+ return unless @cmd_helper.yes?('no flow.yml found, need to build . y/n')
100
97
  build_yaml_file
101
98
  end
102
99
  scripts = get_scripts(select_yml_steps("build"))
@@ -115,8 +112,8 @@ module Flow::Cli
115
112
 
116
113
  def ask_gym_build_options
117
114
  user_gym_config = {}
118
- user_gym_config[:export_method] = @prompt.select("export_method? ", %w[development app-store ad-hoc package enterprise developer-id])
119
- user_gym_config[:silent] = "" if @prompt.yes?("less log?")
115
+ user_gym_config[:export_method] = @cmd_helper.select("export_method? ", %w[development app-store ad-hoc package enterprise developer-id])
116
+ user_gym_config[:silent] = "" if @cmd_helper.yes?("less log?")
120
117
 
121
118
  user_gym_config
122
119
  end
@@ -8,41 +8,63 @@ module Flow::Cli
8
8
  class Remote < Thor
9
9
  def initialize(*args, &proc)
10
10
  super(*args)
11
- @prompt = TTY::Prompt.new
12
- @pastel = Pastel.new
13
- @warning = @pastel.yellow.detach
14
- @error = @pastel.red.bold.detach
15
11
  @db_manager = Utils::DbManager
16
12
  @api_manager = Utils::FlowApiManager.load_from_db(&proc)
13
+ @cmd_helper = Utils::CmdHelper.instance
14
+ end
15
+
16
+ desc "help_ios_init", 'how to fetch provisions, p12 files'
17
+ def help_ios_init
18
+ @cmd_helper.echo_warning %(when you build ios project, you should upload p12 and provision to flow ci project
19
+ followed this website to build p12 and provision files
20
+ http://docs.flow.ci/en/upload_certificate_and_provisioning_profiles.html (EN)
21
+ http://docs.flow.ci/zh/upload_certificate_and_provisioning_profiles.html (中文)
22
+
23
+ finally,
24
+ run `flow-cli remote upload_p12 FILE` and `flow-cli remote upload_provision FILE` to upload the files.
25
+ )
17
26
  end
18
27
 
19
28
  desc "login", "bind flow ci account to flow cli."
20
29
  def login
21
- email = @prompt.ask("email?")
22
- password = @prompt.mask("password?")
30
+ email = @cmd_helper.ask("email?")
31
+ password = @cmd_helper.mask("password?")
23
32
  Utils::FlowApiManager.login(email, password)
24
- puts "login success"
33
+ @cmd_helper.echo_warning "you info saved to ~/.flow_cli_config.yml"
34
+ @cmd_helper.echo "login success..."
25
35
  end
26
36
 
37
+ option :branch, default: "master"
38
+ desc "run_manual_job", 'run manual job(default branch master) using --branch to specify branch'
39
+ def run_manual_job
40
+ choosed_project_check
41
+ answer = @api_manager.run_manual_job(
42
+ current_flow_id,
43
+ current_project_id,
44
+ options[:branch]
45
+ )
46
+ @cmd_helper.echo("job started. click ( cmd + click ) url to visit on browser")
47
+ @cmd_helper.echo("https://dashboard.flow.ci/projects/#{current_project_id}/jobs/#{answer[:id]}")
48
+ end
27
49
  desc "reset", "reset flow api info data"
28
50
  def reset
29
- @db_manager.overide_save({})
30
- puts "reset success..."
51
+ @db_manager.reset
52
+ @cmd_helper.echo_warning "reset ok"
31
53
  end
32
54
 
33
55
  desc "project_init", "set a project from flow ci to operation"
34
56
  def project_init
35
57
  projects = current_api_manager.fetch_projects
36
- begin
37
- file_origin = `git remote -v`.to_s.match("git.*.git").first
38
- rescue
39
- puts @warning.call "read git origin fail..."
40
- end
58
+ # begin
59
+ # file_origin = `git remote -v`.to_s.match("git.*.git").first
60
+ # rescue
61
+ # cmd_helper.echo_warning "read git origin fail..."
62
+ # end
41
63
 
42
64
  dict = {}
43
65
  dict = Hash[projects.map { |p| [p[:name].to_s, p[:id]] }]
44
66
 
45
- current_project_id = @prompt.select("Choose your project?", dict)
67
+ current_project_id = @cmd_helper.select("Choose your project?", dict)
46
68
 
47
69
  @db_manager.save_attribute(:current_project_id, current_project_id)
48
70
 
@@ -53,7 +75,7 @@ module Flow::Cli
53
75
  else
54
76
  dict = {}
55
77
  flows.each { |p| dict[(p[:name]).to_s] = p[:id] }
56
- @prompt.select("Choose your flow?", dict)
78
+ @cmd_helper.select("Choose your flow?", dict)
57
79
  end
58
80
  @db_manager.save_attribute(:current_flow_id, current_flow_id)
59
81
  puts "project_id = #{current_project_id}, flow_id = #{current_flow_id}. saved this info..."
@@ -68,45 +90,67 @@ module Flow::Cli
68
90
  api_p12s = current_api_manager.load_p12s(@db_manager.read_attribute(:current_flow_id))
69
91
  old_p12 = api_p12s.find { |p12| p12[:filename] == basename }
70
92
  unless old_p12.nil?
71
- if @prompt.yes? "found a same name file, override?"
93
+ if @cmd_helper.yes? "found a same name file, override?"
72
94
  current_api_manager.delete_p12(old_p12[:id], @db_manager.read_attribute(:current_flow_id))
73
95
  else
74
- return puts "canceled.."
96
+ return @cmd_helper.echo_warning "canceled..."
75
97
  end
76
98
  end
77
99
  current_api_manager.upload_p12(@db_manager.read_attribute(:current_flow_id), file_path, password)
78
- puts "uploaded."
100
+ puts "uploaded. you can run `flow-cli remote list_p12s` to check the operation."
79
101
  end
80
102
 
81
103
  desc "list_p12s", "list_p12s"
82
104
  def list_p12s
83
105
  choosed_project_check
84
- puts current_api_manager.load_p12s(@db_manager.read_attribute(:current_flow_id))
106
+ dict = current_api_manager.load_p12s(current_flow_id)
107
+ if dict.count.zero?
108
+ @cmd_helper.echo_warning("no p12 found in project #{current_project_id}")
109
+ else
110
+ @cmd_helper.puts_table(dict)
111
+ end
112
+ end
113
+
114
+ desc "fetch_latest_jobs", "fetch_latest_jobs"
115
+ def fetch_latest_jobs
116
+ choosed_project_check
117
+ list = @api_manager.fetch_latest_jobs(current_flow_id, current_project_id)
118
+ show_data = list.map do |item|
119
+ tmp = item.slice(:id, :status, :event_type, :number, :branch, :commit_log)
120
+ tmp[:created_at_str] = Time.at(item[:created_at]).to_s
121
+ tmp[:url] = "https://dashboard.flow.ci/projects/#{current_project_id}/jobs/#{tmp[:id]}"
122
+ tmp
123
+ end
124
+ @cmd_helper.puts_table(show_data, %i[number event_type branch status commit_log created_at_str url])
85
125
  end
86
126
 
87
- desc "upload_provision", "upload_provision"
127
+ desc "upload_provision FILE_PATH", "upload_provision"
88
128
  def upload_provision(file_path)
89
129
  choosed_project_check
90
130
  basename = File.basename file_path
91
- project_init unless @db_manager.read_attribute(:current_flow_id)
92
131
 
93
- api_provisions = current_api_manager.load_provisions(@db_manager.read_attribute(:current_flow_id))
132
+ api_provisions = current_api_manager.load_provisions(current_flow_id)
94
133
  old_provision = api_provisions.find { |provision| provision[:filename] == basename }
95
134
  unless old_provision.nil?
96
- if @prompt.yes? "found a same name file, override?"
97
- current_api_manager.delete_provision(old_provision[:id], @db_manager.read_attribute(:current_flow_id))
135
+ if @cmd_helper.yes? "found a same name file, override?"
136
+ current_api_manager.delete_provision(old_provision[:id], current_flow_id)
98
137
  else
99
138
  return puts "canceled.."
100
139
  end
101
140
  end
102
- current_api_manager.upload_provision(@db_manager.read_attribute(:current_flow_id), file_path)
103
- puts "uploaded."
141
+ current_api_manager.upload_provision(current_flow_id, file_path)
142
+ puts "uploaded. you can run `flow-cli remote list_provisions` to check the operation."
104
143
  end
105
144
 
106
145
  desc "list_provisions", "list provisions"
107
146
  def list_provisions
108
147
  choosed_project_check
109
- puts current_api_manager.load_provisions(@db_manager.read_attribute(:current_flow_id))
148
+ dict = current_api_manager.load_provisions(current_flow_id)
149
+ if dict.count.zero?
150
+ @cmd_helper.echo_warning("no p12 found in project #{current_project_id}")
151
+ else
152
+ @cmd_helper.puts_table(dict)
153
+ end
110
154
  end
111
155
 
112
156
  no_commands do
@@ -115,12 +159,20 @@ module Flow::Cli
115
159
  def current_api_manager
116
160
  return @current_api_manager unless @current_api_manager.nil?
117
161
  @api_manager.refresh_login do
118
- [@prompt.ask("email?"), @prompt.mask("password?")]
162
+ [@cmd_helper.ask("email?"), @cmd_helper.mask("password?")]
119
163
  end
120
164
  @current_api_manager = @api_manager
121
165
  @current_api_manager
122
166
  end
123
167
 
168
+ def current_project_id
169
+ @current_project_id ||= @db_manager.read_attribute(:current_project_id)
170
+ end
171
+
172
+ def current_flow_id
173
+ @current_flow_id ||= @db_manager.read_attribute(:current_flow_id)
174
+ end
175
+
124
176
  def choosed_project_check
125
177
  project_init if @db_manager.read_attribute(:current_project_id).nil?
126
178
  end
@@ -1,5 +1,3 @@
1
- require_relative './ios_build_step_generator'
2
-
3
1
  module Flow::Cli
4
2
  class ProjectAnalytics
5
3
  attr_accessor :config
@@ -1,4 +1,5 @@
1
1
  require_relative './local_service_rest'
2
2
  require_relative './flow_api_rest'
3
+ require_relative './cmd_helper'
3
4
  require_relative './db_manager'
4
5
  require_relative './api/flow_api_manager'
@@ -71,6 +71,16 @@ module Flow::Cli
71
71
  send_to_api(:get, "/flows/#{flow_id}", project_id: project_id)
72
72
  end
73
73
 
74
+ def fetch_latest_jobs(flow_id, project_id)
75
+ answer = send_to_api(:get, "/projects/#{project_id}/jobs", flow_id: flow_id)
76
+ answer[:list] || []
77
+ end
78
+
79
+ def run_manual_job(flow_id, project_id, branch)
80
+ send_to_api(:post, "/projects/#{project_id}/manual_hook", flow_id: flow_id, branch: branch)
81
+ end
82
+
83
+
74
84
  def send_to_api(action, url, params = {}, slice_items = nil, need_access_token = true)
75
85
  params[:access_token] = user_access_token if need_access_token
76
86
  params.compact!
@@ -0,0 +1,57 @@
1
+ require 'forwardable'
2
+ require 'byebug'
3
+
4
+ module Flow::Cli
5
+ module Utils
6
+ class CmdHelper
7
+ extend Forwardable
8
+ attr_accessor :prompt
9
+ def initialize
10
+ @pastel = Pastel.new
11
+ self.prompt = TTY::Prompt.new
12
+ end
13
+
14
+ def_delegators :prompt, :ask, :yes?, :mask, :select
15
+
16
+ def echo(log)
17
+ @green ||= @pastel.green.bold.detach
18
+ puts @green.call log
19
+ end
20
+
21
+ def puts_table(arr_dict, sorted_titles = nil)
22
+ sorted_titles = arr_dict.first.keys if sorted_titles.nil?
23
+ table = TTY::Table.new header: sorted_titles
24
+ arr_dict.each do |item|
25
+ show_item = []
26
+ sorted_titles.each do |key|
27
+ show_item << item[key]
28
+ end
29
+ table << show_item
30
+ end
31
+ puts table.render(:unicode)
32
+ end
33
+
34
+ def puts_error(log)
35
+ @error ||= @pastel.red.bold.detach
36
+ puts @error.call(log)
37
+ end
38
+
39
+ def puts_warning(log)
40
+ @warning ||= @pastel.yellow.detach
41
+ puts @warning.call(log)
42
+ end
43
+
44
+ alias error puts_error
45
+ alias echo_error puts_error
46
+ alias warning puts_warning
47
+ alias echo_warning puts_warning
48
+ alias warn puts_warning
49
+
50
+ class << self
51
+ def instance
52
+ new
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -13,6 +13,10 @@ module Flow::Cli
13
13
  hash
14
14
  end
15
15
 
16
+ def reset
17
+ overide_save({})
18
+ end
19
+
16
20
  def save(settings)
17
21
  old = read
18
22
  settings = old.merge(settings).compact.stringify_keys
@@ -1,5 +1,5 @@
1
1
  module Flow
2
2
  module Cli
3
- VERSION = "0.0.4".freeze
3
+ VERSION = "0.0.5".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ require_relative './flow_yaml_builder'
2
+ require_relative './ios_build_step_generator'
3
+ require_relative './ios_yaml_builder'
@@ -0,0 +1,81 @@
1
+ require 'yaml'
2
+ module Flow::Cli
3
+ module YamlBuilders
4
+ class FlowYamlBuilder
5
+ attr_accessor :flow_cli_config
6
+ def initialize(flow_cli_config = {})
7
+ self.flow_cli_config = flow_cli_config
8
+ end
9
+
10
+ def build_yaml
11
+ build_yaml_hash.deep_stringify_keys.to_yaml
12
+ end
13
+
14
+ def build_yaml_hash
15
+ yaml_hash = {
16
+ env: ["FLOW_YAML_FROM=flow-cli"],
17
+ flows: [create_default_flow_dict]
18
+ }
19
+ yaml_hash
20
+ end
21
+
22
+ def create_default_flow_dict
23
+ flow = {}
24
+ flow[:name] = flow_cli_config[:flow_name] || 'default_flow_by_cli'
25
+ flow[:language] = flow_cli_config[:flow_language]
26
+ flow[:version] = flow_cli_config[:flow_version]
27
+ flow[:env] = flow_cli_config[:env]
28
+ flow[:trigger] = {
29
+ push: %w[develop master]
30
+ }
31
+ flow[:steps] = generate_steps
32
+ flow
33
+ end
34
+
35
+ def generate_steps
36
+ steps = []
37
+ generate_normal_steps.each { |step| steps << step }
38
+ steps << generate_custom_build_step
39
+ end
40
+
41
+ # 创建一些标准的steps
42
+ def generate_normal_steps
43
+ steps = []
44
+ steps << generate_step_dict("init", name: "#{flow_cli_config[:flow_language]}_init")
45
+ steps << generate_step_dict("git")
46
+ steps << generate_step_dict("install", name: "#{flow_cli_config[:flow_language]}_init")
47
+ steps
48
+ end
49
+
50
+ # 生成编译脚本
51
+ def generate_custom_build_step
52
+ # script = IosBuildStepGenerator.new(flow_cli_config).generate_gym_script
53
+ # {
54
+ # name: "build",
55
+ # scripts: [script]
56
+ # }
57
+ end
58
+
59
+ def generate_step_dict(name, plugin_config = nil)
60
+ step_dict = {
61
+ name: name,
62
+ plugin: {
63
+ name: name
64
+ }
65
+ }
66
+ step_dict[:plugin].merge!(plugin_config) if plugin_config
67
+ step_dict
68
+ end
69
+
70
+ class << self
71
+ def init_yaml_builder(flow_cli_config)
72
+ if flow_cli_config[:flow_language] == "objc"
73
+ IosYamlBuilder.new(flow_cli_config)
74
+ else
75
+ new(flow_cli_config)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,39 @@
1
+ require 'fastlane'
2
+ require 'gym'
3
+
4
+ module Flow::Cli
5
+ module YamlBuilders
6
+ class IosBuildStepGenerator
7
+ attr_accessor :cli_config
8
+ def initialize(cli_config = {})
9
+ self.cli_config = cli_config
10
+ if ENV["FLOW_CLI_TEST"] != "TRUE"
11
+ Gym.config = FastlaneCore::Configuration.create(Gym::Options.available_options, {})
12
+ config = Gym.config.values(ask: false).reject { |_k, v| v.nil? }
13
+ allowed_params = %i[workspace project scheme clean output_name configuration
14
+ codesigning_identity include_symbols include_bitcode
15
+ export_method export_options export_xcargs]
16
+ @gym_config = config.select { |k, _v| allowed_params.include? k }
17
+ else
18
+ @gym_config = {}
19
+ end
20
+ end
21
+
22
+ def generate_gym_script
23
+ merge_user_cli_gym_config
24
+ "fastlane gym build #{build_gym_params}"
25
+ end
26
+
27
+ # 返回 由 gym 调用的 core 的生成的相关参数
28
+ def merge_user_cli_gym_config
29
+ user_gym_config = { export_method: 'ad-hoc' }.merge(cli_config[:gym_config] || {})
30
+ @gym_config.merge!(user_gym_config)
31
+ @gym_config
32
+ end
33
+
34
+ def build_gym_params
35
+ @gym_config.map { |k, v| "--#{k} #{v}".rstrip }.join(' ')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require_relative './flow_yaml_builder'
2
+ require_relative './ios_build_step_generator'
3
+ require 'yaml'
4
+ module Flow::Cli
5
+ module YamlBuilders
6
+ class IosYamlBuilder < FlowYamlBuilder
7
+ def initialize(cli_config = {})
8
+ super
9
+ cli_config[:flow_version] = "Xcode8"
10
+ end
11
+
12
+ def generate_custom_build_step
13
+ script = IosBuildStepGenerator.new(flow_cli_config).generate_gym_script
14
+ {
15
+ name: "build",
16
+ scripts: [script]
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/flow/cli.rb CHANGED
@@ -5,8 +5,7 @@ require_relative "./cli/utils/all"
5
5
  require_relative "./cli/exception"
6
6
 
7
7
  require_relative "./cli/project_analytics"
8
- require_relative "./cli/flow_yaml_builder"
9
- require_relative "./cli/ios_build_step_generator"
8
+ require_relative "./cli/yaml_builders/all"
10
9
  require_relative './cli/cmd_manager'
11
10
 
12
11
  module Flow
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flow-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - atpking
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-14 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -172,8 +172,8 @@ executables:
172
172
  extensions: []
173
173
  extra_rdoc_files: []
174
174
  files:
175
- - ".flow.yml"
176
175
  - ".gitignore"
176
+ - ".reek"
177
177
  - ".rspec"
178
178
  - ".travis.yml"
179
179
  - CODE_OF_CONDUCT.md
@@ -190,17 +190,20 @@ files:
190
190
  - lib/flow/cli/commands/remote.rb
191
191
  - lib/flow/cli/constant.rb
192
192
  - lib/flow/cli/exception.rb
193
- - lib/flow/cli/flow_yaml_builder.rb
194
- - lib/flow/cli/ios_build_step_generator.rb
195
193
  - lib/flow/cli/project_analytics.rb
196
194
  - lib/flow/cli/utils/all.rb
197
195
  - lib/flow/cli/utils/api/flow_api_manager.rb
196
+ - lib/flow/cli/utils/cmd_helper.rb
198
197
  - lib/flow/cli/utils/db_manager.rb
199
198
  - lib/flow/cli/utils/flow_api_rest.rb
200
199
  - lib/flow/cli/utils/local_service_rest.rb
201
200
  - lib/flow/cli/vendors/all.rb
202
201
  - lib/flow/cli/vendors/hash.rb
203
202
  - lib/flow/cli/version.rb
203
+ - lib/flow/cli/yaml_builders/all.rb
204
+ - lib/flow/cli/yaml_builders/flow_yaml_builder.rb
205
+ - lib/flow/cli/yaml_builders/ios_build_step_generator.rb
206
+ - lib/flow/cli/yaml_builders/ios_yaml_builder.rb
204
207
  homepage: https://flow.ci
205
208
  licenses:
206
209
  - MIT
data/.flow.yml DELETED
@@ -1,21 +0,0 @@
1
- ---
2
- env:
3
- - FLOW_YAML_FROM=flow-cli
4
- flows:
5
- - name: default_flow_by_cli
6
- language:
7
- env:
8
- trigger:
9
- push:
10
- - develop
11
- - master
12
- steps:
13
- - name: init
14
- plugin:
15
- name: _init
16
- - name: git
17
- plugin:
18
- name: git
19
- - name: build
20
- scripts:
21
- - echo "hello world"
@@ -1,70 +0,0 @@
1
- require 'yaml'
2
- module Flow::Cli
3
- class FlowYamlBuilder
4
- attr_accessor :flow_cli_config
5
- def initialize(flow_cli_config = {})
6
- self.flow_cli_config = flow_cli_config
7
- end
8
-
9
- def build_yaml
10
- build_yaml_hash.deep_stringify_keys.to_yaml
11
- end
12
-
13
- def build_yaml_hash
14
- yaml_hash = {
15
- env: ["FLOW_YAML_FROM=flow-cli"],
16
- flows: [create_default_flow_dict]
17
- }
18
- yaml_hash
19
- end
20
-
21
- def create_default_flow_dict
22
- flow = {}
23
-
24
- flow[:name] = flow_cli_config[:flow_name] || 'default_flow_by_cli'
25
- flow[:language] = flow_cli_config[:language]
26
-
27
- flow[:env] = flow_cli_config[:env]
28
- flow[:trigger] = {
29
- push: %w[develop master]
30
- }
31
- flow[:steps] = generate_steps
32
- flow
33
- end
34
-
35
- def generate_steps
36
- steps = []
37
- generate_normal_steps.each { |step| steps << step }
38
- steps << generate_custom_build_step
39
- end
40
-
41
- # 创建一些标准的steps
42
- def generate_normal_steps
43
- steps = []
44
- steps << generate_step_dict("init", name: "#{flow_cli_config[:flow_language]}_init")
45
- steps << generate_step_dict("git")
46
-
47
- steps
48
- end
49
-
50
- # 生成编译脚本
51
- def generate_custom_build_step
52
- script = IosBuildStepGenerator.new(flow_cli_config).generate_gym_script
53
- {
54
- name: "build",
55
- scripts: [script]
56
- }
57
- end
58
-
59
- def generate_step_dict(name, plugin_config = nil)
60
- step_dict = {
61
- name: name,
62
- plugin: {
63
- name: name
64
- }
65
- }
66
- step_dict[:plugin].merge!(plugin_config) if plugin_config
67
- step_dict
68
- end
69
- end
70
- end
@@ -1,37 +0,0 @@
1
- require 'fastlane'
2
- require 'gym'
3
-
4
- module Flow::Cli
5
- class IosBuildStepGenerator
6
- attr_accessor :cli_config
7
- def initialize(cli_config = {})
8
- self.cli_config = cli_config
9
- if ENV["FLOW_CLI_TEST"] != "TRUE"
10
- Gym.config = FastlaneCore::Configuration.create(Gym::Options.available_options, {})
11
- config = Gym.config.values(ask: false).reject { |_k, v| v.nil? }
12
- allowed_params = %i[workspace project scheme clean output_name configuration
13
- codesigning_identity include_symbols include_bitcode
14
- export_method export_options export_xcargs]
15
- @gym_config = config.select { |k, _v| allowed_params.include? k }
16
- else
17
- @gym_config = {}
18
- end
19
- end
20
-
21
- def generate_gym_script
22
- merge_user_cli_gym_config
23
- "fastlane gym build #{build_gym_params}"
24
- end
25
-
26
- # 返回 由 gym 调用的 core 的生成的相关参数
27
- def merge_user_cli_gym_config
28
- user_gym_config = { export_method: 'ad-hoc' }.merge(cli_config[:gym_config] || {} )
29
- @gym_config.merge!(user_gym_config)
30
- @gym_config
31
- end
32
-
33
- def build_gym_params
34
- @gym_config.map { |k, v| "--#{k} #{v}".rstrip }.join(' ')
35
- end
36
- end
37
- end