synvert 0.19.1 → 0.20.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/.github/workflows/main.yml +1 -1
- data/CHANGELOG.md +14 -0
- data/README.md +84 -27
- data/lib/synvert/cli.rb +35 -34
- data/lib/synvert/version.rb +1 -1
- data/synvert-ruby.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fb489331d776e367ae6be1c1ab39330b59419b07b9db40e1c6ea215fd612338
|
4
|
+
data.tar.gz: fbbb3fc50e1c05bc67aef081b4490e49f1c839dc24eb76941e2487f2cb240cd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dad0c74122ab91f6a05907af7bca9fb3badbb3a137a6914227508814de3682f6578975bd9a2aa51a577881ccb6c22e837b43b2b36c01769eb703f63b2eb1e9a2
|
7
|
+
data.tar.gz: ff5309c3d2ca47e01be1a02aeb5ab9e3f1f6d0ef1c8ea8dc5fe3e8bcf03afeda5035aebf0c4fc26acf62e44097999294fab431936a665e3726ba9a6314522641
|
data/.github/workflows/main.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.20.0 (2022-08-20)
|
4
|
+
|
5
|
+
* Rename `load_rewriters` to `read_rewriters`
|
6
|
+
* Run a snippet from remote url or local file path
|
7
|
+
|
8
|
+
## 0.19.3 (2022-07-18)
|
9
|
+
|
10
|
+
* Require json
|
11
|
+
* update `synvert-core` to 1.5.0
|
12
|
+
|
13
|
+
## 0.19.2 (2021-12-15)
|
14
|
+
|
15
|
+
* List sub_snippets group and name
|
16
|
+
|
3
17
|
## 0.19.1 (2021-10-23)
|
4
18
|
|
5
19
|
* Make URI.open work in ruby 2.4
|
data/README.md
CHANGED
@@ -2,67 +2,124 @@
|
|
2
2
|
|
3
3
|
<img src="https://synvert.xinminlabs.com/img/logo_96.png" alt="logo" width="32" height="32" />
|
4
4
|
|
5
|
+
[](https://awesomecode.io/repos/xinminlabs/synvert-ruby)
|
5
6
|

|
6
|
-
[](https://coveralls.io/r/xinminlabs/synvert)
|
7
7
|
[](http://badge.fury.io/rb/synvert)
|
8
8
|
|
9
|
-
|
10
|
-
automatically.
|
9
|
+
`synvert-ruby` is a command tool to rewrite ruby code automatically, it depends on `synvert-core-ruby` and `synvert-snippets-ruby`.
|
11
10
|
|
12
|
-
|
11
|
+
[synvert-core-ruby](https://github.com/xinminlabs/synvert-core-ruby) provides a set of DSLs to rewrite ruby code.
|
13
12
|
|
14
|
-
[synvert-
|
15
|
-
|
16
|
-
[synvert-snippets][2] lists all snippets to convert ruby code based on
|
17
|
-
synvert-core.
|
13
|
+
[synvert-snippets-ruby](https://github.com/xinminlabs/synvert-snippets-ruby) provides official snippets to rewrite ruby code.
|
18
14
|
|
19
15
|
## Installation
|
20
16
|
|
21
|
-
|
17
|
+
To install the latest version, run
|
18
|
+
|
22
19
|
|
23
20
|
```
|
24
21
|
$ gem install synvert
|
25
22
|
```
|
26
23
|
|
27
|
-
|
24
|
+
This will also install `synvert-core-ruby`.
|
25
|
+
|
26
|
+
Before using synvert, you need to sync all official snippets first.
|
28
27
|
|
29
28
|
```
|
30
29
|
$ synvert-ruby --sync
|
31
30
|
```
|
32
31
|
|
32
|
+
Then you can use synvert to rewrite your ruby code, e.g.
|
33
|
+
|
34
|
+
```
|
35
|
+
$ synvert-ruby -r factory_bot/use_short_syntax
|
36
|
+
```
|
37
|
+
|
33
38
|
## Usage
|
34
39
|
|
35
40
|
```
|
36
41
|
$ synvert-ruby -h
|
37
42
|
Usage: synvert-ruby [project_path]
|
38
|
-
-d, --load SNIPPET_PATHS load custom snippets, snippet paths can be local file path or remote http url
|
39
43
|
-l, --list list all available snippets
|
40
44
|
-q, --query QUERY query specified snippets
|
41
|
-
|
42
|
-
-
|
45
|
+
-s, --show SNIPPET_NAME show specified snippet description, SNIPPET_NAME is combined by group and name, e.g. ruby/new_hash_syntax
|
46
|
+
-o, --open SNIPPET_NAME Open a snippet
|
47
|
+
-g, --generate NEW_SNIPPET_NAME generate a new snippet
|
43
48
|
--sync sync snippets
|
44
|
-
|
49
|
+
--execute execute snippet
|
50
|
+
-r, --run SNIPPET_NAME run specified snippet, e.g. ruby/new_hash_syntax, or remote url, or local file path
|
51
|
+
--show-run-process show processing files when running a snippet
|
52
|
+
--skip FILE_PATTERNS skip specified files or directories, separated by comma, e.g. app/models/post.rb,vendor/plugins/**/*.rb
|
53
|
+
-f, --format FORMAT output format
|
45
54
|
-v, --version show this version
|
46
55
|
```
|
47
56
|
|
48
|
-
|
57
|
+
#### Sync snippets
|
58
|
+
|
59
|
+
[Official Snippets](https://github.com/xinminlabs/synvert-snippets-ruby) are available on github,
|
60
|
+
you can sync them any time you want.
|
61
|
+
|
62
|
+
```
|
63
|
+
$ synvert-ruby --sync
|
64
|
+
```
|
65
|
+
|
66
|
+
#### List snippets
|
67
|
+
|
68
|
+
List all available snippets
|
69
|
+
|
70
|
+
```
|
71
|
+
$ synvert-ruby -l
|
72
|
+
|
73
|
+
$ synvert-ruby --list --form json
|
74
|
+
```
|
75
|
+
|
76
|
+
#### Show a snippet
|
77
|
+
|
78
|
+
Describe what a snippet does.
|
79
|
+
|
80
|
+
```
|
81
|
+
$ synvert-ruby -s factory_bot/use_short_syntax
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Open a snippet
|
85
|
+
|
86
|
+
Open a snippet in your editor, editor is defined in
|
87
|
+
`ENV['SNIPPET_EDITOR']` or `ENV['EDITOR']`
|
88
|
+
|
89
|
+
```
|
90
|
+
$ synvert-ruby -o factory_bot/use_short_syntax
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Run a snippet
|
94
|
+
|
95
|
+
Run a snippet, analyze and then rewrite code.
|
96
|
+
|
97
|
+
```
|
98
|
+
$ synvert-ruby -r factory_bot/use_short_syntax ~/Sites/xinminlabs/synvert-core-ruby
|
99
|
+
```
|
100
|
+
|
101
|
+
run a snippet from remote url
|
49
102
|
|
50
103
|
```
|
51
|
-
$ synvert-ruby -r
|
104
|
+
$ synvert-ruby -r https://raw.githubusercontent.com/xinminlabs/synvert-snippets-ruby/master/lib/factory_bot/use_short_syntax.rb ~/sites/xinminlabs/synvert-core-ruby
|
52
105
|
```
|
53
106
|
|
54
|
-
|
107
|
+
run a snippet from local path
|
55
108
|
|
56
|
-
|
109
|
+
```
|
110
|
+
$ synvert-ruby -r ~/.synvert-ruby/lib/factory_bot/use_short_syntax.rb ~/sites/xinminlabs/synvert-core-ruby
|
111
|
+
```
|
57
112
|
|
58
|
-
|
113
|
+
Show processing files when running a snippet.
|
59
114
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
115
|
+
```
|
116
|
+
$ synvert-ruby -r factory_bot/use_short_syntax --show-run-process ~/Sites/xinminlabs/synvert-core-ruby
|
117
|
+
```
|
118
|
+
|
119
|
+
#### Generate a snippet
|
120
|
+
|
121
|
+
Generate a new snippet
|
65
122
|
|
66
|
-
|
67
|
-
|
68
|
-
|
123
|
+
```
|
124
|
+
$ synvert-ruby -g ruby/convert_foo_to_bar
|
125
|
+
```
|
data/lib/synvert/cli.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
+
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
require 'open-uri'
|
4
7
|
|
5
8
|
module Synvert
|
6
9
|
# Synvert command line interface.
|
@@ -15,7 +18,7 @@ module Synvert
|
|
15
18
|
|
16
19
|
# Initialize a CLI.
|
17
20
|
def initialize
|
18
|
-
@options = { command: 'run',
|
21
|
+
@options = { command: 'run', format: 'plain' }
|
19
22
|
end
|
20
23
|
|
21
24
|
# Run the CLI.
|
@@ -26,12 +29,12 @@ module Synvert
|
|
26
29
|
|
27
30
|
case @options[:command]
|
28
31
|
when 'list'
|
29
|
-
|
32
|
+
read_rewriters
|
30
33
|
list_available_rewriters
|
31
34
|
when 'open'
|
32
35
|
open_rewriter
|
33
36
|
when 'query'
|
34
|
-
|
37
|
+
read_rewriters
|
35
38
|
query_available_rewriters
|
36
39
|
when 'show'
|
37
40
|
show_rewriter
|
@@ -42,9 +45,19 @@ module Synvert
|
|
42
45
|
when 'execute'
|
43
46
|
execute_snippet
|
44
47
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
if /^http/.match?(@options[:snippet_name])
|
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
|
48
61
|
end
|
49
62
|
true
|
50
63
|
rescue SystemExit
|
@@ -66,11 +79,6 @@ module Synvert
|
|
66
79
|
optparse =
|
67
80
|
OptionParser.new do |opts|
|
68
81
|
opts.banner = 'Usage: synvert-ruby [project_path]'
|
69
|
-
opts.on '-d',
|
70
|
-
'--load SNIPPET_PATHS',
|
71
|
-
'load custom snippets, snippet paths can be local file path or remote http url' do |snippet_paths|
|
72
|
-
@options[:custom_snippet_paths] = snippet_paths.split(',').map(&:strip)
|
73
|
-
end
|
74
82
|
opts.on '-l', '--list', 'list all available snippets' do
|
75
83
|
@options[:command] = 'list'
|
76
84
|
end
|
@@ -98,7 +106,7 @@ module Synvert
|
|
98
106
|
opts.on '--execute', 'execute snippet' do
|
99
107
|
@options[:command] = 'execute'
|
100
108
|
end
|
101
|
-
opts.on '-r', '--run SNIPPET_NAME', 'run specified snippet, e.g. ruby/new_hash_syntax' do |snippet_name|
|
109
|
+
opts.on '-r', '--run SNIPPET_NAME', 'run specified snippet, e.g. ruby/new_hash_syntax, or remote url, or local file path' do |snippet_name|
|
102
110
|
@options[:snippet_name] = snippet_name
|
103
111
|
end
|
104
112
|
opts.on '--show-run-process', 'show processing files when running a snippet' do
|
@@ -128,21 +136,9 @@ module Synvert
|
|
128
136
|
end
|
129
137
|
end
|
130
138
|
|
131
|
-
#
|
132
|
-
def
|
139
|
+
# read all rewriters.
|
140
|
+
def read_rewriters
|
133
141
|
Dir.glob(File.join(default_snippets_home, 'lib/**/*.rb')).each { |file| require file }
|
134
|
-
|
135
|
-
@options[:custom_snippet_paths].each do |snippet_path|
|
136
|
-
if /^http/.match?(snippet_path)
|
137
|
-
uri = URI.parse snippet_path
|
138
|
-
eval(uri.read)
|
139
|
-
else
|
140
|
-
require snippet_path
|
141
|
-
end
|
142
|
-
end
|
143
|
-
rescue StandardError
|
144
|
-
FileUtils.rm_rf default_snippets_home
|
145
|
-
retry
|
146
142
|
end
|
147
143
|
|
148
144
|
# List and print all available rewriters.
|
@@ -165,12 +161,11 @@ module Synvert
|
|
165
161
|
Core::Rewriter.availables.each do |group, rewriters|
|
166
162
|
rewriters.each do |name, rewriter|
|
167
163
|
rewriter.process_with_sandbox
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
}
|
164
|
+
sub_snippets =
|
165
|
+
rewriter.sub_snippets.map { |sub_snippet|
|
166
|
+
{ group: sub_snippet.group, name: sub_snippet.name }
|
167
|
+
}
|
168
|
+
item = { group: group, name: name, description: rewriter.description, sub_snippets: sub_snippets }
|
174
169
|
item[:ruby_version] = rewriter.ruby_version.version if rewriter.ruby_version
|
175
170
|
item[:gem_spec] = { name: rewriter.gem_spec.name, version: rewriter.gem_spec.version } if rewriter.gem_spec
|
176
171
|
output << item
|
@@ -234,8 +229,7 @@ module Synvert
|
|
234
229
|
end
|
235
230
|
|
236
231
|
# run snippets
|
237
|
-
def run_snippet
|
238
|
-
snippet_name = @options[:snippet_name]
|
232
|
+
def run_snippet(snippet_name)
|
239
233
|
if plain_output?
|
240
234
|
puts "===== #{snippet_name} started ====="
|
241
235
|
group, name = snippet_name.split('/')
|
@@ -338,5 +332,12 @@ module Synvert
|
|
338
332
|
def json_output?
|
339
333
|
@options[:format] == 'json'
|
340
334
|
end
|
335
|
+
|
336
|
+
# get the last registered snippet name
|
337
|
+
def get_last_snippet_name
|
338
|
+
group = Rewriter.availables.keys.last
|
339
|
+
name = Rewriter.availables[group].keys.last
|
340
|
+
return [group, name].join("/")
|
341
|
+
end
|
341
342
|
end
|
342
343
|
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', '>=
|
23
|
+
spec.add_runtime_dependency 'synvert-core', '>= 1.5.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: 0.20.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:
|
11
|
+
date: 2022-08-20 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:
|
19
|
+
version: 1.5.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:
|
26
|
+
version: 1.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
|
-
rubygems_version: 3.
|
128
|
+
rubygems_version: 3.3.7
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: synvert = syntax + convert.
|