ZMediumToMarkdown 1.3.9 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ZMediumToMarkdown +5 -3
- data/lib/Helper.rb +42 -52
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71acabe26dd68541c1cc082f19d7d8a2063c6f7ec591e63015fd3129a8ed1deb
|
4
|
+
data.tar.gz: 49b9ae6f7b014cec7a1f46869d41d8b3f2fa6726f90bdc2a3913d8205b8f8fe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c12ceb63459b3e01d4f6df554e8305c5e086c4f02efc17fa974b5ee7059b75f5f47606c0c452ccc8e31a5f056a741d6d7d0d80a8fb4eb136b4c0fe40ca9b35
|
7
|
+
data.tar.gz: 06b3de0e481fdacea12e70b504a7eace9fbe5f18c8a7c15eae15554e70eb7755a67e5644e188e75fd214f0030e08fb2d8d0d6b79c5d3852e4dad029b95a3a763
|
data/bin/ZMediumToMarkdown
CHANGED
@@ -32,7 +32,7 @@ class Main
|
|
32
32
|
end
|
33
33
|
|
34
34
|
opts.on('-n', '--new', 'Update to latest version') do
|
35
|
-
if Helper.
|
35
|
+
if Helper.getRemoteVersionFromGithub() > Helper.getLocalVersion()
|
36
36
|
Helper.downloadLatestVersion()
|
37
37
|
else
|
38
38
|
puts "You're using the latest version :)"
|
@@ -46,9 +46,11 @@ class Main
|
|
46
46
|
Helper.printNewVersionMessageIfExists()
|
47
47
|
end
|
48
48
|
|
49
|
-
opts.on('-v', '--version', 'Print current ZMediumToMarkdown Version') do
|
50
|
-
puts "Version:#{Helper.
|
49
|
+
opts.on('-v', '--version', 'Print current ZMediumToMarkdown Version & Output Path') do
|
50
|
+
puts "Version:#{Helper.getLocalVersion().to_s}"
|
51
51
|
puts "Output Path:#{outputFilePath.getAbsolutePath(nil)}"
|
52
|
+
|
53
|
+
Helper.printNewVersionMessageIfExists()
|
52
54
|
end
|
53
55
|
|
54
56
|
end.parse!
|
data/lib/Helper.rb
CHANGED
@@ -11,20 +11,6 @@ require 'zip'
|
|
11
11
|
|
12
12
|
class Helper
|
13
13
|
|
14
|
-
class Version
|
15
|
-
attr_accessor :major, :minor, :patch
|
16
|
-
|
17
|
-
def initialize(major, minor, patch)
|
18
|
-
@major = major.to_i
|
19
|
-
@minor = minor.to_i
|
20
|
-
@patch = patch.to_i
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_string()
|
24
|
-
"#{major.to_s}.#{minor.to_s}.#{patch.to_s}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
14
|
def self.createDirIfNotExist(dirPath)
|
29
15
|
dirs = dirPath.split("/")
|
30
16
|
currentDir = ""
|
@@ -46,42 +32,48 @@ class Helper
|
|
46
32
|
end
|
47
33
|
|
48
34
|
def self.downloadLatestVersion()
|
49
|
-
|
50
|
-
versions = JSON.parse(Request.URL(apiPath).body).sort { |a,b| b["id"] <=> a["id"] }
|
51
|
-
|
52
|
-
version = nil
|
53
|
-
index = 0
|
54
|
-
while version == nil do
|
55
|
-
thisVersion = versions[index]
|
56
|
-
if thisVersion["prerelease"] == false
|
57
|
-
version = thisVersion
|
58
|
-
next
|
59
|
-
end
|
60
|
-
index += 1
|
61
|
-
end
|
35
|
+
rootPath = File.expand_path('../', File.dirname(__FILE__))
|
62
36
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
37
|
+
if File.file?("#{rootPath}/ZMediumToMarkdown.gemspec")
|
38
|
+
apiPath = 'https://api.github.com/repos/ZhgChgLi/ZMediumToMarkdown/releases'
|
39
|
+
versions = JSON.parse(Request.URL(apiPath).body).sort { |a,b| b["id"] <=> a["id"] }
|
40
|
+
|
41
|
+
version = nil
|
42
|
+
index = 0
|
43
|
+
while version == nil do
|
44
|
+
thisVersion = versions[index]
|
45
|
+
if thisVersion["prerelease"] == false
|
46
|
+
version = thisVersion
|
47
|
+
next
|
48
|
+
end
|
49
|
+
index += 1
|
50
|
+
end
|
51
|
+
|
52
|
+
zipFilePath = version["zipball_url"]
|
53
|
+
puts "Downloading latest version from github..."
|
54
|
+
open('latest.zip', 'wb') do |fo|
|
55
|
+
fo.print open(zipFilePath).read
|
56
|
+
end
|
68
57
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
58
|
+
puts "Unzip..."
|
59
|
+
Zip::File.open("latest.zip") do |zipfile|
|
60
|
+
zipfile.each do |file|
|
61
|
+
fileNames = file.name.split("/")
|
62
|
+
fileNames.shift
|
63
|
+
filePath = fileNames.join("/")
|
64
|
+
if filePath != ''
|
65
|
+
puts "Unzinp...#{filePath}"
|
66
|
+
zipfile.extract(file, filePath) { true }
|
67
|
+
end
|
78
68
|
end
|
79
69
|
end
|
80
|
-
|
81
|
-
File.delete("latest.zip")
|
70
|
+
File.delete("latest.zip")
|
82
71
|
|
83
|
-
|
84
|
-
|
72
|
+
tagName = version["tag_name"]
|
73
|
+
puts "Update to version #{tagName} successfully!"
|
74
|
+
else
|
75
|
+
system("gem update ZMediumToMarkdown")
|
76
|
+
end
|
85
77
|
end
|
86
78
|
|
87
79
|
def self.createPostInfo(postInfo)
|
@@ -97,15 +89,15 @@ class Helper
|
|
97
89
|
end
|
98
90
|
|
99
91
|
def self.printNewVersionMessageIfExists()
|
100
|
-
if Helper.
|
92
|
+
if Helper.getRemoteVersionFromGithub() > Helper.getLocalVersion()
|
101
93
|
puts "##########################################################"
|
102
94
|
puts "##### New Version Available!!! #####"
|
103
|
-
puts "##### Please type `
|
95
|
+
puts "##### Please type `ZMediumToMarkdown -n` to update!! #####"
|
104
96
|
puts "##########################################################"
|
105
97
|
end
|
106
98
|
end
|
107
99
|
|
108
|
-
def self.
|
100
|
+
def self.getLocalVersion()
|
109
101
|
rootPath = File.expand_path('../', File.dirname(__FILE__))
|
110
102
|
|
111
103
|
result = nil
|
@@ -117,8 +109,7 @@ class Helper
|
|
117
109
|
end
|
118
110
|
|
119
111
|
if !result.nil?
|
120
|
-
|
121
|
-
Version.new(versions[0],versions[1],versions[2])
|
112
|
+
Gem::Version.new(result)
|
122
113
|
else
|
123
114
|
nil
|
124
115
|
end
|
@@ -140,8 +131,7 @@ class Helper
|
|
140
131
|
end
|
141
132
|
|
142
133
|
if !tagName.nil?
|
143
|
-
|
144
|
-
Version.new(versions[0],versions[1],versions[2])
|
134
|
+
Gem::Version.new(tagName.downcase.gsub! 'v','')
|
145
135
|
else
|
146
136
|
nil
|
147
137
|
end
|