flow-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24aa1cf518f2148d862cc0b5607e18471f5494e2
4
+ data.tar.gz: ff58cc71bb78b8ec63c7aa5c8dff647385f1c405
5
+ SHA512:
6
+ metadata.gz: 9942e1cb0598a931c901eb5bdbfd6775e278d1b6b49bf74959ad2968e237e8045868cd9176f51be82c80473060d58f4e401de4b9d6abe0a30f39a7b2546f76d9
7
+ data.tar.gz: c6a5595d4ec972caedd40ffd63456814ee9aa8bc0746225283528598e0794c28e8311954488f61e609cfdb4d4fc9c3a130a4ed4eeef24327aa5b1f589ec0ef7c
data/.flow.yml ADDED
@@ -0,0 +1,21 @@
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"
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.tag*
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+ .byebug_history*
15
+
16
+ test.xcodeproj
17
+ test.xcworkspace
18
+ test.gradle
19
+ flow-cli-*.gem
20
+ flow.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at atpking@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flow-cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 atpking
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Flow::Cli
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flow/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'flow-cli'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install flow-cli
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/flow-cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "flow/cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/flow-cli ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/flow/cli'
4
+
5
+ Flow::Cli::CmdManager.start(ARGV)
data/flow-cli.gemspec ADDED
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'flow/cli/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "flow-cli"
9
+ spec.version = Flow::Cli::VERSION
10
+ spec.authors = ["atpking"]
11
+ spec.email = ["atpking@gmail.com"]
12
+
13
+ spec.summary = "Flow CI CLI"
14
+ spec.description = "Flow CI CLI, used to build yaml, run ci yaml locally."
15
+ spec.homepage = "https://flow.ci"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.post_install_message = %q(
26
+ _____ _ _____ ______ ___ ____ _ ___
27
+ | ___| | / _ \ \ / / ___|_ _| / ___| | |_ _|
28
+ | |_ | | | | | \ \ /\ / / | | | | | | | | |
29
+ | _| | |__| |_| |\ V V /| |___ | | | |___| |___ | |
30
+ |_| |_____\___/ \_/\_/(_)____|___| \____|_____|___|
31
+
32
+ ****************************************************
33
+ 这是 flow.ci CLI 的早期版本,暂时只支持 ios 项目
34
+
35
+ )
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.14"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency "simplecov"
41
+ spec.add_development_dependency "rubocop"
42
+ spec.add_development_dependency "byebug"
43
+
44
+ spec.add_dependency "thor", ">= 0.15"
45
+ spec.add_dependency "tty", ">= 0.7"
46
+ spec.add_dependency "fastlane", ">= 2.28"
47
+ end
@@ -0,0 +1,103 @@
1
+ require 'yaml'
2
+ require 'tty'
3
+ require 'thor'
4
+
5
+ module Flow::Cli
6
+ class CmdManager < Thor
7
+ def initialize(*args)
8
+ super(*args)
9
+ @prompt = TTY::Prompt.new
10
+ @pastel = Pastel.new
11
+ @error = @pastel.red.bold.detach
12
+ @warning = @pastel.yellow.detach
13
+ end
14
+
15
+ desc "build_yaml_file", "build flow ci project yaml"
16
+ def build_yaml_file
17
+ config = ProjectAnalytics.new.config
18
+ str = FlowYamlBuilder.new(config).build_yaml
19
+ raise YamlError, "存在 flow.yml, 删除后才能重新生成" if File.file?("flow.yml")
20
+ File.open("flow.yml", "wb") do |file|
21
+ file.write(str)
22
+ end
23
+ @warning.call "yaml created...\n#{str}"
24
+ end
25
+
26
+ desc "run_build_script", "run flow yml build script"
27
+ def run_build_script
28
+ show_build_script
29
+ try_run_yml_build_script
30
+ end
31
+
32
+ desc "show_build_script", "show flow yml build script"
33
+ def show_build_script
34
+ script = yml_build_script
35
+ puts @warning.call "This is the build script in yaml"
36
+ print_line
37
+ puts script
38
+ print_line
39
+ end
40
+
41
+ desc "version", "show flow cli version"
42
+ map ['v', '-v', '--version'] => :version
43
+ def version
44
+ puts VERSION
45
+ end
46
+
47
+ desc 'help', 'Describe available commands or one specific command (aliases: `h`).'
48
+ map Thor::HELP_MAPPINGS => :help
49
+ def help(command = nil, subcommand = false)
50
+ print_line
51
+ puts @error.call("VERSION ALPHA\n Support IOS project ONLY, temporarily.")
52
+ print_line
53
+ super
54
+ end
55
+
56
+ no_commands do
57
+ def select_yml_steps(step_name)
58
+ raise YamlError, "Can not found flow.yml" unless File.file?("flow.yml")
59
+ dict = YAML.safe_load(File.read("flow.yml"))
60
+
61
+ the_steps = []
62
+ dict["flows"].map do |flow|
63
+ filtered_steps = flow["steps"].select { |step| step["name"] == step_name }
64
+ the_steps += filtered_steps
65
+ end
66
+ the_steps
67
+ end
68
+
69
+ def get_scripts(steps)
70
+ scripts = []
71
+ steps.each do |step|
72
+ next if step["scripts"].nil?
73
+ scripts += step["scripts"]
74
+ end
75
+ scripts
76
+ end
77
+
78
+ def run_script(script)
79
+ cmd = TTY::Command.new
80
+ cmd.run(script)
81
+ end
82
+
83
+ def yml_build_script
84
+ if File.file?("flow.yml") == false
85
+ return unless @prompt.yes?('no flow.yml found, need to build . y/n')
86
+ build_yaml_file
87
+ end
88
+ scripts = get_scripts(select_yml_steps("build"))
89
+ scripts.first if scripts.count > 0
90
+ end
91
+
92
+ def try_run_yml_build_script
93
+ run_script(yml_build_script)
94
+ end
95
+
96
+ private
97
+
98
+ def print_line
99
+ puts "*" * 30
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,13 @@
1
+ module Flow::Cli
2
+ class BaseException < StandardError
3
+ end
4
+
5
+ class ConflictPlatformError < BaseException
6
+ end
7
+
8
+ class YamlError < BaseException
9
+ end
10
+
11
+ class ParamsError < BaseException
12
+ end
13
+ end
@@ -0,0 +1,70 @@
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[:gym_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
@@ -0,0 +1,42 @@
1
+ require 'fastlane'
2
+ require 'gym'
3
+
4
+ module Flow::Cli
5
+ class IosBuildStepGenerator
6
+ attr_accessor :config
7
+ attr_accessor :debug
8
+ def initialize(default_config = nil)
9
+ if default_config.nil? && 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
+ default_config = config.select { |k, _v| allowed_params.include? k }
16
+ else
17
+ default_config = {}
18
+ end
19
+
20
+ self.config = default_config
21
+ end
22
+
23
+ def generate_gym_script(category = 'ad-hoc', force = false)
24
+ set_export_params(category, force)
25
+ "fastlane gym build #{build_gym_params}"
26
+ end
27
+
28
+ # 返回 由 gym 调用的 core 的生成的相关参数
29
+ def set_export_params(category = 'ad-hoc', force = false)
30
+ raise ParamsError, "#{category} not exists" unless %w[app-store ad-hoc package enterprise development
31
+ developer-id].include? category
32
+ return config if config[:export_method] && force == false
33
+
34
+ config[:export_method] = category
35
+ config
36
+ end
37
+
38
+ def build_gym_params
39
+ config.map { |k, v| "--#{k} #{v}" }.join(' ')
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ require_relative './ios_build_step_generator'
2
+
3
+ module Flow::Cli
4
+ class ProjectAnalytics
5
+ attr_accessor :config
6
+ def initialize(config = {})
7
+ # 要 env
8
+ config[:flow_language] = language
9
+ self.config = config
10
+ end
11
+
12
+ def language
13
+ case platform
14
+ when "ios"
15
+ "objc"
16
+ when "android"
17
+ "android"
18
+ end
19
+ end
20
+
21
+ def platform
22
+ raise ConflictPlatformError, "conflict platforms" if ios? && android?
23
+ return "ios" if ios?
24
+ return "android" if android?
25
+ raise ConflictPlatformError, "conflict, unknown platform"
26
+ end
27
+
28
+ private
29
+
30
+ def ios?
31
+ (Dir["#{base_path}*.xcodeproj"] + Dir["#{base_path}*.xcworkspace"]).count > 0
32
+ end
33
+
34
+ def android?
35
+ Dir["#{base_path}*.gradle"].count > 0
36
+ end
37
+
38
+ def base_path
39
+ return './' if config.nil?
40
+ config[:workspace] || './'
41
+ end
42
+ end
43
+ end
@@ -0,0 +1 @@
1
+ require_relative './hash'
@@ -0,0 +1,170 @@
1
+ class Hash
2
+ # Returns a new hash with all keys converted using the +block+ operation.
3
+ #
4
+ # hash = { name: 'Rob', age: '28' }
5
+ #
6
+ # hash.transform_keys { |key| key.to_s.upcase } # => {"NAME"=>"Rob", "AGE"=>"28"}
7
+ #
8
+ # If you do not provide a +block+, it will return an Enumerator
9
+ # for chaining with other methods:
10
+ #
11
+ # hash.transform_keys.with_index { |k, i| [k, i].join } # => {"name0"=>"Rob", "age1"=>"28"}
12
+ def transform_keys
13
+ return enum_for(:transform_keys) { size } unless block_given?
14
+ result = {}
15
+ each_key do |key|
16
+ result[yield(key)] = self[key]
17
+ end
18
+ result
19
+ end
20
+
21
+ # Destructively converts all keys using the +block+ operations.
22
+ # Same as +transform_keys+ but modifies +self+.
23
+ def transform_keys!
24
+ return enum_for(:transform_keys!) { size } unless block_given?
25
+ keys.each do |key|
26
+ self[yield(key)] = delete(key)
27
+ end
28
+ self
29
+ end
30
+
31
+ # Returns a new hash with all keys converted to strings.
32
+ #
33
+ # hash = { name: 'Rob', age: '28' }
34
+ #
35
+ # hash.stringify_keys
36
+ # # => {"name"=>"Rob", "age"=>"28"}
37
+ def stringify_keys
38
+ transform_keys(&:to_s)
39
+ end
40
+
41
+ # Destructively converts all keys to strings. Same as
42
+ # +stringify_keys+, but modifies +self+.
43
+ def stringify_keys!
44
+ transform_keys!(&:to_s)
45
+ end
46
+
47
+ # Returns a new hash with all keys converted to symbols, as long as
48
+ # they respond to +to_sym+.
49
+ #
50
+ # hash = { 'name' => 'Rob', 'age' => '28' }
51
+ #
52
+ # hash.symbolize_keys
53
+ # # => {:name=>"Rob", :age=>"28"}
54
+ def symbolize_keys
55
+ transform_keys { |key| key.to_sym rescue key }
56
+ end
57
+ alias_method :to_options, :symbolize_keys
58
+
59
+ # Destructively converts all keys to symbols, as long as they respond
60
+ # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
61
+ def symbolize_keys!
62
+ transform_keys! { |key| key.to_sym rescue key }
63
+ end
64
+ alias_method :to_options!, :symbolize_keys!
65
+
66
+ # Validates all keys in a hash match <tt>*valid_keys</tt>, raising
67
+ # +ArgumentError+ on a mismatch.
68
+ #
69
+ # Note that keys are treated differently than HashWithIndifferentAccess,
70
+ # meaning that string and symbol keys will not match.
71
+ #
72
+ # { name: 'Rob', years: '28' }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age"
73
+ # { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age') # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'"
74
+ # { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
75
+ def assert_valid_keys(*valid_keys)
76
+ valid_keys.flatten!
77
+ each_key do |k|
78
+ unless valid_keys.include?(k)
79
+ raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}")
80
+ end
81
+ end
82
+ end
83
+
84
+ # Returns a new hash with all keys converted by the block operation.
85
+ # This includes the keys from the root hash and from all
86
+ # nested hashes and arrays.
87
+ #
88
+ # hash = { person: { name: 'Rob', age: '28' } }
89
+ #
90
+ # hash.deep_transform_keys{ |key| key.to_s.upcase }
91
+ # # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
92
+ def deep_transform_keys(&block)
93
+ _deep_transform_keys_in_object(self, &block)
94
+ end
95
+
96
+ # Destructively converts all keys by using the block operation.
97
+ # This includes the keys from the root hash and from all
98
+ # nested hashes and arrays.
99
+ def deep_transform_keys!(&block)
100
+ _deep_transform_keys_in_object!(self, &block)
101
+ end
102
+
103
+ # Returns a new hash with all keys converted to strings.
104
+ # This includes the keys from the root hash and from all
105
+ # nested hashes and arrays.
106
+ #
107
+ # hash = { person: { name: 'Rob', age: '28' } }
108
+ #
109
+ # hash.deep_stringify_keys
110
+ # # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
111
+ def deep_stringify_keys
112
+ deep_transform_keys(&:to_s)
113
+ end
114
+
115
+ # Destructively converts all keys to strings.
116
+ # This includes the keys from the root hash and from all
117
+ # nested hashes and arrays.
118
+ def deep_stringify_keys!
119
+ deep_transform_keys!(&:to_s)
120
+ end
121
+
122
+ # Returns a new hash with all keys converted to symbols, as long as
123
+ # they respond to +to_sym+. This includes the keys from the root hash
124
+ # and from all nested hashes and arrays.
125
+ #
126
+ # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
127
+ #
128
+ # hash.deep_symbolize_keys
129
+ # # => {:person=>{:name=>"Rob", :age=>"28"}}
130
+ def deep_symbolize_keys
131
+ deep_transform_keys { |key| key.to_sym rescue key }
132
+ end
133
+
134
+ # Destructively converts all keys to symbols, as long as they respond
135
+ # to +to_sym+. This includes the keys from the root hash and from all
136
+ # nested hashes and arrays.
137
+ def deep_symbolize_keys!
138
+ deep_transform_keys! { |key| key.to_sym rescue key }
139
+ end
140
+
141
+ private
142
+ # support methods for deep transforming nested hashes and arrays
143
+ def _deep_transform_keys_in_object(object, &block)
144
+ case object
145
+ when Hash
146
+ object.each_with_object({}) do |(key, value), result|
147
+ result[yield(key)] = _deep_transform_keys_in_object(value, &block)
148
+ end
149
+ when Array
150
+ object.map { |e| _deep_transform_keys_in_object(e, &block) }
151
+ else
152
+ object
153
+ end
154
+ end
155
+
156
+ def _deep_transform_keys_in_object!(object, &block)
157
+ case object
158
+ when Hash
159
+ object.keys.each do |key|
160
+ value = object.delete(key)
161
+ object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
162
+ end
163
+ object
164
+ when Array
165
+ object.map! { |e| _deep_transform_keys_in_object!(e, &block) }
166
+ else
167
+ object
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,5 @@
1
+ module Flow
2
+ module Cli
3
+ VERSION = "0.0.1".freeze
4
+ end
5
+ end
data/lib/flow/cli.rb ADDED
@@ -0,0 +1,13 @@
1
+ require_relative "./cli/version"
2
+ require_relative "./cli/vendors/all"
3
+ require_relative "./cli/exception"
4
+ require_relative "./cli/project_analytics"
5
+ require_relative "./cli/flow_yaml_builder"
6
+ require_relative "./cli/ios_build_step_generator"
7
+ require_relative './cli/cmd_manager'
8
+
9
+ module Flow
10
+ module Cli
11
+ # Your code goes here...
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flow-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - atpking
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0.15'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0.15'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tty
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0.7'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fastlane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '2.28'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '2.28'
139
+ description: Flow CI CLI, used to build yaml, run ci yaml locally.
140
+ email:
141
+ - atpking@gmail.com
142
+ executables:
143
+ - flow-cli
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".flow.yml"
148
+ - ".gitignore"
149
+ - ".rspec"
150
+ - ".travis.yml"
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - exe/flow-cli
159
+ - flow-cli.gemspec
160
+ - lib/flow/cli.rb
161
+ - lib/flow/cli/cmd_manager.rb
162
+ - lib/flow/cli/exception.rb
163
+ - lib/flow/cli/flow_yaml_builder.rb
164
+ - lib/flow/cli/ios_build_step_generator.rb
165
+ - lib/flow/cli/project_analytics.rb
166
+ - lib/flow/cli/vendors/all.rb
167
+ - lib/flow/cli/vendors/hash.rb
168
+ - lib/flow/cli/version.rb
169
+ homepage: https://flow.ci
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message: "\n _____ _ _____ ______ ___ ____ _ ___\n
174
+ | ___| | / _ \\ \\ / / ___|_ _| / ___| | |_ _|\n | |_ | | | | | \\
175
+ \\ /\\ / / | | | | | | | | |\n | _| | |__| |_| |\\ V V /| |___ | | |
176
+ |___| |___ | |\n |_| |_____\\___/ \\_/\\_/(_)____|___| \\____|_____|___|\n\n
177
+ ****************************************************\n 这是 flow.ci CLI 的早期版本,暂时只支持
178
+ ios 项目\n\n "
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.10
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Flow CI CLI
198
+ test_files: []