Sha256: 34648609dd3afdce528f4f08a337907870843308525e8a9e62cb15dd85b38e6f

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require 'yaml'
module Flow::Cli
  class FlowYamlBuilder
    attr_accessor :flow_cli_config
    def initialize(flow_cli_config = {})
      self.flow_cli_config = flow_cli_config
    end

    def build_yaml
      build_yaml_hash.deep_stringify_keys.to_yaml
    end

    def build_yaml_hash
      yaml_hash = {
        env: ["FLOW_YAML_FROM=flow-cli"],
        flows: [create_default_flow_dict]
      }
      yaml_hash
    end

    def create_default_flow_dict
      flow = {}

      flow[:name] = flow_cli_config[:flow_name] || 'default_flow_by_cli'
      flow[:language] = flow_cli_config[:language]

      flow[:env] = flow_cli_config[:env]
      flow[:trigger] = {
        push: %w[develop master]
      }
      flow[:steps] = generate_steps
      flow
    end

    def generate_steps
      steps = []
      generate_normal_steps.each { |step| steps << step }
      steps << generate_custom_build_step
    end

    # 创建一些标准的steps
    def generate_normal_steps
      steps = []
      steps << generate_step_dict("init", name: "#{flow_cli_config[:flow_language]}_init")
      steps << generate_step_dict("git")

      steps
    end

    # 生成编译脚本
    def generate_custom_build_step
      script = IosBuildStepGenerator.new(flow_cli_config).generate_gym_script
      {
        name: "build",
        scripts: [script]
      }
    end

    def generate_step_dict(name, plugin_config = nil)
      step_dict = {
        name: name,
        plugin: {
          name: name
        }
      }
      step_dict[:plugin].merge!(plugin_config) if plugin_config
      step_dict
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flow-cli-0.0.4 lib/flow/cli/flow_yaml_builder.rb
flow-cli-0.0.3 lib/flow/cli/flow_yaml_builder.rb
flow-cli-0.0.2 lib/flow/cli/flow_yaml_builder.rb