erhu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +19 -0
- data/README.md +3 -0
- data/Rakefile +4 -0
- data/exe/erhu +7 -0
- data/lib/erhu/app.rb +130 -0
- data/lib/erhu/init.rb +54 -0
- data/lib/erhu/version.rb +5 -0
- data/lib/erhu.rb +9 -0
- data/sig/erhu.rbs +4 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47f833209095e82b9c3b8a8a4301afd797a371e4aa4749b4607727e8b80eee93
|
4
|
+
data.tar.gz: ca702e35af44e8db93120921990200382b7ff5fba82d01277b0399d743f88ab8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbe906cd9eb69f2a6ab4d4107875e99c63f55bdb6970b7c886b4d80181069ae19d84c54341d94f97f8d92d6301140951b91b1afe6dabc71610b6f4c366ea07a4
|
7
|
+
data.tar.gz: bc5b8af3cfb4a7519c2799e093b1e1b829fab9d5a3bbdff48460f3d56682a15612eb72f03f340130ae34ff6e850e410c506c87a890cf386ba8212b96d1f5d092
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in erhu.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
gem 'tty-platform'
|
10
|
+
gem "tty-command"
|
11
|
+
gem "tty-progressbar"
|
12
|
+
gem "tty-spinner"
|
13
|
+
|
14
|
+
gem "pastel"
|
15
|
+
gem "rugged"
|
16
|
+
|
17
|
+
gem 'faraday'
|
18
|
+
gem 'faraday-follow_redirects'
|
19
|
+
gem 'rubyzip'
|
data/README.md
ADDED
data/Rakefile
ADDED
data/exe/erhu
ADDED
data/lib/erhu/app.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
module Erhu
|
2
|
+
class App
|
3
|
+
attr_accessor :erhufile
|
4
|
+
def initialize(erhufile_path=nil)
|
5
|
+
@erhufile = erhufile_path || File.join(Dir.pwd, "erhuFile")
|
6
|
+
|
7
|
+
@erhu_path = File.join(Dir.pwd, ".erhu")
|
8
|
+
unless Dir.exist?(@erhu_path)
|
9
|
+
FileUtils.mkdir_p(@erhu_path)
|
10
|
+
puts "Created #{@erhu_path}"
|
11
|
+
end
|
12
|
+
@database_path = File.join(@erhu_path, "database.yml")
|
13
|
+
end
|
14
|
+
|
15
|
+
def database
|
16
|
+
if File.exist?(@database_path)
|
17
|
+
@database ||= YAML.load_file(@database_path) || {}
|
18
|
+
else
|
19
|
+
@database ||= {}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def target(path)
|
24
|
+
@target = path
|
25
|
+
unless Dir.exist?(@target)
|
26
|
+
FileUtils.mkdir_p(@target)
|
27
|
+
puts "Created #{@target}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def git(repository_url, branch: nil, name: nil, tag: nil, &block)
|
32
|
+
name = name || File.basename(URI.parse(repository_url).path, '.git')
|
33
|
+
|
34
|
+
info = self.database.fetch(name, {})
|
35
|
+
info.delete(:commit)
|
36
|
+
if info == {repository_url: repository_url, branch: branch, name: name, tag: tag}
|
37
|
+
puts "ignore #{repository_url}"
|
38
|
+
return
|
39
|
+
else
|
40
|
+
FileUtils.rm_rf("#{@target}/#{name}")
|
41
|
+
end
|
42
|
+
|
43
|
+
bar = TTY::ProgressBar.new("clone #{name} [:bar] :percent", total: 50)
|
44
|
+
transfer_progress = lambda do |total_objects, indexed_objects, received_objects, local_objects, total_deltas, indexed_deltas, received_bytes|
|
45
|
+
bar.ratio = indexed_objects / total_objects.to_f
|
46
|
+
end
|
47
|
+
|
48
|
+
repo = Rugged::Repository.clone_at(repository_url,
|
49
|
+
"#{@target}/#{name}",
|
50
|
+
depth: 1,
|
51
|
+
checkout_branch: branch,
|
52
|
+
transfer_progress: transfer_progress
|
53
|
+
)
|
54
|
+
if ! tag.blank? && ! repo.tags[tag].blank?
|
55
|
+
tag_repo = repo.tags[tag]
|
56
|
+
target = tag_repo.target
|
57
|
+
repo.checkout(target.oid, strategy: :safe)
|
58
|
+
end
|
59
|
+
block.call(repo, self) unless block.blank?
|
60
|
+
|
61
|
+
self.database[name] = {repository_url: repository_url,
|
62
|
+
branch: branch, name: name, tag: tag, commit: repo.head.target.oid
|
63
|
+
}
|
64
|
+
rescue => e
|
65
|
+
error! e
|
66
|
+
end
|
67
|
+
|
68
|
+
def package(package_url, name: nil, &block)
|
69
|
+
raise "package url is required" if package_url.blank?
|
70
|
+
raise "name: 'package name' is required" if name.blank?
|
71
|
+
|
72
|
+
package_name = name
|
73
|
+
package_hex = name.unpack('H*').first
|
74
|
+
package_file_path = "#{@erhu_path}/#{package_name}-#{package_hex}.zip"
|
75
|
+
|
76
|
+
if File.exist?(package_file_path)
|
77
|
+
puts "ignored #{package_url}"
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
conn = Faraday.new do |faraday|
|
82
|
+
faraday.use Faraday::FollowRedirects::Middleware
|
83
|
+
faraday.adapter Faraday.default_adapter
|
84
|
+
end
|
85
|
+
|
86
|
+
bar = TTY::ProgressBar.new("Downloading #{package_name} [:bar] :percent", total: 50, interval: 0.1)
|
87
|
+
|
88
|
+
streamed = []
|
89
|
+
response = conn.get(package_url) do |req|
|
90
|
+
req.options.on_data = Proc.new do |chunk, overall_received_bytes, env|
|
91
|
+
content_length = env.response_headers["content-length"]&.to_f
|
92
|
+
bar.ratio = overall_received_bytes / content_length if !content_length.blank? && content_length > 0
|
93
|
+
streamed << chunk
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
File.open(package_file_path, 'w') do |f|
|
98
|
+
f.write(streamed.join)
|
99
|
+
end
|
100
|
+
|
101
|
+
unless block.blank?
|
102
|
+
block.call(package_file_path, self)
|
103
|
+
return
|
104
|
+
end
|
105
|
+
|
106
|
+
self.zip(package_file_path, package_name)
|
107
|
+
end
|
108
|
+
|
109
|
+
def zip(package_file_path, package_name)
|
110
|
+
spinner = TTY::Spinner.new("[:spinner] extracted :title ...", format: :pulse_2)
|
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!")
|
121
|
+
end
|
122
|
+
|
123
|
+
def run
|
124
|
+
instance_eval File.read(@erhufile), @erhufile, 1
|
125
|
+
File.open(@database_path, 'w') do |file|
|
126
|
+
file.write self.database.to_yaml
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/lib/erhu/init.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "tty-command"
|
2
|
+
require "tty-platform"
|
3
|
+
require "tty-progressbar"
|
4
|
+
require "tty-spinner"
|
5
|
+
require 'git'
|
6
|
+
require "pastel"
|
7
|
+
require 'fileutils'
|
8
|
+
require 'rugged'
|
9
|
+
require "uri"
|
10
|
+
require 'yaml'
|
11
|
+
require 'faraday'
|
12
|
+
require 'faraday/follow_redirects'
|
13
|
+
require 'tempfile'
|
14
|
+
require 'zip'
|
15
|
+
|
16
|
+
class Object
|
17
|
+
def blank?
|
18
|
+
respond_to?(:empty?) ? empty? : !self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def platform
|
23
|
+
$platform ||= TTY::Platform.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def pastel
|
27
|
+
$pastel ||= Pastel.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def error!(*args)
|
31
|
+
error = pastel.red.bold.detach
|
32
|
+
puts "error: #{error.(*args)}"
|
33
|
+
end
|
34
|
+
|
35
|
+
class Cmd
|
36
|
+
def initialize(pty: true, uuid: false, color: true)
|
37
|
+
@cmd = TTY::Command.new(pty: pty, uuid: uuid, color: color)
|
38
|
+
end
|
39
|
+
|
40
|
+
def chdir(path)
|
41
|
+
@chdir = path
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def run(*args, &block)
|
46
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
47
|
+
options[:chdir] = options.fetch(:chdir, @chdir)
|
48
|
+
args << options
|
49
|
+
@cmd.run(*args, &block)
|
50
|
+
self
|
51
|
+
rescue => e
|
52
|
+
error! e
|
53
|
+
end
|
54
|
+
end
|
data/lib/erhu/version.rb
ADDED
data/lib/erhu.rb
ADDED
data/sig/erhu.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erhu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MJ
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Erhu 是一个动态可编程的包管理系统
|
14
|
+
email:
|
15
|
+
- tywf91@gmail.com
|
16
|
+
executables:
|
17
|
+
- erhu
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- exe/erhu
|
25
|
+
- lib/erhu.rb
|
26
|
+
- lib/erhu/app.rb
|
27
|
+
- lib/erhu/init.rb
|
28
|
+
- lib/erhu/version.rb
|
29
|
+
- sig/erhu.rbs
|
30
|
+
homepage: https://github.com/mjason/erhu.git
|
31
|
+
licenses: []
|
32
|
+
metadata:
|
33
|
+
homepage_uri: https://github.com/mjason/erhu.git
|
34
|
+
source_code_uri: https://github.com/mjason/erhu.git
|
35
|
+
changelog_uri: https://github.com/mjason/erhu.git
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.6.0
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubygems_version: 3.4.6
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: Erhu 一个包管理
|
55
|
+
test_files: []
|