synvert 0.10.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/lib/synvert/cli.rb +92 -19
- data/lib/synvert/snippet.rb +5 -5
- data/lib/synvert/version.rb +1 -1
- data/spec/synvert/snippet_spec.rb +9 -9
- data/synvert.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ccf2486b37c9a73a8f014901e152ff5229bbcac7a35922d6cb5811318c9621
|
4
|
+
data.tar.gz: 0d9a816901fd978e550f976a6678513a516872f8c41ec3c1a1f21751e8b0a781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eafeb5f93d44b239f1c48dda8be7426491d126adb1b3ba4a7a17f16b93ec9b48b79db1af3be89a60469891b5b25c4afd31326fc1ef11094fc05d24e0e118f4bc
|
7
|
+
data.tar.gz: 37c977345a20633089077628dc58d1db3dc7a382f64550f42aa912450437886555f2b372fd4edf1fa54bb6ecdefe222a8a08d9d56af5f8d7e6032252f7eb82c1
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.13.0 (2021-03-02)
|
4
4
|
|
5
|
+
* Use `ENV['SYNVERT_SNIPPETS_HOME']` to change default snippets home
|
6
|
+
* Display snippet source code for showing a snippet
|
7
|
+
|
8
|
+
## 0.12.0 (2021-03-01)
|
9
|
+
|
10
|
+
* Display `synvert-core` and `parser` version
|
11
|
+
* Generate a new snippet
|
12
|
+
|
13
|
+
## 0.11.1 (2021-02-20)
|
14
|
+
|
15
|
+
* Use `Synvert::VERSION` instead of `Synvert::Core::VERSION`
|
16
|
+
|
17
|
+
## 0.11.0 (2021-02-15)
|
18
|
+
|
19
|
+
* Add `--list-all` option
|
5
20
|
* Add post install message
|
21
|
+
* Fix `Synvert::Snippet.fetch_core_version`
|
6
22
|
|
7
23
|
## 0.10.0 (2021-02-07)
|
8
24
|
|
data/lib/synvert/cli.rb
CHANGED
@@ -28,6 +28,9 @@ module Synvert
|
|
28
28
|
when 'list'
|
29
29
|
load_rewriters
|
30
30
|
list_available_rewriters
|
31
|
+
when 'list-all'
|
32
|
+
load_rewriters
|
33
|
+
list_all_rewriters_in_json
|
31
34
|
when 'open'
|
32
35
|
open_rewriter
|
33
36
|
when 'query'
|
@@ -38,6 +41,8 @@ module Synvert
|
|
38
41
|
show_rewriter
|
39
42
|
when 'sync'
|
40
43
|
sync_snippets
|
44
|
+
when 'generate'
|
45
|
+
generate_snippet
|
41
46
|
else
|
42
47
|
# run
|
43
48
|
load_rewriters
|
@@ -77,6 +82,9 @@ module Synvert
|
|
77
82
|
'load custom snippets, snippet paths can be local file path or remote http url' do |snippet_paths|
|
78
83
|
@options[:custom_snippet_paths] = snippet_paths.split(',').map(&:strip)
|
79
84
|
end
|
85
|
+
opts.on '--list-all', 'list all available snippets name and description in json format' do
|
86
|
+
@options[:command] = 'list-all'
|
87
|
+
end
|
80
88
|
opts.on '-l', '--list', 'list all available snippets' do
|
81
89
|
@options[:command] = 'list'
|
82
90
|
end
|
@@ -106,8 +114,12 @@ module Synvert
|
|
106
114
|
'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
115
|
@options[:snippet_names] = snippet_names.split(',').map(&:strip)
|
108
116
|
end
|
117
|
+
opts.on '-g', '--generate NEW_SNIPPET_NAME', 'generate a new snippet' do |name|
|
118
|
+
@options[:command] = 'generate'
|
119
|
+
@options[:snippet_name] = name
|
120
|
+
end
|
109
121
|
opts.on '-v', '--version', 'show this version' do
|
110
|
-
puts Core::VERSION
|
122
|
+
puts "#{VERSION} (with synvert-core #{Core::VERSION} and parser #{Parser::VERSION})"
|
111
123
|
exit
|
112
124
|
end
|
113
125
|
end
|
@@ -125,7 +137,7 @@ module Synvert
|
|
125
137
|
|
126
138
|
# Load all rewriters.
|
127
139
|
def load_rewriters
|
128
|
-
Dir.glob(File.join(
|
140
|
+
Dir.glob(File.join(default_snippets_home, 'lib/**/*.rb')).each { |file| require file }
|
129
141
|
|
130
142
|
@options[:custom_snippet_paths].each do |snippet_path|
|
131
143
|
if /^http/.match?(snippet_path)
|
@@ -136,7 +148,7 @@ module Synvert
|
|
136
148
|
end
|
137
149
|
end
|
138
150
|
rescue StandardError
|
139
|
-
FileUtils.rm_rf
|
151
|
+
FileUtils.rm_rf default_snippets_home
|
140
152
|
retry
|
141
153
|
end
|
142
154
|
|
@@ -155,12 +167,34 @@ module Synvert
|
|
155
167
|
end
|
156
168
|
end
|
157
169
|
|
170
|
+
def list_all_rewriters_in_json
|
171
|
+
if Core::Rewriter.availables.empty?
|
172
|
+
puts 'There is no snippet under ~/.synvert, please run `synvert --sync` to fetch snippets.'
|
173
|
+
return
|
174
|
+
end
|
175
|
+
|
176
|
+
output = []
|
177
|
+
Core::Rewriter.availables.each do |group, rewriters|
|
178
|
+
rewriters.each do |name, rewriter|
|
179
|
+
rewriter.process_with_sandbox
|
180
|
+
output << {
|
181
|
+
group: group,
|
182
|
+
name: name,
|
183
|
+
description: rewriter.description,
|
184
|
+
sub_snippets: rewriter.sub_snippets.map(&:name)
|
185
|
+
}
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
puts JSON.generate(output)
|
190
|
+
end
|
191
|
+
|
158
192
|
# Open one rewriter.
|
159
193
|
def open_rewriter
|
160
194
|
editor = [ENV['SYNVERT_EDITOR'], ENV['EDITOR']].find { |e| !e.nil? && !e.empty? }
|
161
195
|
return puts 'To open a synvert snippet, set $EDITOR or $SYNVERT_EDITOR' unless editor
|
162
196
|
|
163
|
-
path = File.expand_path(File.join(
|
197
|
+
path = File.expand_path(File.join(default_snippets_home, "lib/#{@options[:snippet_name]}.rb"))
|
164
198
|
if File.exist? path
|
165
199
|
system editor, path
|
166
200
|
else
|
@@ -188,18 +222,9 @@ module Synvert
|
|
188
222
|
|
189
223
|
# Show and print one rewriter.
|
190
224
|
def show_rewriter
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
rewriter.process_with_sandbox
|
195
|
-
puts rewriter.description
|
196
|
-
rewriter.sub_snippets.each do |sub_rewriter|
|
197
|
-
puts
|
198
|
-
puts '=' * 80
|
199
|
-
puts "snippet: #{sub_rewriter.name}"
|
200
|
-
puts '=' * 80
|
201
|
-
puts sub_rewriter.description
|
202
|
-
end
|
225
|
+
path = File.expand_path(File.join(default_snippets_home, "lib/#{@options[:snippet_name]}.rb"))
|
226
|
+
if File.exist?(path)
|
227
|
+
puts File.read(path)
|
203
228
|
else
|
204
229
|
puts "snippet #{@options[:snippet_name]} not found"
|
205
230
|
end
|
@@ -207,7 +232,7 @@ module Synvert
|
|
207
232
|
|
208
233
|
# sync snippets
|
209
234
|
def sync_snippets
|
210
|
-
Snippet.new(
|
235
|
+
Snippet.new(default_snippets_home).sync
|
211
236
|
puts 'synvert snippets are synced'
|
212
237
|
core_version = Snippet.fetch_core_version
|
213
238
|
if Gem::Version.new(core_version) > Gem::Version.new(Synvert::Core::VERSION)
|
@@ -215,8 +240,56 @@ module Synvert
|
|
215
240
|
end
|
216
241
|
end
|
217
242
|
|
218
|
-
|
219
|
-
|
243
|
+
# generate a new snippet
|
244
|
+
def generate_snippet
|
245
|
+
group, name = @options[:snippet_name].split('/')
|
246
|
+
FileUtils.mkdir_p("lib/#{group}")
|
247
|
+
FileUtils.mkdir_p("spec/#{group}")
|
248
|
+
lib_content = <<~EOF
|
249
|
+
# frozen_string_literal: true
|
250
|
+
|
251
|
+
Synvert::Rewriter.new '#{group}', '#{name}' do
|
252
|
+
description <<~EOS
|
253
|
+
It convert Foo to Bar
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
Foo
|
257
|
+
```
|
258
|
+
|
259
|
+
=>
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
Bar
|
263
|
+
```
|
264
|
+
EOS
|
265
|
+
|
266
|
+
within_files '**/*.rb' do
|
267
|
+
with_node type: 'const', to_source: 'Foo' do
|
268
|
+
replace_with 'Bar'
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
EOF
|
273
|
+
spec_content = <<~EOF
|
274
|
+
# frozen_string_literal: true
|
275
|
+
|
276
|
+
require 'spec_helper'
|
277
|
+
|
278
|
+
RSpec.describe 'Convert Foo to Bar' do
|
279
|
+
let(:rewriter_name) { '#{group}/#{name}' }
|
280
|
+
let(:fake_file_path) { 'foobar.rb' }
|
281
|
+
let(:test_content) { 'Foo' }
|
282
|
+
let(:test_rewritten_content) { 'Bar' }
|
283
|
+
|
284
|
+
include_examples 'convertable'
|
285
|
+
end
|
286
|
+
EOF
|
287
|
+
File.write("lib/#{group}/#{name}.rb", lib_content)
|
288
|
+
File.write("spec/#{group}/#{name}_spec.rb", spec_content)
|
289
|
+
end
|
290
|
+
|
291
|
+
def default_snippets_home
|
292
|
+
ENV['SYNVERT_SNIPPETS_HOME'] || File.join(ENV['HOME'], '.synvert')
|
220
293
|
end
|
221
294
|
end
|
222
295
|
end
|
data/lib/synvert/snippet.rb
CHANGED
@@ -6,6 +6,11 @@ require 'json'
|
|
6
6
|
module Synvert
|
7
7
|
# Manage synvert snippets.
|
8
8
|
class Snippet
|
9
|
+
def self.fetch_core_version
|
10
|
+
content = URI.open('https://rubygems.org/api/v1/versions/synvert-core.json').read
|
11
|
+
JSON.parse(content).first['number']
|
12
|
+
end
|
13
|
+
|
9
14
|
def initialize(snippets_path)
|
10
15
|
@snippets_path = snippets_path
|
11
16
|
end
|
@@ -19,10 +24,5 @@ module Synvert
|
|
19
24
|
Kernel.system("git clone https://github.com/xinminlabs/synvert-snippets.git #{@snippets_path}")
|
20
25
|
end
|
21
26
|
end
|
22
|
-
|
23
|
-
def fetch_core_version
|
24
|
-
content = URI.open('https://rubygems.org/api/v1/versions/synvert-core.json').read
|
25
|
-
JSON.parse(content).first['number']
|
26
|
-
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/synvert/version.rb
CHANGED
@@ -8,6 +8,15 @@ module Synvert
|
|
8
8
|
let(:snippet) { Snippet.new(snippets_path) }
|
9
9
|
after { FileUtils.rmdir(snippets_path) if File.exist?(snippets_path) }
|
10
10
|
|
11
|
+
describe '.fetch_core_version' do
|
12
|
+
it 'gets remote version' do
|
13
|
+
stub_request(:get, 'https://rubygems.org/api/v1/versions/synvert-core.json').to_return(
|
14
|
+
body: '[{"number":"0.4.2"}]'
|
15
|
+
)
|
16
|
+
expect(Snippet.fetch_core_version).to eq '0.4.2'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
describe 'sync' do
|
12
21
|
it 'git clones snippets' do
|
13
22
|
expect(Kernel).to receive(:system).with(
|
@@ -23,14 +32,5 @@ module Synvert
|
|
23
32
|
FileUtils.cd File.dirname(__FILE__)
|
24
33
|
end
|
25
34
|
end
|
26
|
-
|
27
|
-
describe 'fetch_core_version' do
|
28
|
-
it 'gets remote version' do
|
29
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/synvert-core.json').to_return(
|
30
|
-
body: '[{"number":"0.4.2"}]'
|
31
|
-
)
|
32
|
-
expect(snippet.fetch_core_version).to eq '0.4.2'
|
33
|
-
end
|
34
|
-
end
|
35
35
|
end
|
36
36
|
end
|
data/synvert.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
spec.post_install_message = 'Please run `synvert --sync` first to sync snippets remotely.'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency 'synvert-core', '>= 0.
|
23
|
+
spec.add_runtime_dependency 'synvert-core', '>= 0.20.1'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
26
|
spec.add_development_dependency 'rake'
|
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.
|
4
|
+
version: 0.13.0
|
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-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: synvert-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.20.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.20.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|