Class: KCommercial::Resources::LibBundleGenerator

Inherits:
BundleGenerator show all
Defined in:
lib/KCommercialPipeline/core/resource/source/lib_bundle.rb

Instance Attribute Summary collapse

Attributes inherited from BundleGenerator

#bundle_name, #component_name, #resource_path

Instance Method Summary collapse

Methods inherited from BundleGenerator

#initialize

Constructor Details

This class inherits a constructor from KCommercial::Resources::BundleGenerator

Instance Attribute Details

#depotObject

Returns the value of attribute depot.



9
10
11
# File 'lib/KCommercialPipeline/core/resource/source/lib_bundle.rb', line 9

def depot
  @depot
end

Instance Method Details

#check_exist?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/KCommercialPipeline/core/resource/source/lib_bundle.rb', line 15

def check_exist?
  return !depot.materials_cache.component_for_name(@component_name).nil?
end

#copy_resource!Object

copy resource



38
39
40
41
42
43
44
45
46
47
# File 'lib/KCommercialPipeline/core/resource/source/lib_bundle.rb', line 38

def copy_resource!
  KCommercial::UI.debug("开始自动copy资源到#{@component_name}组件")
  bundle_path = "#{@depot.root_path}/#{@depot.configuration.components.origin_configurations[:search_paths].last}"
  target_dir = Pathname(bundle_path).join(component_name).join('Pod').join('Assets')
  FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
  FileUtils.mkdir(target_dir)
  FileUtils.copy_entry(@resource_path, target_dir)
  KCommercial::UI.debug("开始自动copy资源到#{@component_name}组件完成")
  KCommercial::UI.info("如需要使用#{@app_name}资源请添加#{@component_name}组件依赖")
end

#generate!Object

auto generate componet



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/KCommercialPipeline/core/resource/source/lib_bundle.rb', line 20

def generate!
  unless check_exist?
    KCommercial::UI.debug("开始自动创建资源组件#{@component_name}")
    templete_url = '[email protected]:exploration-client/cocoadepot-toolchain/templates/pod-template.git'.freeze
    creator = CocoaDepot::MaterialCreator.new(templete_url, @component_name)
    custom_resource_bundle_config = <<EOF
    s.resource_bundles = {
'#{@bundle_name}Resources' => ['Pod/Assets/**/*.{xcassets,json}']
    }
EOF
    bundle_path = "#{@depot.root_path}/#{@depot.configuration.components.origin_configurations[:search_paths].last}"
    creator.auto_create!(true, bundle_path, custom_resource_bundle_config)
    KCommercial::UI.info("自动创建资源组件#{@component_name}成功")
  end
  copy_resource!
end