erhu 0.1.6 → 0.1.8

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: 67f03be8e9f501c9c5aeabb72e8c1c02b8af4071ae7202650b8eb613e7ef9d89
4
- data.tar.gz: 0b1e04f538c108856d3cce11f841bcf65e291a8f4ba27aa805717cf63ccdb0b0
3
+ metadata.gz: aece6b3c18dbb9b1584bc2d2adb64afe0ba93c39a724260309eb9bba98d77ce7
4
+ data.tar.gz: e8f1179dfebb0dbcb879b52f345195834be61ffa91c86ffbe476c14e1bd5c23c
5
5
  SHA512:
6
- metadata.gz: d64097dfa0d355254252925da1d7353807a5e356662f99bf4152ecc80bfac2197c52f11bde20e603cb41244ace8aebb20465c7543ed2b6d885af94d77fb63a90
7
- data.tar.gz: 3ed530e799f073492f0f007a982a0e202a10f59356f798949633f8d7946514c6260da6e928d605026508c4a7eca18f3abfcba132d93822e7778cdd5e75d07b50
6
+ metadata.gz: 0c435ed69d9ad03f55d1d25eefd24330993a39bc1507129f26e1dbfe2bc6b1e9a67154eaa5aa8d822d25aff97e4bcfdfba6b4abe0cf025d6276326ca7b68c7a0
7
+ data.tar.gz: 01224f69ceeb3ceb76ce7b959e5e57568b56dea97184e4980016c447ddd12ae7cb1f98892e7e6dcdf2b7cfcd56fd86f801d4d5099917692ced6bcc2e519a3e41
data/ErhuFile ADDED
@@ -0,0 +1,3 @@
1
+ target "./thirdparty"
2
+ # git "https://github.com/Tencent/rapidjson", tag: "v1.1.0"
3
+ package "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.15.zip", name: "cjson"
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- erhu (0.1.4)
5
- faraday (~> 2.7, >= 2.7.4)
6
- faraday-follow_redirects (~> 0.3.0)
4
+ erhu (0.1.7)
5
+ down (~> 5.0)
7
6
  git (~> 1.18)
7
+ http (~> 5.0)
8
8
  pastel (~> 0.8.0)
9
9
  rubyzip (~> 2.3, >= 2.3.2)
10
10
  tty-command (~> 0.10.1)
@@ -17,26 +17,33 @@ GEM
17
17
  specs:
18
18
  addressable (2.8.1)
19
19
  public_suffix (>= 2.0.2, < 6.0)
20
- coderay (1.1.3)
21
- faraday (2.7.4)
22
- faraday-net_http (>= 2.0, < 3.1)
23
- ruby2_keywords (>= 0.0.4)
24
- faraday-follow_redirects (0.3.0)
25
- faraday (>= 1, < 3)
26
- faraday-net_http (3.0.2)
20
+ domain_name (0.5.20190701)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ down (5.4.0)
23
+ addressable (~> 2.8)
24
+ ffi (1.15.5)
25
+ ffi-compiler (1.0.1)
26
+ ffi (>= 1.0.0)
27
+ rake
27
28
  git (1.18.0)
28
29
  addressable (~> 2.8)
29
30
  rchardet (~> 1.8)
30
- method_source (1.0.0)
31
+ http (5.1.1)
32
+ addressable (~> 2.8)
33
+ http-cookie (~> 1.0)
34
+ http-form_data (~> 2.2)
35
+ llhttp-ffi (~> 0.4.0)
36
+ http-cookie (1.0.5)
37
+ domain_name (~> 0.5)
38
+ http-form_data (2.3.0)
39
+ llhttp-ffi (0.4.0)
40
+ ffi-compiler (~> 1.0)
41
+ rake (~> 13.0)
31
42
  pastel (0.8.0)
32
43
  tty-color (~> 0.5)
33
- pry (0.14.2)
34
- coderay (~> 1.1)
35
- method_source (~> 1.0)
36
44
  public_suffix (5.0.1)
37
45
  rake (13.0.6)
38
46
  rchardet (1.8.0)
39
- ruby2_keywords (0.0.5)
40
47
  rubyzip (2.3.2)
41
48
  strings-ansi (0.2.0)
42
49
  tty-color (0.6.0)
@@ -52,6 +59,9 @@ GEM
52
59
  tty-screen (0.8.1)
53
60
  tty-spinner (0.9.3)
54
61
  tty-cursor (~> 0.7)
62
+ unf (0.1.4)
63
+ unf_ext
64
+ unf_ext (0.0.8.2)
55
65
  unicode-display_width (2.4.2)
56
66
 
57
67
  PLATFORMS
@@ -61,7 +71,6 @@ PLATFORMS
61
71
 
62
72
  DEPENDENCIES
63
73
  erhu!
64
- pry
65
74
  rake (~> 13.0)
66
75
 
67
76
  BUNDLED WITH
data/README.md CHANGED
@@ -7,8 +7,6 @@
7
7
  gem install erhu
8
8
  ```
9
9
 
10
- 注意:你的系统必须有cmake和pkg-config,mac用户可以用homebrew安装
11
-
12
10
  ## 如何使用
13
11
 
14
12
  在根目录里面建立`ErhuFile`, 当前也可以使用`erhu init`用于拉取依赖
@@ -24,4 +22,57 @@ package "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.15.zip", nam
24
22
 
25
23
  然后就在项目目录中使用 erhu 命令即可拉取对应的代码
26
24
 
27
- 示例项目可以看 example 目录
25
+ 示例项目可以看 demo 目录
26
+
27
+ ## 注意事项
28
+ 1. 请不要随便用git来做依赖管理
29
+ 2. package只支持zip压缩包,暂时没有计划做其他
30
+ 3. ErhuFile着色采用ruby编程语言即可,同时整个文件均可执行ruby脚本
31
+ 4. 判断系统安装对应的包,请看高级用法的系统判断
32
+ 5. 下载后可以有高级使用办法,比如进入里面继续cmake等等,具体请看高级用法的安装后处理
33
+
34
+ ## 高级用法
35
+
36
+ ### 系统判断
37
+
38
+ ```ruby
39
+ # platform.windows? # => false
40
+ # platform.unix? # => true
41
+ # platform.linux? # => false
42
+ # platform.mac? # => true
43
+ if platform.windows?
44
+ package "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.15.zip", name: "cjson"
45
+ end
46
+ ```
47
+
48
+ ### 安装后处理
49
+ > 警告一般不建议这么做,而是采用Rakefile的方式来做处理
50
+
51
+ ```ruby
52
+ # 方法定义 git(repository_url, branch: nil, name: nil, tag: nil, &block)
53
+ git "https://github.com/Tencent/rapidjson", tag: "v1.1.0" do |repo, env|
54
+ # repo 的接口请看 https://rubydoc.info/gems/git/Git/Base
55
+ # env 的接口请看 https://github.com/mjason/erhu/blob/main/lib/erhu/app.rb
56
+ # 还有一些高级接口 https://github.com/mjason/erhu/blob/main/lib/erhu/init.rb
57
+ end
58
+
59
+ # 方法定义 package(package_url, name: nil, &block)
60
+ package "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.15.zip", name: "cjson" do |package_file_path, env|
61
+ # package_file_path 下载包的地址,String类型,你得自己解压
62
+ # env 同上
63
+
64
+ # 解压示例
65
+ #
66
+ # zip_file_path: String类型,包含要解压缩的zip文件的路径
67
+ # target_directory: String类型,包含要提取zip文件的位置
68
+ #
69
+ # 该方法使用TTY::Spinner库来显示进度条,并通过调用Zip::File库中的方法来解压缩zip文件。
70
+ # 它迭代zip文件中的每个条目,并使用条目名称中的信息来构造目标路径。
71
+ unzip(package_file_path, "./libs/cjson")
72
+ end
73
+ ```
74
+
75
+ 具体使用案例,可以查看项目里的 demo 目录
76
+
77
+ ## 总结
78
+ 这是一个很灵活的包管理,希望你用的开心,开源协议MIT
@@ -0,0 +1,10 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+
3
+ project(Erhu)
4
+
5
+ add_executable(${PROJECT_NAME} main.cpp)
6
+
7
+ # 设置编译产物的输出目录
8
+ set_target_properties(${PROJECT_NAME} PROPERTIES
9
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/target"
10
+ )
data/demo/ErhuFile ADDED
@@ -0,0 +1,3 @@
1
+ target "./thirdparty"
2
+ git "https://github.com/Tencent/rapidjson", tag: "v1.1.0"
3
+ # package "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.15.zip", name: "cjson"
data/demo/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # gem "rails"
6
+ gem 'tty-platform'
7
+ gem "tty-command"
8
+ gem "tty-progressbar"
9
+ gem "tty-spinner"
10
+ gem "pry"
11
+
12
+ gem "pastel"
13
+ gem "rugged"
14
+
15
+ gem 'faraday'
16
+ gem 'faraday-follow_redirects'
17
+ gem 'rubyzip'
data/demo/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ coderay (1.1.3)
5
+ faraday (2.7.4)
6
+ faraday-net_http (>= 2.0, < 3.1)
7
+ ruby2_keywords (>= 0.0.4)
8
+ faraday-follow_redirects (0.3.0)
9
+ faraday (>= 1, < 3)
10
+ faraday-net_http (3.0.2)
11
+ method_source (1.0.0)
12
+ pastel (0.8.0)
13
+ tty-color (~> 0.5)
14
+ pry (0.14.2)
15
+ coderay (~> 1.1)
16
+ method_source (~> 1.0)
17
+ ruby2_keywords (0.0.5)
18
+ rubyzip (2.3.2)
19
+ rugged (1.6.2)
20
+ strings-ansi (0.2.0)
21
+ tty-color (0.6.0)
22
+ tty-command (0.10.1)
23
+ pastel (~> 0.8)
24
+ tty-cursor (0.7.1)
25
+ tty-platform (0.3.0)
26
+ tty-progressbar (0.18.2)
27
+ strings-ansi (~> 0.2)
28
+ tty-cursor (~> 0.7)
29
+ tty-screen (~> 0.8)
30
+ unicode-display_width (>= 1.6, < 3.0)
31
+ tty-screen (0.8.1)
32
+ tty-spinner (0.9.3)
33
+ tty-cursor (~> 0.7)
34
+ unicode-display_width (2.4.2)
35
+
36
+ PLATFORMS
37
+ arm64-darwin-22
38
+
39
+ DEPENDENCIES
40
+ faraday
41
+ faraday-follow_redirects
42
+ pastel
43
+ pry
44
+ rubyzip
45
+ rugged
46
+ tty-command
47
+ tty-platform
48
+ tty-progressbar
49
+ tty-spinner
50
+
51
+ BUNDLED WITH
52
+ 2.4.6
data/demo/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "erhu"
2
+
3
+ task :build do |t|
4
+ Cmd.new().chdir("./build")
5
+ .run("cmake", "..")
6
+ .run("make")
7
+ end
8
+
9
+ task run: [:build] do |t|
10
+ Cmd.new().chdir("./target").run("./Erhu")
11
+ end
data/demo/main.cpp ADDED
@@ -0,0 +1,8 @@
1
+ #include <iostream>
2
+
3
+ using namespace std;
4
+
5
+ int main(int argc, char* argv[]) {
6
+ cout << "使用erhu来做包管理是你的第一选择" << endl;
7
+ return 0;
8
+ }
data/erhu.gemspec CHANGED
@@ -36,8 +36,8 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'tty-spinner', '~> 0.9.3'
37
37
  spec.add_dependency 'pastel', '~> 0.8.0'
38
38
  spec.add_dependency 'git', '~> 1.18'
39
- spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.4'
40
- spec.add_dependency 'faraday-follow_redirects', '~> 0.3.0'
39
+ spec.add_dependency "down", "~> 5.0"
40
+ spec.add_dependency "http", "~> 5.0"
41
41
  spec.add_dependency 'rubyzip', '~> 2.3', '>= 2.3.2'
42
42
 
43
43
  # Uncomment to register a new dependency of your gem
data/lib/erhu/app.rb CHANGED
@@ -2,17 +2,17 @@ module Erhu
2
2
  class App
3
3
  attr_accessor :erhufile
4
4
  def initialize(erhufile_path=nil)
5
- @erhufile = erhufile_path || File.join(Dir.pwd, "erhuFile")
5
+ @erhufile = erhufile_path || File.join(Dir.pwd, "ErhuFile")
6
6
 
7
7
  @erhu_path = File.join(Dir.pwd, ".erhu")
8
8
  unless Dir.exist?(@erhu_path)
9
9
  FileUtils.mkdir_p(@erhu_path)
10
10
  puts "Created #{@erhu_path}"
11
- end
11
+ end
12
12
  @database_path = File.join(@erhu_path, "database.yml")
13
13
  end
14
14
 
15
- def database
15
+ def database
16
16
  if File.exist?(@database_path)
17
17
  @database ||= YAML.load_file(@database_path) || {}
18
18
  else
@@ -77,25 +77,19 @@ module Erhu
77
77
  return
78
78
  end
79
79
 
80
- conn = Faraday.new do |faraday|
81
- faraday.use Faraday::FollowRedirects::Middleware
82
- faraday.adapter Faraday.default_adapter
83
- end
84
-
85
- bar = TTY::ProgressBar.new("Downloading #{package_name} [:bar] :percent", total: 50, interval: 0.1)
86
-
87
- streamed = []
88
- response = conn.get(package_url) do |req|
89
- req.options.on_data = Proc.new do |chunk, overall_received_bytes, env|
90
- content_length = env.response_headers["content-length"]&.to_f
91
- bar.ratio = overall_received_bytes / content_length if !content_length.blank? && content_length > 0
92
- streamed << chunk
93
- end
94
- end
80
+ bar = TTY::ProgressBar.new("downloading #{package_name} :percent [:bar]", total: 50)
81
+ total_size = 0
95
82
 
96
- File.open(package_file_path, 'w') do |f|
97
- f.write(streamed.join)
98
- end
83
+ http.download package_url, destination: package_file_path,
84
+ content_length_proc: -> (content_length) {
85
+ total_size = content_length
86
+ },
87
+ progress_proc: -> (progress) {
88
+ if total_size > 0
89
+ bar.ratio = progress / total_size.to_f
90
+ end
91
+ }
92
+ bar.finish
99
93
 
100
94
  unless block.blank?
101
95
  block.call(package_file_path, self)
@@ -106,18 +100,7 @@ module Erhu
106
100
  end
107
101
 
108
102
  def zip(package_file_path, package_name)
109
- spinner = TTY::Spinner.new("[:spinner] extracted :title ...")
110
- spinner.auto_spin
111
-
112
- Zip::File.open(package_file_path) do |zip_file|
113
- zip_file.each do |entry|
114
- dest_path = File.join(@target, package_name, entry.name.split('/')[1..-1].join('/'))
115
- entry.extract(dest_path)
116
- spinner.update title: entry.name
117
- end
118
- end
119
- spinner.update title: "ALL"
120
- spinner.stop("Done!")
103
+ unzip(package_file_path, File.join(@target, package_name))
121
104
  end
122
105
 
123
106
  def run
data/lib/erhu/init.rb CHANGED
@@ -6,12 +6,11 @@ require "pastel"
6
6
  require 'fileutils'
7
7
  require "uri"
8
8
  require 'yaml'
9
- require 'faraday'
10
- require 'faraday/follow_redirects'
11
9
  require 'tempfile'
12
10
  require 'zip'
13
11
  require 'git'
14
12
  require 'optparse'
13
+ require "down/http"
15
14
 
16
15
  class Object
17
16
  def blank?
@@ -37,6 +36,25 @@ def warn!(*args)
37
36
  puts "Warning: #{warning.(*args)}"
38
37
  end
39
38
 
39
+ def unzip(zip_file_path, target_directory)
40
+ spinner = TTY::Spinner.new("[:spinner] extracted :title ...")
41
+ spinner.auto_spin
42
+
43
+ Zip::File.open(zip_file_path) do |zip_file|
44
+ zip_file.each do |entry|
45
+ dest_path = File.join(target_directory, entry.name.split('/')[1..-1].join('/'))
46
+ entry.extract(dest_path)
47
+ spinner.update title: entry.name
48
+ end
49
+ end
50
+ spinner.update title: "ALL"
51
+ spinner.stop("Done!")
52
+ end
53
+
54
+ def http
55
+ http = Down::Http.new
56
+ end
57
+
40
58
  class Cmd
41
59
  def initialize(pty: true, uuid: false, color: true, printer: :pretty)
42
60
  @cmd = TTY::Command.new(pty: pty, uuid: uuid, color: color, pretty: printer)
data/lib/erhu/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Erhu
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erhu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - MJ
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-25 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-platform
@@ -95,39 +95,33 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.18'
97
97
  - !ruby/object:Gem::Dependency
98
- name: faraday
98
+ name: down
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '2.7'
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 2.7.4
103
+ version: '5.0'
107
104
  type: :runtime
108
105
  prerelease: false
109
106
  version_requirements: !ruby/object:Gem::Requirement
110
107
  requirements:
111
108
  - - "~>"
112
109
  - !ruby/object:Gem::Version
113
- version: '2.7'
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: 2.7.4
110
+ version: '5.0'
117
111
  - !ruby/object:Gem::Dependency
118
- name: faraday-follow_redirects
112
+ name: http
119
113
  requirement: !ruby/object:Gem::Requirement
120
114
  requirements:
121
115
  - - "~>"
122
116
  - !ruby/object:Gem::Version
123
- version: 0.3.0
117
+ version: '5.0'
124
118
  type: :runtime
125
119
  prerelease: false
126
120
  version_requirements: !ruby/object:Gem::Requirement
127
121
  requirements:
128
122
  - - "~>"
129
123
  - !ruby/object:Gem::Version
130
- version: 0.3.0
124
+ version: '5.0'
131
125
  - !ruby/object:Gem::Dependency
132
126
  name: rubyzip
133
127
  requirement: !ruby/object:Gem::Requirement
@@ -156,10 +150,17 @@ executables:
156
150
  extensions: []
157
151
  extra_rdoc_files: []
158
152
  files:
153
+ - ErhuFile
159
154
  - Gemfile
160
155
  - Gemfile.lock
161
156
  - README.md
162
157
  - Rakefile
158
+ - demo/CMakeLists.txt
159
+ - demo/ErhuFile
160
+ - demo/Gemfile
161
+ - demo/Gemfile.lock
162
+ - demo/Rakefile
163
+ - demo/main.cpp
163
164
  - erhu.gemspec
164
165
  - exe/erhu
165
166
  - lib/erhu.rb