KCommercialPipeline 0.2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.idea/.gitignore +8 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/inspectionProfiles/profiles_settings.xml +5 -0
- data/.idea/kcommercialpipeline.iml +130 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +224 -0
- data/KCommercialPipeline-0.2.5.0.gem +0 -0
- data/KCommercialPipeline.gemspec +49 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +16 -0
- data/bin/KCommercialPipeline +17 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/KCommercialPipeline/App.rb +18 -0
- data/lib/KCommercialPipeline/command/app_runner.rb +34 -0
- data/lib/KCommercialPipeline/command/auto_cherry_pick_cmd.rb +18 -0
- data/lib/KCommercialPipeline/command/change_log.rb +19 -0
- data/lib/KCommercialPipeline/command/check_release_cmd.rb +34 -0
- data/lib/KCommercialPipeline/command/command.rb +44 -0
- data/lib/KCommercialPipeline/command/feat_check.rb +16 -0
- data/lib/KCommercialPipeline/command/git_hook_install_cmd.rb +29 -0
- data/lib/KCommercialPipeline/command/ios_publish_component.rb +71 -0
- data/lib/KCommercialPipeline/command/rb_auto.rb +30 -0
- data/lib/KCommercialPipeline/command/resource.rb +52 -0
- data/lib/KCommercialPipeline/core/app_demo.rb +196 -0
- data/lib/KCommercialPipeline/core/branch_diffs.rb +95 -0
- data/lib/KCommercialPipeline/core/change_log/change_log_task.rb +317 -0
- data/lib/KCommercialPipeline/core/change_log/doc_builder.rb +91 -0
- data/lib/KCommercialPipeline/core/component_publisher.rb +122 -0
- data/lib/KCommercialPipeline/core/feature_send.rb +88 -0
- data/lib/KCommercialPipeline/core/git.rb +125 -0
- data/lib/KCommercialPipeline/core/git_hook/install_git_hook.rb +84 -0
- data/lib/KCommercialPipeline/core/git_hook/prepare_commit_msg.rb +0 -0
- data/lib/KCommercialPipeline/core/kim_cfg.rb +64 -0
- data/lib/KCommercialPipeline/core/kim_notify.rb +99 -0
- data/lib/KCommercialPipeline/core/resource/auto_publish_resource/update_resource_component.rb +35 -0
- data/lib/KCommercialPipeline/core/resource/bundle/colors_generator.rb +29 -0
- data/lib/KCommercialPipeline/core/resource/bundle/files_generator.rb +36 -0
- data/lib/KCommercialPipeline/core/resource/bundle/fonts_generator.rb +29 -0
- data/lib/KCommercialPipeline/core/resource/bundle/i18ns_generator.rb +29 -0
- data/lib/KCommercialPipeline/core/resource/bundle/images_generator.rb +67 -0
- data/lib/KCommercialPipeline/core/resource/bundle/indexes_generator.rb +55 -0
- data/lib/KCommercialPipeline/core/resource/bundle/scale_pathname.rb +23 -0
- data/lib/KCommercialPipeline/core/resource/code_generator/code_generator.rb +59 -0
- data/lib/KCommercialPipeline/core/resource/code_generator/file_generator.rb +16 -0
- data/lib/KCommercialPipeline/core/resource/code_generator/resources_status.rb +24 -0
- data/lib/KCommercialPipeline/core/resource/component_resources_config.rb +63 -0
- data/lib/KCommercialPipeline/core/resource/file_generator.rb +16 -0
- data/lib/KCommercialPipeline/core/resource/i18n/auto_component.rb +61 -0
- data/lib/KCommercialPipeline/core/resource/i18n/bundle_generator.rb +36 -0
- data/lib/KCommercialPipeline/core/resource/i18n/generator.rb +368 -0
- data/lib/KCommercialPipeline/core/resource/key_defines.rb +41 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/code_model.rb +51 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/oc_file_model.rb +59 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/oc_generator.rb +55 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{component_header_name}}.h +39 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Colors.h +31 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Colors.m +29 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Files.h +31 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Files.m +29 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Fonts.h +31 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Fonts.m +29 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+I18ns.h +31 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+I18ns.m +29 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Images.h +30 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}+Images.m +29 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}.h +39 -0
- data/lib/KCommercialPipeline/core/resource/objective-c/templates/{{oc_class_name}}.m +51 -0
- data/lib/KCommercialPipeline/core/resource/source/asset.rb +120 -0
- data/lib/KCommercialPipeline/core/resource/source/asset_type.rb +16 -0
- data/lib/KCommercialPipeline/core/resource/source/git_source.rb +105 -0
- data/lib/KCommercialPipeline/core/resource/source/git_source_manager.rb +114 -0
- data/lib/KCommercialPipeline/core/resource/source/interface.rb +9 -0
- data/lib/KCommercialPipeline/core/resource/source/lib_bundle.rb +50 -0
- data/lib/KCommercialPipeline/core/resource/source/source.rb +9 -0
- data/lib/KCommercialPipeline/core/resource/source/source_interface.rb +20 -0
- data/lib/KCommercialPipeline/core/resource/source/source_manager.rb +93 -0
- data/lib/KCommercialPipeline/core/resource/source/star_source.rb +145 -0
- data/lib/KCommercialPipeline/core/resource/source/subspec_bundle.rb +34 -0
- data/lib/KCommercialPipeline/core/resource/swift/colors_generator.rb +22 -0
- data/lib/KCommercialPipeline/core/resource/swift/files_generate.rb +22 -0
- data/lib/KCommercialPipeline/core/resource/swift/fonts_generator.rb +22 -0
- data/lib/KCommercialPipeline/core/resource/swift/i18n_generetor.rb +22 -0
- data/lib/KCommercialPipeline/core/resource/swift/images_generator.rb +22 -0
- data/lib/KCommercialPipeline/core/resource/swift/swift_generator.rb +84 -0
- data/lib/KCommercialPipeline/core/resource/xcassets/image.rb +30 -0
- data/lib/KCommercialPipeline/core/resource/xcassets/imageset.rb +53 -0
- data/lib/KCommercialPipeline/core/resource/xcassets/xcassets.rb +63 -0
- data/lib/KCommercialPipeline/core/version_pipeline/auto_cherry_pick.rb +173 -0
- data/lib/KCommercialPipeline/core/version_pipeline/release_branches.rb +183 -0
- data/lib/KCommercialPipeline/core/version_pipeline/release_check.rb +111 -0
- data/lib/KCommercialPipeline/version.rb +5 -0
- data/lib/KCommercialPipeline.rb +19 -0
- metadata +304 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'asset_type'
|
3
|
+
require 'singleton'
|
4
|
+
module KCommercial
|
5
|
+
module Resources
|
6
|
+
class GitSourceManager
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
# The shared manager
|
10
|
+
# @return [CocoaDepot::Resources::GitSourceManager]
|
11
|
+
def self.shared
|
12
|
+
GitSourceManager.instance
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :repos_dir
|
16
|
+
|
17
|
+
def home_dir
|
18
|
+
@home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoadepot-resources').expand_path
|
19
|
+
@home_dir.mkpath unless @home_dir.exist?
|
20
|
+
@home_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
def repos_dir
|
24
|
+
@repos_dir ||= home_dir.join('repos')
|
25
|
+
@repos_dir.mkpath unless @repos_dir.exist?
|
26
|
+
@repos_dir
|
27
|
+
end
|
28
|
+
|
29
|
+
def sources
|
30
|
+
@sources ||= {}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get the git source with name or url
|
34
|
+
# @param [String] url
|
35
|
+
# @return [GitSource]
|
36
|
+
def source_with_url(url)
|
37
|
+
name = name_for_url(url)
|
38
|
+
sources[name] ||= begin
|
39
|
+
path = repos_dir.join(name)
|
40
|
+
GitSource.new(url, path)
|
41
|
+
end
|
42
|
+
sources[name]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns a suitable repository name for `url`.
|
46
|
+
#
|
47
|
+
# @example A GitHub.com URL
|
48
|
+
#
|
49
|
+
# name_for_url('https://github.com/Artsy/Specs.git')
|
50
|
+
# # "artsy"
|
51
|
+
# name_for_url('https://github.com/Artsy/Specs.git')
|
52
|
+
# # "artsy-1"
|
53
|
+
#
|
54
|
+
# @example A non-Github.com URL
|
55
|
+
#
|
56
|
+
# name_for_url('https://sourceforge.org/Artsy/Specs.git')
|
57
|
+
# # sourceforge-artsy-specs
|
58
|
+
#
|
59
|
+
# @example A file URL
|
60
|
+
#
|
61
|
+
# name_for_url('file:///Artsy/Specs.git')
|
62
|
+
# # artsy-specs
|
63
|
+
#
|
64
|
+
# @param [#to_s] url
|
65
|
+
# The URL of the source.
|
66
|
+
#
|
67
|
+
# @return [String] A suitable repository name for `url`.
|
68
|
+
#
|
69
|
+
def name_for_url(url)
|
70
|
+
base_from_host_and_path = lambda do |host, path|
|
71
|
+
if host && !host.empty?
|
72
|
+
base = host.split('.')[-2] || host
|
73
|
+
base += '-'
|
74
|
+
else
|
75
|
+
base = ''
|
76
|
+
end
|
77
|
+
|
78
|
+
base + path.gsub(/.git$/, '').gsub(%r{^/}, '').split('/').join('-')
|
79
|
+
end
|
80
|
+
|
81
|
+
case url.to_s.downcase
|
82
|
+
when %r{github.com[:/]+(.+)/(.+)}
|
83
|
+
base = Regexp.last_match[1]
|
84
|
+
when %r{^\S+@(\S+)[:/]+(.+)$}
|
85
|
+
host, path = Regexp.last_match.captures
|
86
|
+
base = base_from_host_and_path[host, path]
|
87
|
+
when URI.regexp
|
88
|
+
url = URI(url.downcase)
|
89
|
+
base = base_from_host_and_path[url.host, url.path]
|
90
|
+
else
|
91
|
+
base = url.to_s.downcase
|
92
|
+
end
|
93
|
+
|
94
|
+
name = base
|
95
|
+
# infinity = 1.0 / 0
|
96
|
+
# (1..infinity).each do |i|
|
97
|
+
# break unless source_dir(name).exist?
|
98
|
+
# name = "#{base}-#{i}"
|
99
|
+
# end
|
100
|
+
name
|
101
|
+
end
|
102
|
+
|
103
|
+
# @return [Pathname] The path of the source with the given name.
|
104
|
+
#
|
105
|
+
# @param [String] name
|
106
|
+
# The name of the source.
|
107
|
+
#
|
108
|
+
def source_dir(name)
|
109
|
+
repos_dir + name
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative 'subspec_bundle'
|
2
|
+
require 'cocoadepot'
|
3
|
+
require 'fileutils'
|
4
|
+
require_relative '../i18n/auto_component'
|
5
|
+
|
6
|
+
module KCommercial
|
7
|
+
module Resources
|
8
|
+
class LibBundleGenerator < BundleGenerator
|
9
|
+
attr_accessor :depot
|
10
|
+
|
11
|
+
def depot
|
12
|
+
@depot ||= CocoaDepot::Depot.instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_exist?
|
16
|
+
return !depot.materials_cache.component_for_name(@component_name).nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
# auto generate componet
|
20
|
+
def generate!
|
21
|
+
unless check_exist?
|
22
|
+
KCommercial::UI.debug("开始自动创建资源组件#{@component_name}")
|
23
|
+
templete_url = 'git@git.corp.kuaishou.com:exploration-client/cocoadepot-toolchain/templates/pod-template.git'.freeze
|
24
|
+
creator = CocoaDepot::MaterialCreator.new(templete_url, @component_name)
|
25
|
+
custom_resource_bundle_config = <<EOF
|
26
|
+
s.resource_bundles = {
|
27
|
+
'#{@bundle_name}Resources' => ['Pod/Assets/**/*.{xcassets,json}']
|
28
|
+
}
|
29
|
+
EOF
|
30
|
+
bundle_path = "#{@depot.root_path}/#{@depot.configuration.components.origin_configurations[:search_paths].last}"
|
31
|
+
creator.auto_create!(true, bundle_path, custom_resource_bundle_config)
|
32
|
+
KCommercial::UI.info("自动创建资源组件#{@component_name}成功")
|
33
|
+
end
|
34
|
+
copy_resource!
|
35
|
+
end
|
36
|
+
|
37
|
+
# copy resource
|
38
|
+
def copy_resource!
|
39
|
+
KCommercial::UI.debug("开始自动copy资源到#{@component_name}组件")
|
40
|
+
bundle_path = "#{@depot.root_path}/#{@depot.configuration.components.origin_configurations[:search_paths].last}"
|
41
|
+
target_dir = Pathname(bundle_path).join(component_name).join('Pod').join('Assets')
|
42
|
+
FileUtils.rm_rf(target_dir) if File.exist?(target_dir)
|
43
|
+
FileUtils.mkdir(target_dir)
|
44
|
+
FileUtils.copy_entry(@resource_path, target_dir)
|
45
|
+
KCommercial::UI.debug("开始自动copy资源到#{@component_name}组件完成")
|
46
|
+
KCommercial::UI.info("如需要使用#{@app_name}资源请添加#{@component_name}组件依赖")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
require_relative 'interface'
|
3
|
+
|
4
|
+
module KCommercial
|
5
|
+
module Resources
|
6
|
+
module SourceInterface
|
7
|
+
extend RubyLanguage::Interface
|
8
|
+
|
9
|
+
# update the current source to the latest version
|
10
|
+
interface :update
|
11
|
+
|
12
|
+
# get asset from the source
|
13
|
+
# @param [String] type
|
14
|
+
# @return [CocoaDepot::Resources::Asset]
|
15
|
+
interface :all_assets
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require_relative 'star_source'
|
3
|
+
require_relative 'git_source'
|
4
|
+
module KCommercial
|
5
|
+
module Resources
|
6
|
+
class SourceManager
|
7
|
+
include Singleton
|
8
|
+
# The shared manager
|
9
|
+
# @return [CocoaDepot::Resources::SourceManager]
|
10
|
+
def self.shared
|
11
|
+
SourceManager.instance
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def home_dir
|
16
|
+
@home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoadepot-resources').expand_path
|
17
|
+
@home_dir.mkpath unless @home_dir.exist?
|
18
|
+
@home_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
def repos_dir
|
22
|
+
@repos_dir ||= home_dir.join('repos')
|
23
|
+
@repos_dir.mkpath unless @repos_dir.exist?
|
24
|
+
@repos_dir
|
25
|
+
end
|
26
|
+
|
27
|
+
def sources
|
28
|
+
@sources ||= {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def source_with_url(url)
|
32
|
+
if is_git_url(url)
|
33
|
+
name = name_for_git_url(url)
|
34
|
+
path = repos_dir.join(name)
|
35
|
+
sources[name] ||= GitSource.new(url, path)
|
36
|
+
else
|
37
|
+
name = name_for_platform_url(url)
|
38
|
+
path = repos_dir.join(name)
|
39
|
+
sources[name] ||= StarSource.new(url, path)
|
40
|
+
end
|
41
|
+
sources[name]
|
42
|
+
end
|
43
|
+
# url是否是git仓库
|
44
|
+
def is_git_url(url)
|
45
|
+
regexp = Regexp.new('(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$')
|
46
|
+
return regexp.match(url)
|
47
|
+
end
|
48
|
+
# 获取git资源仓库名字
|
49
|
+
def name_for_git_url(url)
|
50
|
+
base_from_host_and_path = lambda do |host, path|
|
51
|
+
if host && !host.empty?
|
52
|
+
base = host.split('.')[-2] || host
|
53
|
+
base += '-'
|
54
|
+
else
|
55
|
+
base = ''
|
56
|
+
end
|
57
|
+
|
58
|
+
base + path.gsub(/.git$/, '').gsub(%r{^/}, '').split('/').join('-')
|
59
|
+
end
|
60
|
+
|
61
|
+
case url.to_s.downcase
|
62
|
+
when %r{github.com[:/]+(.+)/(.+)}
|
63
|
+
base = Regexp.last_match[1]
|
64
|
+
when %r{^\S+@(\S+)[:/]+(.+)$}
|
65
|
+
host, path = Regexp.last_match.captures
|
66
|
+
base = base_from_host_and_path[host, path]
|
67
|
+
when URI.regexp
|
68
|
+
url = URI(url.downcase)
|
69
|
+
base = base_from_host_and_path[url.host, url.path]
|
70
|
+
else
|
71
|
+
base = url.to_s.downcase
|
72
|
+
end
|
73
|
+
|
74
|
+
name = base
|
75
|
+
name
|
76
|
+
end
|
77
|
+
# 获取资源平台名字
|
78
|
+
def name_for_platform_url(url)
|
79
|
+
hash = Hash.new("")
|
80
|
+
if url.index('?')
|
81
|
+
str = url.split('?')[1]
|
82
|
+
if str.split('&')
|
83
|
+
array = str.split('&')
|
84
|
+
array.each do |item|
|
85
|
+
hash[item.split('=')[0]] = item.split('=')[1]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return "exploration_#{hash['space']}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'zip'
|
4
|
+
require_relative 'asset_type'
|
5
|
+
module KCommercial
|
6
|
+
module Resources
|
7
|
+
class StarSource
|
8
|
+
class PathSource
|
9
|
+
# is common resources
|
10
|
+
attr_reader :is_common_asset
|
11
|
+
attr_accessor :assets_name, :assets_type, :assets, :app
|
12
|
+
|
13
|
+
def initialize(assets_name, assets_type, path, app = 'default')
|
14
|
+
@is_common_asset = app == 'default'
|
15
|
+
@app = app
|
16
|
+
@assets_name = assets_name
|
17
|
+
@assets_type = assets_type
|
18
|
+
@assets = []
|
19
|
+
prepare(path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def assets_from_directory(directory, asset_class)
|
23
|
+
asset_paths = directory.glob('**/*.cdasset')
|
24
|
+
asset_paths.map do |path|
|
25
|
+
name = path.basename('.*').to_s
|
26
|
+
asset_class.new(name, path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def prepare(path)
|
31
|
+
return [] unless @assets_name && path
|
32
|
+
asset_paths = []
|
33
|
+
if is_common_asset
|
34
|
+
asset_paths << path.join(@assets_name.to_s)
|
35
|
+
else
|
36
|
+
asset_paths = path.glob("**/#{@assets_name}")
|
37
|
+
|
38
|
+
end
|
39
|
+
asset_paths.each do |path|
|
40
|
+
if [ KCommercial::Resources::AssetType::Font].include? @assets_type
|
41
|
+
dir_assets = assets_from_directory path, HashAsset
|
42
|
+
elsif [KCommercial::Resources::AssetType::Color, KCommercial::Resources::AssetType::I18n].include? @assets_type
|
43
|
+
dir_assets = assets_from_directory path, StringAsset
|
44
|
+
elsif [KCommercial::Resources::AssetType::Image].include? @assets_type
|
45
|
+
dir_assets = assets_from_directory path, ArrayHashAsset
|
46
|
+
else
|
47
|
+
dir_assets = assets_from_directory path, Asset
|
48
|
+
end
|
49
|
+
merge_assets(dir_assets)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def merge_assets(assets)
|
54
|
+
if @assets != assets && assets
|
55
|
+
result = assets + @assets
|
56
|
+
@assets = result.uniq(&:name)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
# 合并数据源,被merge的优先级较高,会替换前边的
|
60
|
+
def merge(path_source)
|
61
|
+
raise 'merge error,raise' unless path_source.assets_type == assets_type
|
62
|
+
|
63
|
+
if path_source != self
|
64
|
+
result = @assets + path_source.assets
|
65
|
+
@assets = result.uniq(&:name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
# The url for the star platform
|
70
|
+
# @return [String]
|
71
|
+
attr_reader :url
|
72
|
+
attr_reader :default_path, :app_paths, :all_assets_maps
|
73
|
+
# The local storage path
|
74
|
+
# @return [Pathname]
|
75
|
+
attr_reader :root_path
|
76
|
+
|
77
|
+
# @param [String] url
|
78
|
+
# @param [Pathname] root_path
|
79
|
+
def initialize(url, root_path)
|
80
|
+
@url = url
|
81
|
+
@root_path = root_path
|
82
|
+
@temp_path = root_path.split[0].join("temp_#{Time.now.to_i}")
|
83
|
+
@default_path = root_path.join('defaults')
|
84
|
+
@all_assets_maps = {}
|
85
|
+
end
|
86
|
+
|
87
|
+
def load_assets(type)
|
88
|
+
directory_name = type_directory_mapper[type]
|
89
|
+
return nil unless directory_name
|
90
|
+
|
91
|
+
sources = app_paths.map { |c| PathSource.new(directory_name, type, c, c.basename.to_s) }
|
92
|
+
common_source = sources.find_all(&:is_common_asset)
|
93
|
+
sources.each { |items| items.merge(common_source.first) } if common_source.size.positive?
|
94
|
+
all_assets_maps[directory_name] = sources
|
95
|
+
sources
|
96
|
+
end
|
97
|
+
|
98
|
+
def struct_assets_from_directory(directory)
|
99
|
+
asset_paths = directory.glob('**/*.cdasset')
|
100
|
+
asset_paths.map do |path|
|
101
|
+
name = path.basename('.*').to_s
|
102
|
+
HashAsset.new(name, path)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def type_directory_mapper
|
107
|
+
{
|
108
|
+
AssetType::Color => 'Colors',
|
109
|
+
AssetType::File => 'Files',
|
110
|
+
AssetType::Font => 'Fonts',
|
111
|
+
AssetType::I18n => 'I18ns',
|
112
|
+
AssetType::Image => 'Images',
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
# Update the source
|
117
|
+
def update
|
118
|
+
# 先在临时目录下载
|
119
|
+
download_resources(url)
|
120
|
+
# 最后rename
|
121
|
+
rename_resources
|
122
|
+
end
|
123
|
+
|
124
|
+
def download_resources(url)
|
125
|
+
KCommercial::UI.info "download the source #{url}"
|
126
|
+
download = URI.open(url)
|
127
|
+
Zip::File.open_buffer(download) do |zip|
|
128
|
+
zip.each do |entry|
|
129
|
+
path = @temp_path.join(entry.name)
|
130
|
+
entry.extract(path)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
def rename_resources
|
137
|
+
if root_path.exist?
|
138
|
+
FileUtils.rm_r(root_path)
|
139
|
+
end
|
140
|
+
File.rename(@temp_path, root_path)
|
141
|
+
@app_paths = root_path.children.find_all(&:directory?) || [] if @root_path.exist?
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module KCommercial
|
2
|
+
module Resources
|
3
|
+
class BundleGenerator
|
4
|
+
attr_accessor :bundle_name, :component_name, :resource_path
|
5
|
+
|
6
|
+
def initialize(component_name, bundle_name, resource_path)
|
7
|
+
@component_name = component_name
|
8
|
+
@bundle_name = bundle_name
|
9
|
+
@resource_path = resource_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_exist?
|
13
|
+
raise NotImplementedError, "#{self.class.name}#check是抽象方法"
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate!
|
17
|
+
raise NotImplementedError, "#{self.class.name}#generate!是抽象方法"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module CocoaDepot
|
24
|
+
module Resources
|
25
|
+
class SubspecBundleGenerator
|
26
|
+
def check
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate!
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'swift_generator'
|
3
|
+
module KCommercial
|
4
|
+
module Resources
|
5
|
+
class ColorsGenerator < SwiftGenerator
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def class_name
|
10
|
+
"Colors"
|
11
|
+
end
|
12
|
+
|
13
|
+
def key_to_code(key)
|
14
|
+
<<EOF
|
15
|
+
public class func #{key_to_function_name(key)}() -> UIColor? {
|
16
|
+
return R.default.color(for: "#{key}", env: Enviroment.shared)
|
17
|
+
}
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'swift_generator'
|
3
|
+
module KCommercial
|
4
|
+
module Resources
|
5
|
+
class FilesGenerator < SwiftGenerator
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def class_name
|
10
|
+
"Files"
|
11
|
+
end
|
12
|
+
|
13
|
+
def key_to_code(key)
|
14
|
+
<<EOF
|
15
|
+
public class func #{key_to_function_name(key)}() -> URL? {
|
16
|
+
return R.default.file(for: "#{key}", env: Enviroment.shared)
|
17
|
+
}
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'swift_generator'
|
3
|
+
module KCommercial
|
4
|
+
module Resources
|
5
|
+
class FontsGenerator < SwiftGenerator
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def class_name
|
10
|
+
"Fonts"
|
11
|
+
end
|
12
|
+
|
13
|
+
def key_to_code(key)
|
14
|
+
<<EOF
|
15
|
+
public class func #{key_to_function_name(key)}() -> UIFont? {
|
16
|
+
return R.default.font(for: "#{key}", env: Enviroment.shared)
|
17
|
+
}
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'swift_generator'
|
3
|
+
module KCommercial
|
4
|
+
module Resources
|
5
|
+
class I18nsGenerator < SwiftGenerator
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def class_name
|
10
|
+
"I18ns"
|
11
|
+
end
|
12
|
+
|
13
|
+
def key_to_code(key)
|
14
|
+
<<EOF
|
15
|
+
public class func #{key_to_function_name(key)}() -> String? {
|
16
|
+
return R.default.i18n(for: "#{key}", env: Enviroment.shared)
|
17
|
+
}
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'swift_generator'
|
3
|
+
module KCommercial
|
4
|
+
module Resources
|
5
|
+
class ImagesGenerator < SwiftGenerator
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def class_name
|
10
|
+
"Images"
|
11
|
+
end
|
12
|
+
|
13
|
+
def key_to_code(key)
|
14
|
+
<<EOF
|
15
|
+
public class func #{key_to_function_name(key)}() -> UIImage? {
|
16
|
+
return R.default.image(for: "#{key}", env: Enviroment.shared)
|
17
|
+
}
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class String
|
3
|
+
def camelize(uppercase_first_letter = true)
|
4
|
+
string = self
|
5
|
+
if uppercase_first_letter
|
6
|
+
string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
7
|
+
else
|
8
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
9
|
+
end
|
10
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module KCommercial
|
15
|
+
module Resources
|
16
|
+
class SwiftGenerator
|
17
|
+
# The super module default is MKResources
|
18
|
+
# @return [String]
|
19
|
+
attr_reader :super_module
|
20
|
+
|
21
|
+
# The key defines for the generator
|
22
|
+
# @return [Array<String>]
|
23
|
+
attr_reader :keys
|
24
|
+
|
25
|
+
# Create a new SwiftGenerator
|
26
|
+
# @param [Array<String>] keys the defines for keys
|
27
|
+
def initialize(keys, options = {})
|
28
|
+
@keys = keys
|
29
|
+
@keys ||= []
|
30
|
+
@super_module = options.delete(:super) { :MKResources}
|
31
|
+
end
|
32
|
+
|
33
|
+
def extension_contents
|
34
|
+
<<EOF
|
35
|
+
//
|
36
|
+
// SharedResources.swift
|
37
|
+
// MKSharedResources
|
38
|
+
//
|
39
|
+
// Created by Dong Zhao on 2020/12/31.
|
40
|
+
//
|
41
|
+
import MKResources
|
42
|
+
import #{super_module}
|
43
|
+
extension R {
|
44
|
+
#{append_prefix(swift_contents,"\t")}
|
45
|
+
}
|
46
|
+
EOF
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def class_name
|
52
|
+
"Colors"
|
53
|
+
end
|
54
|
+
|
55
|
+
def swift_contents
|
56
|
+
key_functions = keys.map { |key| "#{key_to_code(key)}" }.join('')
|
57
|
+
<<EOF
|
58
|
+
// swiftlint:disable all
|
59
|
+
open class #{class_name}: #{super_module}.R.#{class_name}{
|
60
|
+
#{append_prefix(key_functions, "\t")}
|
61
|
+
}
|
62
|
+
// swiftlint:enable all
|
63
|
+
EOF
|
64
|
+
end
|
65
|
+
|
66
|
+
def key_to_code(key)
|
67
|
+
raise NotImplementedError
|
68
|
+
end
|
69
|
+
|
70
|
+
def key_to_function_name(key)
|
71
|
+
key = key.camelize(false)
|
72
|
+
if key.length > 0
|
73
|
+
key[0] = key[0].downcase
|
74
|
+
end
|
75
|
+
key
|
76
|
+
end
|
77
|
+
|
78
|
+
def append_prefix(contents, prefix)
|
79
|
+
contents.lines.map { |l| "#{prefix}#{l}"}.join('')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|