lhj-tools 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2210e536172e4943d1e39f4460cd715ef726e35b0859c348b24963a1f0ff433
4
- data.tar.gz: c1e81cf0c82016ee20f57168c840780cd7127a28a1c2c92d409785f03a52dbe5
3
+ metadata.gz: 345699c92fe75a529d05050135d866e8670fe07c28f4aa9bf32aefd960fdc40f
4
+ data.tar.gz: 5ddc18ba4e727e6eeb5363bc3623850ff0f1c741b86e33cecc877b01ac5bf9a4
5
5
  SHA512:
6
- metadata.gz: 8cd06e57308f22d90b13d330f21a6c198d873a5483ae604c044e3c0fbd76c8083550fb261e30fc40f43b8e1af8f891063b0ba7a7930a258de8cf1f8292855802
7
- data.tar.gz: 2428331f080d48dac6ae877c179a900ddb2601a32c292062d2edbfa7febb1a202dda40fd7fe21f6d840dffad0335695ad1c306c6ea9903a99bd2895cead8edc4
6
+ metadata.gz: 7132fb9221499be206163ab2aa9b540e56e8ec5ad5084dbe24807b09bf40697a647dfcbdc9261831d36474d77afa0e0e124d83284f5c070f177bb916f24f6139
7
+ data.tar.gz: c7295be5a50ccb8c6746fa4ece7ccdfdaaf8aea8925aa981ac10b141c2c05e232d129bc49233c3a089a7f2682736a549afbc7078c5b01b6b2cddbfb9fd42e14f
@@ -1,12 +1,19 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'lhj/config'
1
6
 
2
7
  module Lhj
3
8
  class Command
4
- # init tools
9
+ # sync config
5
10
  class Init < Command
6
11
  self.summary = '初始化控件'
12
+ self.description = '使用工具前先执行`lhj init`'
7
13
 
8
14
  def run
9
- p 'hello world'
15
+ FileUtils.mkdir_p(target_folder) unless File.exist?(target_folder)
16
+ download_file
10
17
  end
11
18
 
12
19
  def down_load_urls
@@ -16,11 +23,29 @@ module Lhj
16
23
  http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml]
17
24
  end
18
25
 
19
- def down_load_file
20
- ary = down_load_urls
21
- ary.each do |key|
26
+ def target_folder
27
+ Lhj::Config.instance.home_dir
28
+ end
29
+
30
+ def save_file(url, target)
31
+ http_client = Faraday.new do |c|
32
+ c.adapter Faraday.default_adapter
33
+ end
34
+ response = http_client.get(url)
35
+ File.open(target, 'wb') { |fp| fp.write(response.body) }
36
+ end
37
+
38
+ def file_name_with_url(url)
39
+ url.scan(%r{(/.[^/]*)}).flatten.last
40
+ end
41
+
42
+ def download_file
43
+ down_load_urls.each do |url|
44
+ file_name = file_name_with_url(url)
45
+ file_path = File.join(target_folder, file_name)
46
+ save_file(url, file_path) unless File.exist?(file_path)
22
47
  end
23
- puts "同步完成 \n"
48
+ puts "工具初始化完成 \n"
24
49
  end
25
50
  end
26
51
  end
@@ -4,6 +4,8 @@ module Lhj
4
4
  class Command
5
5
  class OSS < Command
6
6
  class List < OSS
7
+ self.summary = '查看oss列表'
8
+
7
9
  def run
8
10
  objects = Lhj::OSS::Helper.instance.list
9
11
  objects.each do |o|
@@ -0,0 +1,10 @@
1
+
2
+ module Lhj
3
+ class Command
4
+ # sync config
5
+ class OSS < Command
6
+ self.summary = 'oss操作'
7
+ self.abstract_command = true
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,8 @@
2
2
  module Lhj
3
3
  class Command
4
4
  class Rename < Command
5
+ self.summary = '重命名图片'
6
+
5
7
  def run
6
8
  rename
7
9
  end
@@ -5,6 +5,7 @@ module Lhj
5
5
  class Command
6
6
  class Trans < Command
7
7
  self.summary = '源码中的简繁体转换'
8
+ self.description = '当前目录简繁体转换 `lhj trans --zh-cn`'
8
9
 
9
10
  def self.options
10
11
  [
@@ -1,7 +1,8 @@
1
1
  module Lhj
2
2
  class Command
3
3
  class View < Command
4
- self.summary = '生成源码'
4
+ self.summary = '生成iOS组件源码'
5
+ self.description = '使用`lhj view --type=UILabel --name=titleLabel`'
5
6
 
6
7
  def initialize(argv)
7
8
  @name = argv.option('name', 'titleLabel')
@@ -10,24 +11,25 @@ module Lhj
10
11
  end
11
12
 
12
13
  def names
13
- @name.split(",").map(&:strip)
14
+ @name.split(',').map(&:strip)
14
15
  end
15
16
 
16
17
  def type
17
18
  @ele_type ||= begin
18
- if @type =~ /image/i
19
+ case @type
20
+ when /image/i
19
21
  'UIImageView'
20
- elsif @type =~ /stack/i
22
+ when /stack/i
21
23
  'UIStackView'
22
- elsif @type =~ /label/i
24
+ when /label/i
23
25
  'UILabel'
24
- elsif @type =~ /table/i
26
+ when /table/i
25
27
  'UITableView'
26
- elsif @type =~ /text/i
28
+ when /text/i
27
29
  'UITextField'
28
- elsif @type =~ /button/i
30
+ when /button/i
29
31
  'UIButton'
30
- elsif @type =~ /view/i
32
+ when /view/i
31
33
  'UIView'
32
34
  else
33
35
  @type
@@ -47,7 +49,7 @@ module Lhj
47
49
 
48
50
  def print_declare
49
51
  names.each do |name|
50
- puts "///"
52
+ puts '///'
51
53
  puts "@property (nonatomic, strong) #{type} *#{name};"
52
54
  end
53
55
  end
@@ -55,24 +57,25 @@ module Lhj
55
57
  def print_instance
56
58
  names.each do |name|
57
59
  puts "-(#{type} *)#{name}"
58
- puts "{"
60
+ puts '{'
59
61
  puts " if(!_#{name}){"
60
62
  print_alloc(name)
61
63
  puts " _#{name}.translatesAutoresizingMaskIntoConstraints = NO;"
62
64
  print_property(name)
63
- puts " }"
65
+ puts ' }'
64
66
  puts " return _#{name};"
65
- puts "}"
67
+ puts '}'
66
68
  puts "\n"
67
69
  end
68
70
  end
69
71
 
70
72
  def print_alloc(name)
71
- if type.eql?('UIImageView')
73
+ case type
74
+ when 'UIImageView'
72
75
  puts " _#{name} = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"xxxx\"]];"
73
- elsif type.eql?('UIButton')
76
+ when 'UIButton'
74
77
  puts " _#{name} = [UIButton buttonWithType:UIButtonTypeCustom];"
75
- elsif type.eql?('UITableView')
78
+ when 'UITableView'
76
79
  puts " _#{name} = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];"
77
80
  else
78
81
  puts " _#{name} = [[#{type} alloc] init];"
@@ -80,34 +83,35 @@ module Lhj
80
83
  end
81
84
 
82
85
  def print_property(name)
83
- if type.eql?('UILabel')
86
+ case type
87
+ when 'UILabel'
84
88
  puts " _#{name}.textColor = kSetCOLOR(0x333333);"
85
89
  puts " _#{name}.text = @\"xxxxxxxx\";"
86
90
  puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
87
91
  puts " _#{name}.textAlignment = NSTextAlignmentCenter;"
88
- elsif type.eql?('UIImageView')
92
+ when 'UIImageView'
89
93
  puts " _#{name}.backgroundColor = kBackgroundColor;"
90
94
  puts " _#{name}.contentMode = UIViewContentModeScaleAspectFit;"
91
95
  puts " _#{name}.clipsToBounds = YES;"
92
96
  puts " _#{name}.layer.cornerRadius = 6.0f;"
93
97
  puts " _#{name}.layer.borderColor = kLineColor.CGColor;"
94
98
  puts " _#{name}.layer.borderWidth = 0.5;"
95
- elsif type.eql?('UITextField')
99
+ when 'UITextField'
96
100
  puts " _#{name}.textColor = kSetCOLOR(0x333333);"
97
101
  puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
98
- elsif type.eql?('UIView')
102
+ when 'UIView'
99
103
  puts " _#{name}.backgroundColor = kBackgroundColor;"
100
- elsif type.eql?('UIStackView')
104
+ when 'UIStackView'
101
105
  puts " _#{name}.axis = UILayoutConstraintAxisHorizontal;"
102
106
  puts " _#{name}.distribution = UIStackViewDistributionFillEqually;"
103
- elsif type.eql?('UITableView')
107
+ when 'UITableView'
104
108
  puts " _#{name}.backgroundColor = kBackgroundColor;"
105
109
  puts " _#{name}.delegate = self;"
106
110
  puts " _#{name}.delegate = self;"
107
111
  puts " _#{name}.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
108
112
  puts " _#{name}.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
109
113
  puts " _#{name}.separatorStyle = UITableViewCellSeparatorStyleNone;"
110
- elsif type.eql?('UIButton')
114
+ when 'UIButton'
111
115
  puts " _#{name}.backgroundColor = kBackgroundColor;"
112
116
  puts " [_#{name} setTitle:@\"xxx\" forState:UIControlStateNormal];"
113
117
  puts " [_#{name} setTitleColor:kSetCOLOR(0x999999) forState:UIControlStateNormal];"
@@ -7,6 +7,7 @@ module Lhj
7
7
  class Command
8
8
  class Yapi < Command
9
9
  self.summary = '通过yapi接口生成请求'
10
+ self.description = '更新 ~/.lhj/yapi.yml 文件配置后执行`lhj api`生成接口模型'
10
11
 
11
12
  def self.options
12
13
  [
@@ -43,8 +44,8 @@ module Lhj
43
44
  def test_ding
44
45
  require 'net/http'
45
46
  require 'uri'
46
- body = { "msgtype" => "text", "text" => { "content" => "error:上传蒲公英超时失败!" } }.to_json
47
- Net::HTTP.post(URI('https://oapi.dingtalk.com/robot/send?access_token=6a3519057170cdb1b7274edfe43934c84a0062ffe2c9bcced434699296a7e26e'), body, "Content-Type" => "application/json")
47
+ body = { 'msgtype' => 'text', 'text' => { 'content' => 'error:上传蒲公英超时失败!' } }.to_json
48
+ Net::HTTP.post(URI('https://oapi.dingtalk.com/robot/send?access_token=6a3519057170cdb1b7274edfe43934c84a0062ffe2c9bcced434699296a7e26e'), body, 'Content-Type' => 'application/json')
48
49
  end
49
50
 
50
51
  def puts_h(str)
@@ -178,7 +179,8 @@ module Lhj
178
179
  p_model = { name: p_name }
179
180
 
180
181
  properties = []
181
- if p_type.eql?('object')
182
+ case p_type
183
+ when 'object'
182
184
  p_properties.each do |k, v|
183
185
  c_type = @type_trans[v['type']] || v['type']
184
186
  c_model = { key: k, type: c_type, description: v['description'], default: '' }
@@ -186,7 +188,7 @@ module Lhj
186
188
  o = v['items'] || v
187
189
  o['name'] = gen_model_name(k)
188
190
  if v['type'].eql?('array') && v['items']['type'].eql?('string')
189
- c_model[:type_name] = "NSString"
191
+ c_model[:type_name] = 'NSString'
190
192
  else
191
193
  c_model[:type_name] = o['name']
192
194
  handle_model(o)
@@ -196,7 +198,7 @@ module Lhj
196
198
  end
197
199
  p_model[:properties] = properties
198
200
  @models << p_model
199
- elsif p_type.eql?('array')
201
+ when 'array'
200
202
  t = model['items']
201
203
  t['name'] = p_name
202
204
  handle_model(t)
@@ -220,9 +222,9 @@ module Lhj
220
222
  puts_m "@implementation #{model[:name]}"
221
223
  str = model[:properties].filter { |p| p[:type].eql?('array') && !p[:type_name].eql?('NSString') }.map { |p| "@\"#{p[:key]}\": #{p[:type_name]}.class" }.join(', ')
222
224
  if str && str.length > 0
223
- puts_m "+(NSDictionary *)modelContainerPropertyGenericClass {"
225
+ puts_m '+(NSDictionary *)modelContainerPropertyGenericClass {'
224
226
  puts_m " return @{#{str}};"
225
- puts_m "}"
227
+ puts_m '}'
226
228
  end
227
229
  puts_m "@end\n"
228
230
  puts "\n\n"
@@ -237,27 +239,28 @@ module Lhj
237
239
  des.gsub!(/\n/, ' ')
238
240
  default = m[:default]
239
241
  puts_h "///#{des} #{default}"
240
- if type.eql?('integer')
242
+ case type
243
+ when 'integer'
241
244
  puts_h "@property (nonatomic, assign) NSInteger #{key};"
242
245
  if des.include?('分')
243
- puts_h "/////////==========删掉其中一个属性"
246
+ puts_h '/////////==========删掉其中一个属性'
244
247
  puts_h "@property (nonatomic, strong) MLCentNumber *#{key};"
245
248
  end
246
- elsif type.eql?('cent')
249
+ when 'cent'
247
250
  puts_h "@property (nonatomic, strong) MLCentNumber *#{key};"
248
- elsif type.eql?('string')
251
+ when 'string'
249
252
  puts_h "@property (nonatomic, copy) NSString *#{key};"
250
- elsif type.eql?('number')
253
+ when 'number'
251
254
  puts_h "@property (nonatomic, strong) NSNumber *#{key};"
252
- elsif type.eql?('float')
255
+ when 'float'
253
256
  puts_h "@property (nonatomic, assign) CGFloat #{key};"
254
- elsif type.eql?('double')
257
+ when 'double'
255
258
  puts_h "@property (nonatomic, assign) double #{key};"
256
- elsif type.eql?('boolean')
259
+ when 'boolean'
257
260
  puts_h "@property (nonatomic, assign) BOOL #{key};"
258
- elsif type.eql?('object')
261
+ when 'object'
259
262
  puts_h "@property (nonatomic, strong) #{type_name} *#{key};"
260
- elsif type.eql?('array')
263
+ when 'array'
261
264
  puts_h "@property (nonatomic, strong) NSArray<#{type_name} *> *#{key};"
262
265
  else
263
266
  puts_h "@property (nonatomic, copy) NSString *#{key};"
@@ -266,36 +269,36 @@ module Lhj
266
269
 
267
270
  def print_methods
268
271
  puts "\n<===============方法调用=====================>\n"
269
- puts_m "/**"
272
+ puts_m '/**'
270
273
  puts_m " * #{@data_json['title']} -- #{@data_json['username']}"
271
- puts_m " */"
274
+ puts_m ' */'
272
275
  key_str = @data_json['path'].split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { $&.upcase } }.join('')
273
276
  key = "k#{key_str}URL"
274
277
  puts_m "static NSString * const #{key} = @\"#{@data_json['path']}\";"
275
278
  puts_m "\n\n"
276
- puts_h "@interface MLParamModel : NSObject"
279
+ puts_h '@interface MLParamModel : NSObject'
277
280
  @data_json['req_query'].each do |h|
278
281
  des = h['desc']
279
282
  puts_h "///#{des} #{h['example']}"
280
283
  puts_h "@property (nonatomic, copy) NSString *#{h['name']};"
281
284
  end
282
- puts_h "@end"
285
+ puts_h '@end'
283
286
  puts "\n\n"
284
287
  model = @models.last
285
288
  if @data_json['method'].eql?('GET')
286
289
  puts_m " [MLNetworkingManager getWithUrl:#{key} params:nil response:^(MLResponseMessage *responseMessage) {"
287
- puts_m " if (response.resultCode == 0 && !response.error){"
288
- puts_m " NSDictionary *detailMsg = response.detailMsg"
290
+ puts_m ' if (response.resultCode == 0 && !response.error){'
291
+ puts_m ' NSDictionary *detailMsg = response.detailMsg'
289
292
  puts_m " #{model[:name]} *model = [#{model[:name]} yy_modelWithDictionary:detailMsg];" if model
290
- puts_m " }"
291
- puts_m " }];"
293
+ puts_m ' }'
294
+ puts_m ' }];'
292
295
  else
293
296
  puts_m " [MLNetworkingManager postWithUrl:#{key} params:nil response:^(MLResponseMessage *responseMessage) {"
294
- puts_m " if (response.resultCode == 0 && !response.error){"
295
- puts_m " NSDictionary *detailMsg = response.detailMsg"
297
+ puts_m ' if (response.resultCode == 0 && !response.error){'
298
+ puts_m ' NSDictionary *detailMsg = response.detailMsg'
296
299
  puts_m " #{model[:name]} *model = [#{model[:name]} yy_modelWithDictionary:detailMsg];" if model
297
- puts_m " }"
298
- puts_m " }];"
300
+ puts_m ' }'
301
+ puts_m ' }];'
299
302
  end
300
303
  end
301
304
  end
data/lib/lhj/command.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'claide'
2
2
 
3
3
  module Lhj
4
+ # command plugin
4
5
  class Command < CLAide::Command
5
6
  require 'lhj/command/init'
6
7
  require 'lhj/command/head_import'
@@ -10,6 +11,7 @@ module Lhj
10
11
  require 'lhj/command/local/local'
11
12
  require 'lhj/command/local/micro_service'
12
13
  require 'lhj/command/local/local_upload'
14
+ require 'lhj/command/oss'
13
15
  require 'lhj/command/oss/del'
14
16
  require 'lhj/command/oss/upload'
15
17
  require 'lhj/command/oss/list'
@@ -21,4 +23,4 @@ module Lhj
21
23
  self.abstract_command = true
22
24
  self.command = 'lhj'
23
25
  end
24
- end
26
+ end
data/lib/lhj/config.rb CHANGED
@@ -1,354 +1,14 @@
1
-
2
1
  module Lhj
3
- # Stores the global configuration of CocoaPods.
4
- #
2
+ # config
5
3
  class Config
6
- # The default settings for the configuration.
7
- #
8
- # Users can specify custom settings in `~/.cocoapods/config.yaml`.
9
- # An example of the contents of this file might look like:
10
- #
11
- # ---
12
- # skip_repo_update: true
13
- # new_version_message: false
14
- #
15
- DEFAULTS = {
16
- :verbose => false,
17
- :silent => false,
18
- :skip_download_cache => !ENV['COCOAPODS_SKIP_CACHE'].nil?,
19
-
20
- :new_version_message => ENV['COCOAPODS_SKIP_UPDATE_MESSAGE'].nil?,
21
-
22
- :cache_root => Pathname.new(Dir.home) + 'Library/Caches/CocoaPods',
23
- }
24
-
25
- # Applies the given changes to the config for the duration of the given
26
- # block.
27
- #
28
- # @param [Hash<#to_sym,Object>] changes
29
- # the changes to merge temporarily with the current config
30
- #
31
- # @yield [] is called while the changes are applied
32
- #
33
- def with_changes(changes)
34
- old = {}
35
- changes.keys.each do |key|
36
- key = key.to_sym
37
- old[key] = send(key) if respond_to?(key)
38
- end
39
- configure_with(changes)
40
- yield if block_given?
41
- ensure
42
- configure_with(old)
43
- end
44
-
45
- public
46
-
47
- #-------------------------------------------------------------------------#
48
-
49
- # @!group UI
50
-
51
- # @return [Boolean] Whether CocoaPods should provide detailed output about the
52
- # performed actions.
53
- #
54
- attr_accessor :verbose
55
- alias_method :verbose?, :verbose
56
-
57
- # @return [Boolean] Whether CocoaPods should produce not output.
58
- #
59
- attr_accessor :silent
60
- alias_method :silent?, :silent
61
-
62
- # @return [Boolean] Whether CocoaPods is allowed to run as root.
63
- #
64
- attr_accessor :allow_root
65
- alias_method :allow_root?, :allow_root
66
-
67
- # @return [Boolean] Whether a message should be printed when a new version of
68
- # CocoaPods is available.
69
- #
70
- attr_accessor :new_version_message
71
- alias_method :new_version_message?, :new_version_message
72
-
73
- #-------------------------------------------------------------------------#
74
-
75
- # @!group Installation
76
-
77
- # @return [Boolean] Whether the installer should skip the download cache.
78
- #
79
- attr_accessor :skip_download_cache
80
- alias_method :skip_download_cache?, :skip_download_cache
81
-
82
- public
83
-
84
- #-------------------------------------------------------------------------#
85
-
86
- # @!group Cache
87
-
88
- # @return [Pathname] The directory where CocoaPods should cache remote data
89
- # and other expensive to compute information.
90
- #
91
- attr_accessor :cache_root
92
-
93
- def cache_root
94
- @cache_root.mkpath unless @cache_root.exist?
95
- @cache_root
96
- end
97
-
98
- public
99
-
100
- #-------------------------------------------------------------------------#
101
-
102
- # @!group Initialization
103
-
104
- def initialize(use_user_settings = true)
105
- configure_with(DEFAULTS)
106
-
107
- unless ENV['CP_HOME_DIR'].nil?
108
- @cache_root = home_dir + 'cache'
109
- end
110
-
111
- if use_user_settings && user_settings_file.exist?
112
- require 'yaml'
113
- user_settings = YAML.load_file(user_settings_file)
114
- configure_with(user_settings)
115
- end
116
-
117
- unless ENV['CP_CACHE_DIR'].nil?
118
- @cache_root = Pathname.new(ENV['CP_CACHE_DIR']).expand_path
119
- end
120
- end
121
-
122
- def verbose
123
- @verbose && !silent
124
- end
125
-
126
- public
127
-
128
- #-------------------------------------------------------------------------#
129
-
130
- # @!group Paths
131
-
132
- # @return [Pathname] the directory where repos, templates and configuration
133
- # files are stored.
134
- #
135
4
  def home_dir
136
- @home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.lhj').expand_path
5
+ @home_dir ||= Pathname.new('~/.lhj').expand_path
137
6
  end
138
7
 
139
- # @return [Pathname] the directory where the CocoaPods sources are stored.
140
- #
141
- def repos_dir
142
- @repos_dir ||= Pathname.new(ENV['CP_REPOS_DIR'] || (home_dir + 'repos')).expand_path
143
- end
144
-
145
- attr_writer :repos_dir
146
-
147
- # @return [Source::Manager] the source manager for the spec repos in `repos_dir`
148
- #
149
- def sources_manager
150
- return @sources_manager if @sources_manager && @sources_manager.repos_dir == repos_dir
151
- @sources_manager = Source::Manager.new(repos_dir)
152
- end
153
-
154
- # @return [Pathname] the directory where the CocoaPods templates are stored.
155
- #
156
- def templates_dir
157
- @templates_dir ||= Pathname.new(ENV['CP_TEMPLATES_DIR'] || (home_dir + 'templates')).expand_path
158
- end
159
-
160
- # @return [Pathname] the root of the CocoaPods installation where the
161
- # Podfile is located.
162
- #
163
- def installation_root
164
- @installation_root ||= begin
165
- current_dir = Pathname.new(Dir.pwd.unicode_normalize(:nfkc))
166
- current_path = current_dir
167
- until current_path.root?
168
- if podfile_path_in_dir(current_path)
169
- installation_root = current_path
170
- unless current_path == current_dir
171
- UI.puts("[in #{current_path}]")
172
- end
173
- break
174
- else
175
- current_path = current_path.parent
176
- end
177
- end
178
- installation_root || current_dir
179
- end
180
- end
181
-
182
- attr_writer :installation_root
183
- alias_method :project_root, :installation_root
184
-
185
- # @return [Pathname] The root of the sandbox.
186
- #
187
- def sandbox_root
188
- @sandbox_root ||= installation_root + 'Pods'
189
- end
190
-
191
- attr_writer :sandbox_root
192
- alias_method :project_pods_root, :sandbox_root
193
-
194
- # @return [Sandbox] The sandbox of the current project.
195
- #
196
- def sandbox
197
- @sandbox ||= Sandbox.new(sandbox_root)
198
- end
199
-
200
- # @return [Podfile] The Podfile to use for the current execution.
201
- # @return [Nil] If no Podfile is available.
202
- #
203
- def podfile
204
- @podfile ||= Podfile.from_file(podfile_path) if podfile_path
205
- end
206
- attr_writer :podfile
207
-
208
- # @return [Lockfile] The Lockfile to use for the current execution.
209
- # @return [Nil] If no Lockfile is available.
210
- #
211
- def lockfile
212
- @lockfile ||= Lockfile.from_file(lockfile_path) if lockfile_path
213
- end
214
-
215
- # Returns the path of the Podfile.
216
- #
217
- # @note The Podfile can be named either `CocoaPods.podfile.yaml`,
218
- # `CocoaPods.podfile` or `Podfile`. The first two are preferred as
219
- # they allow to specify an OS X UTI.
220
- #
221
- # @return [Pathname]
222
- # @return [Nil]
223
- #
224
- def podfile_path
225
- @podfile_path ||= podfile_path_in_dir(installation_root)
226
- end
227
-
228
- # Returns the path of the Lockfile.
229
- #
230
- # @note The Lockfile is named `Podfile.lock`.
231
- #
232
- def lockfile_path
233
- @lockfile_path ||= installation_root + 'Podfile.lock'
234
- end
235
-
236
- # Returns the path of the default Podfile pods.
237
- #
238
- # @note The file is expected to be named Podfile.default
239
- #
240
- # @return [Pathname]
241
- #
242
- def default_podfile_path
243
- @default_podfile_path ||= templates_dir + 'Podfile.default'
244
- end
245
-
246
- # Returns the path of the default Podfile test pods.
247
- #
248
- # @note The file is expected to be named Podfile.test
249
- #
250
- # @return [Pathname]
251
- #
252
- def default_test_podfile_path
253
- @default_test_podfile_path ||= templates_dir + 'Podfile.test'
254
- end
255
-
256
- # @return [Pathname] The file to use to cache the search data.
257
- #
258
- def search_index_file
259
- cache_root + 'search_index.json'
260
- end
261
-
262
- private
263
-
264
- #-------------------------------------------------------------------------#
265
-
266
- # @!group Private helpers
267
-
268
- # @return [Pathname] The path of the file which contains the user settings.
269
- #
270
- def user_settings_file
271
- home_dir + 'config.yaml'
272
- end
273
-
274
- # Sets the values of the attributes with the given hash.
275
- #
276
- # @param [Hash{String,Symbol => Object}] values_by_key
277
- # The values of the attributes grouped by key.
278
- #
279
- # @return [void]
280
- #
281
- def configure_with(values_by_key)
282
- return unless values_by_key
283
- values_by_key.each do |key, value|
284
- if key.to_sym == :cache_root
285
- value = Pathname.new(value).expand_path
286
- end
287
- instance_variable_set("@#{key}", value)
288
- end
289
- end
290
-
291
- # @return [Array<String>] The filenames that the Podfile can have ordered
292
- # by priority.
293
- #
294
- PODFILE_NAMES = [
295
- 'CocoaPods.podfile.yaml',
296
- 'CocoaPods.podfile',
297
- 'Podfile',
298
- 'Podfile.rb',
299
- ].freeze
300
-
301
- public
302
-
303
- # Returns the path of the Podfile in the given dir if any exists.
304
- #
305
- # @param [Pathname] dir
306
- # The directory where to look for the Podfile.
307
- #
308
- # @return [Pathname] The path of the Podfile.
309
- # @return [Nil] If not Podfile was found in the given dir
310
- #
311
- def podfile_path_in_dir(dir)
312
- PODFILE_NAMES.each do |filename|
313
- candidate = dir + filename
314
- if candidate.file?
315
- return candidate
316
- end
317
- end
318
- nil
319
- end
320
-
321
- # Excludes the given dir from Time Machine backups.
322
- #
323
- # @param [Pathname] dir
324
- # The directory to exclude from Time Machine backups.
325
- #
326
- # @return [void]
327
- #
328
- def exclude_from_backup(dir)
329
- return if Gem.win_platform?
330
- system('tmutil', 'addexclusion', dir.to_s, %i(out err) => File::NULL)
331
- end
332
-
333
- public
334
-
335
- #-------------------------------------------------------------------------#
336
-
337
- # @!group Singleton
338
-
339
- # @return [Config] the current config instance creating one if needed.
340
- #
341
8
  def self.instance
342
9
  @instance ||= new
343
10
  end
344
11
 
345
- # Sets the current config instance. If set to nil the config will be
346
- # recreated when needed.
347
- #
348
- # @param [Config, Nil] the instance.
349
- #
350
- # @return [void]
351
- #
352
12
  class << self
353
13
  attr_writer :instance
354
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
data/lib/lhj/tools.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  require_relative "tools/version"
4
3
 
5
4
  module Lhj
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
@@ -104,6 +104,20 @@ dependencies:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
106
  version: 0.8.0
107
+ - !ruby/object:Gem::Dependency
108
+ name: addressable
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '2.8'
114
+ type: :runtime
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '2.8'
107
121
  - !ruby/object:Gem::Dependency
108
122
  name: faraday-cookie_jar
109
123
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +226,7 @@ files:
212
226
  - lib/lhj/command/local/local.rb
213
227
  - lib/lhj/command/local/local_upload.rb
214
228
  - lib/lhj/command/local/micro_service.rb
229
+ - lib/lhj/command/oss.rb
215
230
  - lib/lhj/command/oss/del.rb
216
231
  - lib/lhj/command/oss/list.rb
217
232
  - lib/lhj/command/oss/upload.rb