lhj-tools 0.1.26 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f89a71391e6b1fde204d1f60f8de9f53c9c2fbef9719f71c389be011dc81525f
4
- data.tar.gz: 45381e21de6e280cf07c28bc1beb45da1e81f736d3db455c46f74bd24f80e80c
3
+ metadata.gz: e3afdfb3713841a23a3cd431741fa3a2add9acefdec7c7adeda320eead551100
4
+ data.tar.gz: 56366dee80c13449fef8ca7d06958950796cf580decc9344b2e8504dd8c30c73
5
5
  SHA512:
6
- metadata.gz: 6ae36d611435d72feccbde3e516c692977cb4cbaa3a68dd3c7720ee7b58744bfb0da83d18f32a465e97abc75e6668d1a0a75a1b31e2d32973d18bc3cfcfb5210
7
- data.tar.gz: e2bf9d372ba3f47fbabff55575930cbb5c56c2f987b0714185ccf01058e8b1ba50435326b07640768cc06e6060e9e9f6b3714a2ac397c2a3aa4d093c1854a9e1
6
+ metadata.gz: f7a81af5dd316ea322f40edd1b6c40baf8fea27a397383e392ced1ac2d95325c23c66504a83313ff1998ada24d08b85bcb900e080ae7c956e3ab1c6a1e4af07d
7
+ data.tar.gz: 67ef0b91969fd2d517d0f8ee319e681e61d0da8239d7dc2e6b93a95e39f3914b030a69b455eed66838dc53681e6c8ede3426653c298664c49ff94bd660a82f79
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+ require 'csv'
3
+
4
+ module Lhj
5
+ class Command
6
+ class DuplicateImageset < Command
7
+ self.summary = '查找重复的图片资源'
8
+
9
+ def initialize(argv)
10
+ @current_path = argv.shift_argument || Dir.pwd
11
+ super
12
+ end
13
+
14
+ def handle
15
+ write_to_file
16
+ end
17
+
18
+ def write_to_file
19
+ map = fetch_images
20
+ file = File.join(@current_path, 'images.cvs')
21
+ FileUtils.rm_rf(file) if File.exist?(file)
22
+ CSV.open(file, 'wb:utf-8') do |csv|
23
+ csv << ['所在模块']
24
+ map.each do |k, v|
25
+ csv << [v.join(', ')] if v.length > 1
26
+ end
27
+ end
28
+ end
29
+
30
+ def fetch_images
31
+ image_map = {}
32
+ Dir.glob("#{@current_path}/**/Assets.xcassets/**/*.imageset").each do |f|
33
+ image_name = File.basename(f, '.*')
34
+ models = image_map[image_name.to_sym]
35
+ unless models
36
+ models = []
37
+ image_map[image_name.to_sym] = models
38
+ end
39
+ models << model_name_with_path(f)
40
+ end
41
+ image_map
42
+ end
43
+
44
+ def model_name_with_path(path)
45
+ reg = %r{Code/([^/]*)/}
46
+ reg = %r{Pods/([^/]*)/} if path =~ /Pods/
47
+ ma = path.match(reg)
48
+ ma[1]
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,91 @@
1
+ require 'lhj/config'
2
+ require 'highline'
3
+ require 'lhj/helper/pod_repo_config'
4
+
5
+ module Lhj
6
+ class Command
7
+ # sync code to pod
8
+ class SyncPodVersion < Command
9
+ self.summary = '同步主工程的库的版本号'
10
+
11
+ def initialize(argv)
12
+ @cli = HighLine.new
13
+ super
14
+ end
15
+
16
+ def begin_title
17
+ '读取映射文件~/.lhj/pod_config.yml'
18
+ end
19
+
20
+ def handle
21
+ sync
22
+ end
23
+
24
+ def sync
25
+ config_file = File.join(Lhj::Config.instance.home_dir, 'pod_config.yml')
26
+ arr = YAML.load_file(config_file)
27
+ arr.each_index { |i| puts "#{i}.#{arr[i]['pod']}".yellow }
28
+ idx = @cli.ask('请选择哪一个库同步: '.green).strip.to_i
29
+ pod_name = arr[idx]['pod']
30
+ src = arr[idx]['main_path']
31
+ dest = arr[idx]['pod_path']
32
+
33
+ ma = nil
34
+ Dir.chdir(dest) do
35
+ Dir.glob('*.podspec').each do |p|
36
+ version_line = IO.readlines(p).find{ |line| (/\.version/ =~ line) && (version_regex =~ line) }
37
+ ma = version_line.match(version_regex)
38
+ end
39
+ puts '获取版本号成功'.green
40
+
41
+ end
42
+
43
+ # find src root dir
44
+ src_root_dir = find_src_root_dir(src)
45
+ Dir.chdir(src_root_dir) do
46
+ if ma
47
+ pod_version = ma[0]
48
+ update_all_pod_dependency(pod_name, pod_version)
49
+ puts '更新主工程引用pod版本号成功'.green
50
+ end
51
+ end
52
+ end
53
+
54
+ def find_src_root_dir(src)
55
+ ps = []
56
+ src.scan(%r{(/[^/]*)}).flatten.each do |path|
57
+ path =~ /Code/ ? break : ps << path
58
+ end
59
+ File.join(ps)
60
+ end
61
+
62
+ def version_regex
63
+ /\d+\.\d+\.(\d+)/
64
+ end
65
+
66
+ def update_all_pod_dependency(pod_name, pod_version)
67
+ Dir.glob(%w[./**/*.podspec ./**/Podfile]).each do |p|
68
+ next if /Example/ =~ p || /temp/ =~ p
69
+
70
+ update_main_version(p, pod_name, pod_version)
71
+ end
72
+ end
73
+
74
+ def update_main_version(file, pod_name, pod_version)
75
+ cont = ''
76
+ File.readlines(file).each do |l|
77
+ if (/#{pod_name}/ =~ l) && (/\d+\.\d+\.\d+/ =~ l)
78
+ path = File.absolute_path(file)
79
+ puts "更新文件:#{path}".magenta
80
+ l.scan(/\d+\.\d+\.\d+/).each do |key|
81
+ cont += l.gsub(key, pod_version)
82
+ end
83
+ else
84
+ cont += l.dup
85
+ end
86
+ end
87
+ File.write(file, cont)
88
+ end
89
+ end
90
+ end
91
+ end
data/lib/lhj/command.rb CHANGED
@@ -24,7 +24,9 @@ module Lhj
24
24
  require 'lhj/command/file_path'
25
25
  require 'lhj/command/http'
26
26
  require 'lhj/command/sync_pod_repo'
27
+ require 'lhj/command/sync_pod_version'
27
28
  require 'lhj/command/pgyer_upload'
29
+ require 'lhj/command/duplicate_imageset'
28
30
 
29
31
  self.abstract_command = true
30
32
  self.command = 'lhj'
@@ -19,5 +19,9 @@ module Lhj
19
19
  def self.dingtalk_robot
20
20
  config['dingtalk_robot']
21
21
  end
22
+
23
+ def self.git_branch
24
+ config['git_branch']
25
+ end
22
26
  end
23
27
  end
@@ -8,7 +8,25 @@ module Lhj
8
8
  def self.post_message(title, message)
9
9
  robot_url = Lhj::DingTalkConfig.dingtalk_robot
10
10
  http_body = { 'msgtype' => 'markdown', 'markdown' => { 'title' => title, 'text' => message } }.to_json
11
+ http_post(robot_url, http_body)
12
+ post_branch_message(http_body)
13
+ end
14
+
15
+ def self.post_branch_message(http_body)
16
+ branch_name = fetch_branch
17
+ branch_map = Lhj::DingTalkConfig.git_branch
18
+ branch_robot_key = branch_map[branch_name] if branch_map && branch_name
19
+ branch_robot_url = Lhj::DingTalkConfig.config[branch_robot_key] if branch_robot_key
20
+ http_post(branch_robot_url, http_body) if branch_robot_url
21
+ end
22
+
23
+ def self.http_post(robot_url, http_body)
11
24
  Net::HTTP.post(URI(robot_url), http_body, 'Content-Type' => 'application/json')
12
25
  end
26
+
27
+ def self.fetch_branch
28
+ name = Lhj::Actions.git_branch || ''
29
+ name.split('/').last
30
+ end
13
31
  end
14
32
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'lhj/config'
4
+
5
+ module Lhj
6
+ # Git BranchFeature Config
7
+ class GitBranchFeatureConfig
8
+
9
+ CONFIG_NAME = 'git_branch_feature.yml'
10
+
11
+ def self.config_file
12
+ File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
13
+ end
14
+
15
+ def self.config
16
+ @yaml ||= YAML.load_file(config_file)
17
+ end
18
+
19
+ def self.feature(branch)
20
+ config[branch] if config
21
+ end
22
+ end
23
+ end
@@ -1,9 +1,10 @@
1
1
  require 'lhj/helper/team_member_config'
2
+ require 'lhj/helper/git_branch_feature_config'
2
3
 
3
4
  module Lhj
4
5
  # log helper
5
6
  class LogHelper
6
- attr_reader :branch, :env, :log
7
+ attr_reader :branch, :env, :log, :feature
7
8
 
8
9
  def self.instance
9
10
  @instance ||= new
@@ -13,6 +14,7 @@ module Lhj
13
14
  @branch = fetch_branch
14
15
  @env = fetch_env(env)
15
16
  @log = fetch_log
17
+ @feature = fetch_feature
16
18
  save_last_commit_hash
17
19
  render_template
18
20
  end
@@ -22,6 +24,10 @@ module Lhj
22
24
  name.split('/').last
23
25
  end
24
26
 
27
+ def fetch_feature
28
+ Lhj::GitBranchFeatureConfig.feature(@branch)
29
+ end
30
+
25
31
  def fetch_env(env)
26
32
  case env
27
33
  when :release
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'lhj/config'
4
+
5
+ module Lhj
6
+ # Ding Talk Config
7
+ class VikaConfig
8
+
9
+ CONFIG_NAME = 'vika_config.yml'
10
+
11
+ def self.config_file
12
+ File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
13
+ end
14
+
15
+ def self.config
16
+ @yaml ||= YAML.load_file(config_file)
17
+ end
18
+
19
+ def self.datasheet_id
20
+ config['datasheet_id']
21
+ end
22
+
23
+ def self.view_id
24
+ config['view_id']
25
+ end
26
+
27
+ def self.record_id
28
+ config['record_id']
29
+ end
30
+
31
+ def self.authorization
32
+ config['authorization']
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ require 'lhj/helper/vika_config'
2
+ require 'json'
3
+ require 'lhj/config'
4
+
5
+ module Lhj
6
+ # pgyer upload
7
+ class VikaHelper
8
+
9
+ RECORDS_API_URL = 'https://api.vika.cn/fusion/v1/datasheets/dstmDXBooTe1Wj0QqE/views'.freeze
10
+
11
+ def self.records
12
+ url = URI(RECORDS_API_URL)
13
+
14
+ https = Net::HTTP.new(url.host, url.port)
15
+ https.use_ssl = true
16
+
17
+ request = Net::HTTP::Get.new(url)
18
+ request["Authorization"] = "Bearer usk3cvEicoXG84y32J61BRg"
19
+
20
+ response = https.request(request)
21
+ File.write(File.join(Lhj::Config.instance.home_dir, 'vika_all_records.json'), JSON.parse(response.read_body))
22
+ end
23
+
24
+ def self.all_records
25
+ map = {'v6.2.0' => '月底发版分支'}
26
+ puts map.to_yaml
27
+ end
28
+ end
29
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.26"
5
+ VERSION = "0.1.29"
6
6
  end
7
7
  end
data/lib/lhj/tools.rb CHANGED
@@ -12,12 +12,14 @@ module Lhj
12
12
  require 'lhj/ui/ui'
13
13
  require 'lhj/config'
14
14
  require 'lhj/helper/pod_repo_config'
15
+ require 'lhj/helper/git_branch_feature_config'
15
16
  require 'lhj/helper/pgyer_helper'
16
17
  require 'lhj/helper/dingtalk_helper'
17
18
  require 'lhj/helper/tb_helper'
18
19
  require 'lhj/action/sh_helper'
19
20
  require 'lhj/helper/git_helper'
20
21
  require 'lhj/helper/log_helper'
22
+ require 'lhj/helper/vika_helper'
21
23
 
22
24
  class Error < StandardError; end
23
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -296,6 +296,7 @@ files:
296
296
  - lib/lhj/command.rb
297
297
  - lib/lhj/command/config.rb
298
298
  - lib/lhj/command/config/info.rb
299
+ - lib/lhj/command/duplicate_imageset.rb
299
300
  - lib/lhj/command/file_path.rb
300
301
  - lib/lhj/command/head_import.rb
301
302
  - lib/lhj/command/http.rb
@@ -314,6 +315,7 @@ files:
314
315
  - lib/lhj/command/rename_image.rb
315
316
  - lib/lhj/command/reverse_import.rb
316
317
  - lib/lhj/command/sync_pod_repo.rb
318
+ - lib/lhj/command/sync_pod_version.rb
317
319
  - lib/lhj/command/template.rb
318
320
  - lib/lhj/command/trans.rb
319
321
  - lib/lhj/command/view.rb
@@ -329,6 +331,7 @@ files:
329
331
  - lib/lhj/env.rb
330
332
  - lib/lhj/helper/dingtalk_config.rb
331
333
  - lib/lhj/helper/dingtalk_helper.rb
334
+ - lib/lhj/helper/git_branch_feature_config.rb
332
335
  - lib/lhj/helper/git_helper.rb
333
336
  - lib/lhj/helper/local_config.rb
334
337
  - lib/lhj/helper/log_helper.rb
@@ -341,6 +344,8 @@ files:
341
344
  - lib/lhj/helper/tb_helper.rb
342
345
  - lib/lhj/helper/team_member_config.rb
343
346
  - lib/lhj/helper/trans_helper.rb
347
+ - lib/lhj/helper/vika_config.rb
348
+ - lib/lhj/helper/vika_helper.rb
344
349
  - lib/lhj/jenkins/client.rb
345
350
  - lib/lhj/jenkins/exceptions.rb
346
351
  - lib/lhj/jenkins/job.rb