synvert 0.10.0 → 0.10.1
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 +4 -4
- data/.travis.yml +4 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/bin/synvert +2 -2
- data/lib/synvert.rb +2 -1
- data/lib/synvert/cli.rb +56 -45
- data/lib/synvert/snippet.rb +2 -1
- data/lib/synvert/version.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/synvert/snippet_spec.rb +8 -3
- data/synvert.gemspec +4 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ccc2f378bbcddf7fe052b577b594bd832672b7cca486786ee0e07611d07d87
|
4
|
+
data.tar.gz: 5ba5f7e67f79dc322e73034f699d76a3c3020bbe7090991d23e947ca25278353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ad3896b92637a657e5b453a492d6620b108a33d98470eecc71850de266bfb9cf544c82780bb90f1556fcd0fe9a01ee362f953a186e1b50bc437dd8263558b83
|
7
|
+
data.tar.gz: d84667fea189b0d4c0f249e2889b87946612baa103a007fb7bbcddecb88af6cb7308b0efbc2ebc63997675b5f698400230e1209b1bcf7d225f5ce00f5ff380fb
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/synvert
CHANGED
data/lib/synvert.rb
CHANGED
data/lib/synvert/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'optparse'
|
3
4
|
|
4
5
|
module Synvert
|
@@ -14,7 +15,7 @@ module Synvert
|
|
14
15
|
|
15
16
|
# Initialize a CLI.
|
16
17
|
def initialize
|
17
|
-
@options = {command: 'run', custom_snippet_paths: [], snippet_names: []}
|
18
|
+
@options = { command: 'run', custom_snippet_paths: [], snippet_names: [] }
|
18
19
|
end
|
19
20
|
|
20
21
|
# Run the CLI.
|
@@ -37,7 +38,8 @@ module Synvert
|
|
37
38
|
show_rewriter
|
38
39
|
when 'sync'
|
39
40
|
sync_snippets
|
40
|
-
else
|
41
|
+
else
|
42
|
+
# run
|
41
43
|
load_rewriters
|
42
44
|
@options[:snippet_names].each do |snippet_name|
|
43
45
|
puts "===== #{snippet_name} started ====="
|
@@ -67,47 +69,56 @@ module Synvert
|
|
67
69
|
|
68
70
|
# Run OptionParser to parse arguments.
|
69
71
|
def run_option_parser(args)
|
70
|
-
optparse =
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
72
|
+
optparse =
|
73
|
+
OptionParser.new do |opts|
|
74
|
+
opts.banner = 'Usage: synvert [project_path]'
|
75
|
+
opts.on '-d',
|
76
|
+
'--load SNIPPET_PATHS',
|
77
|
+
'load custom snippets, snippet paths can be local file path or remote http url' do |snippet_paths|
|
78
|
+
@options[:custom_snippet_paths] = snippet_paths.split(',').map(&:strip)
|
79
|
+
end
|
80
|
+
opts.on '-l', '--list', 'list all available snippets' do
|
81
|
+
@options[:command] = 'list'
|
82
|
+
end
|
83
|
+
opts.on '-o', '--open SNIPPET_NAME', 'Open a snippet' do |snippet_name|
|
84
|
+
@options[:command] = 'open'
|
85
|
+
@options[:snippet_name] = snippet_name
|
86
|
+
end
|
87
|
+
opts.on '-q', '--query QUERY', 'query specified snippets' do |query|
|
88
|
+
@options[:command] = 'query'
|
89
|
+
@options[:query] = query
|
90
|
+
end
|
91
|
+
opts.on '--skip FILE_PATTERNS',
|
92
|
+
'skip specified files or directories, separated by comma, e.g. app/models/post.rb,vendor/plugins/**/*.rb' do |file_patterns|
|
93
|
+
@options[:skip_file_patterns] = file_patterns.split(',')
|
94
|
+
end
|
95
|
+
opts.on '-s',
|
96
|
+
'--show SNIPPET_NAME',
|
97
|
+
'show specified snippet description, SNIPPET_NAME is combined by group and name, e.g. ruby/new_hash_syntax' do |snippet_name|
|
98
|
+
@options[:command] = 'show'
|
99
|
+
@options[:snippet_name] = snippet_name
|
100
|
+
end
|
101
|
+
opts.on '--sync', 'sync snippets' do
|
102
|
+
@options[:command] = 'sync'
|
103
|
+
end
|
104
|
+
opts.on '-r',
|
105
|
+
'--run SNIPPET_NAMES',
|
106
|
+
'run specified snippets, each SNIPPET_NAME is combined by group and name, e.g. ruby/new_hash_syntax,ruby/new_lambda_syntax' do |snippet_names|
|
107
|
+
@options[:snippet_names] = snippet_names.split(',').map(&:strip)
|
108
|
+
end
|
109
|
+
opts.on '-v', '--version', 'show this version' do
|
110
|
+
puts Core::VERSION
|
111
|
+
exit
|
112
|
+
end
|
102
113
|
end
|
103
|
-
end
|
104
114
|
paths = optparse.parse(args)
|
105
115
|
Core::Configuration.path = paths.first || Dir.pwd
|
106
116
|
if @options[:skip_file_patterns] && !@options[:skip_file_patterns].empty?
|
107
|
-
skip_files =
|
108
|
-
|
109
|
-
|
110
|
-
|
117
|
+
skip_files =
|
118
|
+
@options[:skip_file_patterns].map do |file_pattern|
|
119
|
+
full_file_pattern = File.join(Core::Configuration.path, file_pattern)
|
120
|
+
Dir.glob(full_file_pattern)
|
121
|
+
end.flatten
|
111
122
|
Core::Configuration.skip_files = skip_files
|
112
123
|
end
|
113
124
|
end
|
@@ -117,14 +128,14 @@ module Synvert
|
|
117
128
|
Dir.glob(File.join(default_snippets_path, 'lib/**/*.rb')).each { |file| require file }
|
118
129
|
|
119
130
|
@options[:custom_snippet_paths].each do |snippet_path|
|
120
|
-
if
|
131
|
+
if /^http/.match?(snippet_path)
|
121
132
|
uri = URI.parse snippet_path
|
122
133
|
eval(uri.read)
|
123
134
|
else
|
124
135
|
require snippet_path
|
125
136
|
end
|
126
137
|
end
|
127
|
-
rescue
|
138
|
+
rescue StandardError
|
128
139
|
FileUtils.rm_rf default_snippets_path
|
129
140
|
retry
|
130
141
|
end
|
@@ -136,7 +147,7 @@ module Synvert
|
|
136
147
|
else
|
137
148
|
Core::Rewriter.availables.each do |group, rewriters|
|
138
149
|
puts group
|
139
|
-
rewriters.each do |name,
|
150
|
+
rewriters.each do |name, _rewriter|
|
140
151
|
puts ' ' + name
|
141
152
|
end
|
142
153
|
end
|
@@ -162,12 +173,12 @@ module Synvert
|
|
162
173
|
Core::Rewriter.availables.each do |group, rewriters|
|
163
174
|
if group.include? @options[:query]
|
164
175
|
puts group
|
165
|
-
rewriters.each do |name,
|
176
|
+
rewriters.each do |name, _rewriter|
|
166
177
|
puts ' ' + name
|
167
178
|
end
|
168
179
|
elsif rewriters.keys.any? { |name| name.include? @options[:query] }
|
169
180
|
puts group
|
170
|
-
rewriters.each do |name,
|
181
|
+
rewriters.each do |name, _rewriter|
|
171
182
|
puts ' ' + name if name.include?(@options[:query])
|
172
183
|
end
|
173
184
|
end
|
data/lib/synvert/snippet.rb
CHANGED
data/lib/synvert/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert
|
@@ -8,7 +10,9 @@ module Synvert
|
|
8
10
|
|
9
11
|
describe 'sync' do
|
10
12
|
it 'git clones snippets' do
|
11
|
-
expect(Kernel).to receive(:system).with(
|
13
|
+
expect(Kernel).to receive(:system).with(
|
14
|
+
"git clone https://github.com/xinminlabs/synvert-snippets.git #{snippets_path}"
|
15
|
+
)
|
12
16
|
snippet.sync
|
13
17
|
end
|
14
18
|
|
@@ -22,8 +26,9 @@ module Synvert
|
|
22
26
|
|
23
27
|
describe 'fetch_core_version' do
|
24
28
|
it 'gets remote version' do
|
25
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/synvert-core.json').
|
26
|
-
|
29
|
+
stub_request(:get, 'https://rubygems.org/api/v1/versions/synvert-core.json').to_return(
|
30
|
+
body: '[{"number":"0.4.2"}]'
|
31
|
+
)
|
27
32
|
expect(snippet.fetch_core_version).to eq '0.4.2'
|
28
33
|
end
|
29
34
|
end
|
data/synvert.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'synvert/version'
|
5
6
|
|
@@ -17,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ['lib']
|
21
|
+
spec.post_install_message = 'Please run `synvert --sync` first to sync snippets remotely.'
|
20
22
|
|
21
23
|
spec.add_runtime_dependency 'synvert-core', '>= 0.19.0'
|
22
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: synvert-core
|
@@ -108,7 +108,7 @@ homepage: https://github.com/xinminlabs/synvert
|
|
108
108
|
licenses:
|
109
109
|
- MIT
|
110
110
|
metadata: {}
|
111
|
-
post_install_message:
|
111
|
+
post_install_message: Please run `synvert --sync` first to sync snippets remotely.
|
112
112
|
rdoc_options: []
|
113
113
|
require_paths:
|
114
114
|
- lib
|