synvert 0.20.0 → 1.0.0
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/.gitignore +0 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +101 -0
- data/README.md +19 -5
- data/lib/synvert/cli.rb +70 -52
- data/lib/synvert/version.rb +1 -1
- data/synvert-ruby.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 13a6cfb15282317c912c0ddd99f6e4dfe5040c2ec28c8f7a1b60d2266b7f1517
|
|
4
|
+
data.tar.gz: c34227427bed2b0d7f3e29112fbd225ff46517fa20fc58c5c9d7c4e4d53a6e2e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9642ee80da8558c06b294ebc4e4ce786405d6f93455a3700ac5f3299abdfecba8ee2d2d6dc9cafa9f98c6984ce965075850d39b30573fc686673a74da4979809
|
|
7
|
+
data.tar.gz: 83b1a5dd39156e8e70725c58c13e1b9ec0968316944583a1153ac9d57fb64f2a9d696d6e515f59be7c2535b1c10a406577fcefa56b1f792d27fcbac779615286
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.0.0 (2022-09-17)
|
|
4
|
+
|
|
5
|
+
* Test a snippet
|
|
6
|
+
* Require single rewriter instead of loading all rewriters
|
|
7
|
+
* Execute command can be either run or test
|
|
8
|
+
* Add `skip_path` and `only_paths` options
|
|
9
|
+
|
|
3
10
|
## 0.20.0 (2022-08-20)
|
|
4
11
|
|
|
5
12
|
* Rename `load_rewriters` to `read_rewriters`
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
synvert (1.0.0)
|
|
5
|
+
synvert-core (>= 1.8.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activesupport (6.1.7)
|
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
12
|
+
i18n (>= 1.6, < 2)
|
|
13
|
+
minitest (>= 5.1)
|
|
14
|
+
tzinfo (~> 2.0)
|
|
15
|
+
zeitwerk (~> 2.3)
|
|
16
|
+
addressable (2.8.0)
|
|
17
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
18
|
+
ast (2.4.2)
|
|
19
|
+
concurrent-ruby (1.1.10)
|
|
20
|
+
coveralls (0.8.23)
|
|
21
|
+
json (>= 1.8, < 3)
|
|
22
|
+
simplecov (~> 0.16.1)
|
|
23
|
+
term-ansicolor (~> 1.3)
|
|
24
|
+
thor (>= 0.19.4, < 2.0)
|
|
25
|
+
tins (~> 1.6)
|
|
26
|
+
crack (0.4.5)
|
|
27
|
+
rexml
|
|
28
|
+
diff-lcs (1.4.4)
|
|
29
|
+
docile (1.4.0)
|
|
30
|
+
erubis (2.7.0)
|
|
31
|
+
hashdiff (1.0.1)
|
|
32
|
+
i18n (1.12.0)
|
|
33
|
+
concurrent-ruby (~> 1.0)
|
|
34
|
+
json (2.5.1)
|
|
35
|
+
minitest (5.16.3)
|
|
36
|
+
node_mutation (1.3.3)
|
|
37
|
+
activesupport (< 7.0.0)
|
|
38
|
+
erubis
|
|
39
|
+
node_query (1.6.0)
|
|
40
|
+
activesupport (< 7.0.0)
|
|
41
|
+
parser (3.1.2.1)
|
|
42
|
+
ast (~> 2.4.1)
|
|
43
|
+
parser_node_ext (0.4.0)
|
|
44
|
+
parser
|
|
45
|
+
public_suffix (4.0.6)
|
|
46
|
+
rake (13.0.6)
|
|
47
|
+
rexml (3.2.5)
|
|
48
|
+
rspec (3.10.0)
|
|
49
|
+
rspec-core (~> 3.10.0)
|
|
50
|
+
rspec-expectations (~> 3.10.0)
|
|
51
|
+
rspec-mocks (~> 3.10.0)
|
|
52
|
+
rspec-core (3.10.1)
|
|
53
|
+
rspec-support (~> 3.10.0)
|
|
54
|
+
rspec-expectations (3.10.1)
|
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
56
|
+
rspec-support (~> 3.10.0)
|
|
57
|
+
rspec-mocks (3.10.2)
|
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
59
|
+
rspec-support (~> 3.10.0)
|
|
60
|
+
rspec-support (3.10.2)
|
|
61
|
+
simplecov (0.16.1)
|
|
62
|
+
docile (~> 1.1)
|
|
63
|
+
json (>= 1.8, < 3)
|
|
64
|
+
simplecov-html (~> 0.10.0)
|
|
65
|
+
simplecov-html (0.10.2)
|
|
66
|
+
sync (0.5.0)
|
|
67
|
+
synvert-core (1.8.0)
|
|
68
|
+
activesupport (< 7.0.0)
|
|
69
|
+
erubis
|
|
70
|
+
node_mutation
|
|
71
|
+
node_query
|
|
72
|
+
parser
|
|
73
|
+
parser_node_ext
|
|
74
|
+
term-ansicolor (1.7.1)
|
|
75
|
+
tins (~> 1.0)
|
|
76
|
+
thor (1.1.0)
|
|
77
|
+
tins (1.29.1)
|
|
78
|
+
sync
|
|
79
|
+
tzinfo (2.0.5)
|
|
80
|
+
concurrent-ruby (~> 1.0)
|
|
81
|
+
webmock (3.14.0)
|
|
82
|
+
addressable (>= 2.8.0)
|
|
83
|
+
crack (>= 0.3.2)
|
|
84
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
85
|
+
zeitwerk (2.6.0)
|
|
86
|
+
|
|
87
|
+
PLATFORMS
|
|
88
|
+
x86_64-darwin-20
|
|
89
|
+
x86_64-darwin-21
|
|
90
|
+
x86_64-linux
|
|
91
|
+
|
|
92
|
+
DEPENDENCIES
|
|
93
|
+
bundler
|
|
94
|
+
coveralls
|
|
95
|
+
rake
|
|
96
|
+
rspec
|
|
97
|
+
synvert!
|
|
98
|
+
webmock
|
|
99
|
+
|
|
100
|
+
BUNDLED WITH
|
|
101
|
+
2.3.7
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Synvert
|
|
2
2
|
|
|
3
|
-
<img src="https://synvert.
|
|
3
|
+
<img src="https://synvert.net/img/logo_96.png" alt="logo" width="32" height="32" />
|
|
4
4
|
|
|
5
5
|
[](https://awesomecode.io/repos/xinminlabs/synvert-ruby)
|
|
6
6
|

|
|
@@ -47,9 +47,11 @@ Usage: synvert-ruby [project_path]
|
|
|
47
47
|
-g, --generate NEW_SNIPPET_NAME generate a new snippet
|
|
48
48
|
--sync sync snippets
|
|
49
49
|
--execute execute snippet
|
|
50
|
-
-r, --run SNIPPET_NAME run
|
|
50
|
+
-r, --run SNIPPET_NAME run a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path
|
|
51
|
+
-t, --test SNIPPET_NAME test a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path
|
|
51
52
|
--show-run-process show processing files when running a snippet
|
|
52
|
-
--
|
|
53
|
+
--only-paths DIRECTORIES only specified files or directories, separated by comma, e.g. app/models,app/controllers
|
|
54
|
+
--skip-paths FILE_PATTERNS skip specified files or directories, separated by comma, e.g. vendor/,lib/**/*.rb
|
|
53
55
|
-f, --format FORMAT output format
|
|
54
56
|
-v, --version show this version
|
|
55
57
|
```
|
|
@@ -98,18 +100,30 @@ Run a snippet, analyze and then rewrite code.
|
|
|
98
100
|
$ synvert-ruby -r factory_bot/use_short_syntax ~/Sites/xinminlabs/synvert-core-ruby
|
|
99
101
|
```
|
|
100
102
|
|
|
101
|
-
|
|
103
|
+
Run a snippet from remote url
|
|
102
104
|
|
|
103
105
|
```
|
|
104
106
|
$ synvert-ruby -r https://raw.githubusercontent.com/xinminlabs/synvert-snippets-ruby/master/lib/factory_bot/use_short_syntax.rb ~/sites/xinminlabs/synvert-core-ruby
|
|
105
107
|
```
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
Run a snippet from local path
|
|
108
110
|
|
|
109
111
|
```
|
|
110
112
|
$ synvert-ruby -r ~/.synvert-ruby/lib/factory_bot/use_short_syntax.rb ~/sites/xinminlabs/synvert-core-ruby
|
|
111
113
|
```
|
|
112
114
|
|
|
115
|
+
Skip paths
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
$ synvert-ruby -r factory_bot/use_short_syntax --skip-paths vendor/ ~/sites/xinminlabs/synvert-core-ruby
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Only paths
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
$ synvert-ruby -r factory_bot/use_short_syntax --only-paths app/models/ ~/sites/xinminlabs/synvert-core-ruby
|
|
125
|
+
```
|
|
126
|
+
|
|
113
127
|
Show processing files when running a snippet.
|
|
114
128
|
|
|
115
129
|
```
|
data/lib/synvert/cli.rb
CHANGED
|
@@ -43,21 +43,15 @@ module Synvert
|
|
|
43
43
|
when 'generate'
|
|
44
44
|
generate_snippet
|
|
45
45
|
when 'execute'
|
|
46
|
-
execute_snippet
|
|
46
|
+
execute_snippet(@options[:execute_command])
|
|
47
|
+
when 'test'
|
|
48
|
+
group, name = get_snippet_name(@options[:snippet_name])
|
|
49
|
+
test_snippet(group, name)
|
|
50
|
+
when 'run'
|
|
51
|
+
group, name = get_snippet_name(@options[:snippet_name])
|
|
52
|
+
run_snippet(group, name)
|
|
47
53
|
else
|
|
48
|
-
|
|
49
|
-
uri = URI.parse(@options[:snippet_name])
|
|
50
|
-
eval(uri.open.read)
|
|
51
|
-
snippet_name = get_last_snippet_name
|
|
52
|
-
run_snippet(snippet_name)
|
|
53
|
-
elsif File.exists?(@options[:snippet_name])
|
|
54
|
-
require(@options[:snippet_name])
|
|
55
|
-
snippet_name = get_last_snippet_name
|
|
56
|
-
run_snippet(snippet_name)
|
|
57
|
-
else
|
|
58
|
-
read_rewriters
|
|
59
|
-
run_snippet(@options[:snippet_name])
|
|
60
|
-
end
|
|
54
|
+
# nothing to do
|
|
61
55
|
end
|
|
62
56
|
true
|
|
63
57
|
rescue SystemExit
|
|
@@ -103,18 +97,28 @@ module Synvert
|
|
|
103
97
|
opts.on '--sync', 'sync snippets' do
|
|
104
98
|
@options[:command] = 'sync'
|
|
105
99
|
end
|
|
106
|
-
opts.on '--execute', 'execute snippet' do
|
|
100
|
+
opts.on '--execute', 'execute snippet' do |execute_command|
|
|
107
101
|
@options[:command] = 'execute'
|
|
102
|
+
@options[:execute_command] = execute_command
|
|
103
|
+
end
|
|
104
|
+
opts.on '-r', '--run SNIPPET_NAME', 'run a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path' do |snippet_name|
|
|
105
|
+
@options[:command] = 'run'
|
|
106
|
+
@options[:snippet_name] = snippet_name
|
|
108
107
|
end
|
|
109
|
-
opts.on '-
|
|
108
|
+
opts.on '-t', '--test SNIPPET_NAME', 'test a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path' do |snippet_name|
|
|
109
|
+
@options[:command] = 'test'
|
|
110
110
|
@options[:snippet_name] = snippet_name
|
|
111
111
|
end
|
|
112
112
|
opts.on '--show-run-process', 'show processing files when running a snippet' do
|
|
113
113
|
Core::Configuration.show_run_process = true
|
|
114
114
|
end
|
|
115
|
-
opts.on '--
|
|
116
|
-
'
|
|
117
|
-
@options[:
|
|
115
|
+
opts.on '--only-paths DIRECTORIES',
|
|
116
|
+
'only specified files or directories, separated by comma, e.g. app/models,app/controllers' do |directories|
|
|
117
|
+
@options[:only_paths] = directories
|
|
118
|
+
end
|
|
119
|
+
opts.on '--skip-paths FILE_PATTERNS',
|
|
120
|
+
'skip specified files or directories, separated by comma, e.g. vendor/,lib/**/*.rb' do |file_patterns|
|
|
121
|
+
@options[:skip_paths] = file_patterns
|
|
118
122
|
end
|
|
119
123
|
opts.on '-f', '--format FORMAT', 'output format' do |format|
|
|
120
124
|
@options[:format] = format
|
|
@@ -125,14 +129,12 @@ module Synvert
|
|
|
125
129
|
end
|
|
126
130
|
end
|
|
127
131
|
paths = optparse.parse(args)
|
|
128
|
-
Core::Configuration.
|
|
129
|
-
if @options[:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
end.flatten
|
|
135
|
-
Core::Configuration.skip_files = skip_files
|
|
132
|
+
Core::Configuration.root_path = paths.first || Dir.pwd
|
|
133
|
+
if @options[:only_paths] && !@options[:only_paths].empty?
|
|
134
|
+
Core::Configuration.only_paths = @options[:only_paths].split(",").map { |only_path| only_path.strip }
|
|
135
|
+
end
|
|
136
|
+
if @options[:skip_paths] && !@options[:skip_paths].empty?
|
|
137
|
+
Core::Configuration.skip_paths = @options[:skip_paths].split(",").map { |skip_path| skip_path.strip }
|
|
136
138
|
end
|
|
137
139
|
end
|
|
138
140
|
|
|
@@ -228,19 +230,40 @@ module Synvert
|
|
|
228
230
|
end
|
|
229
231
|
end
|
|
230
232
|
|
|
231
|
-
#
|
|
232
|
-
|
|
233
|
+
# get snippet name
|
|
234
|
+
# it can get from explicit snippet name,
|
|
235
|
+
# or from local path or http url.
|
|
236
|
+
def get_snippet_name(snippet_name)
|
|
237
|
+
if /^http/.match?(snippet_name)
|
|
238
|
+
uri = URI.parse(snippet_name)
|
|
239
|
+
eval(uri.open.read)
|
|
240
|
+
get_last_snippet_name
|
|
241
|
+
elsif File.exists?(snippet_name)
|
|
242
|
+
require(snippet_name)
|
|
243
|
+
get_last_snippet_name
|
|
244
|
+
else
|
|
245
|
+
require(File.join(default_snippets_home, 'lib', "#{snippet_name}.rb"))
|
|
246
|
+
snippet_name.split('/')
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# get snippet name by user inputs
|
|
251
|
+
def get_snippet_name_by_input(input)
|
|
252
|
+
rewriter = eval(input)
|
|
253
|
+
get_last_snippet_name
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# run a snippet
|
|
257
|
+
def run_snippet(group, name)
|
|
233
258
|
if plain_output?
|
|
234
|
-
puts "===== #{
|
|
235
|
-
group, name = snippet_name.split('/')
|
|
259
|
+
puts "===== #{group}/#{name} started ====="
|
|
236
260
|
rewriter = Core::Rewriter.call group, name
|
|
237
261
|
rewriter.warnings.each do |warning|
|
|
238
262
|
puts '[Warn] ' + warning.message
|
|
239
263
|
end
|
|
240
264
|
puts rewriter.todo if rewriter.todo
|
|
241
|
-
puts "===== #{
|
|
265
|
+
puts "===== #{group}/#{name} done ====="
|
|
242
266
|
elsif json_output?
|
|
243
|
-
group, name = snippet_name.split('/')
|
|
244
267
|
rewriter = Core::Rewriter.call group, name
|
|
245
268
|
output = {
|
|
246
269
|
affected_files: rewriter.affected_files.union(rewriter.sub_snippets.sum(Set.new, &:affected_files)).to_a,
|
|
@@ -251,25 +274,20 @@ module Synvert
|
|
|
251
274
|
end
|
|
252
275
|
end
|
|
253
276
|
|
|
277
|
+
# test a snippet
|
|
278
|
+
def test_snippet(group, name)
|
|
279
|
+
rewriter = Core::Rewriter.fetch(group, name)
|
|
280
|
+
results = rewriter.test
|
|
281
|
+
puts JSON.generate(results)
|
|
282
|
+
end
|
|
283
|
+
|
|
254
284
|
# execute snippet
|
|
255
|
-
def execute_snippet
|
|
256
|
-
|
|
257
|
-
if
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
puts '[Warn] ' + warning.message
|
|
262
|
-
end
|
|
263
|
-
puts rewriter.todo if rewriter.todo
|
|
264
|
-
puts '===== execute done ====='
|
|
265
|
-
elsif json_output?
|
|
266
|
-
rewriter = eval(input)
|
|
267
|
-
output = {
|
|
268
|
-
affected_files: rewriter.affected_files.union(rewriter.sub_snippets.sum(Set.new, &:affected_files)).to_a,
|
|
269
|
-
warnings: rewriter.warnings.union(rewriter.sub_snippets.sum([], &:warnings)),
|
|
270
|
-
todo: rewriter.todo
|
|
271
|
-
}
|
|
272
|
-
puts JSON.generate(output)
|
|
285
|
+
def execute_snippet(execute_command)
|
|
286
|
+
group, name = get_snippet_name_by_input(STDIN.read)
|
|
287
|
+
if execute_command == 'test'
|
|
288
|
+
test_snippet(group, name)
|
|
289
|
+
else
|
|
290
|
+
run_snippet(group, name)
|
|
273
291
|
end
|
|
274
292
|
end
|
|
275
293
|
|
|
@@ -337,7 +355,7 @@ module Synvert
|
|
|
337
355
|
def get_last_snippet_name
|
|
338
356
|
group = Rewriter.availables.keys.last
|
|
339
357
|
name = Rewriter.availables[group].keys.last
|
|
340
|
-
return
|
|
358
|
+
return group, name
|
|
341
359
|
end
|
|
342
360
|
end
|
|
343
361
|
end
|
data/lib/synvert/version.rb
CHANGED
data/synvert-ruby.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-ruby --sync` first to sync snippets remotely.'
|
|
22
22
|
|
|
23
|
-
spec.add_runtime_dependency 'synvert-core', '>= 1.
|
|
23
|
+
spec.add_runtime_dependency 'synvert-core', '>= 1.8.0'
|
|
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: 1.0.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: 2022-
|
|
11
|
+
date: 2022-09-17 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: 1.
|
|
19
|
+
version: 1.8.0
|
|
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: 1.
|
|
26
|
+
version: 1.8.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bundler
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -94,6 +94,7 @@ files:
|
|
|
94
94
|
- ".rspec"
|
|
95
95
|
- CHANGELOG.md
|
|
96
96
|
- Gemfile
|
|
97
|
+
- Gemfile.lock
|
|
97
98
|
- LICENSE.txt
|
|
98
99
|
- README.md
|
|
99
100
|
- Rakefile
|