synvert 0.14.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e99142ef7ed4127f66b23dba5d3ab0ec04d2b8edb315ac48945c15fb6056c294
4
- data.tar.gz: dbcbfffa5f570522d6385660663a8438d55ae7216f49cd8964787b31e916aa88
3
+ metadata.gz: fbc4490f4b48111cb658dbdf8d86f63f881a137fa40ef5c6050fa57d24392e09
4
+ data.tar.gz: d5ebc66ea45897622f6ed40e7838817c8dada422d92cd8898feadfb471d47bab
5
5
  SHA512:
6
- metadata.gz: 5346a5cc7fba0bc0aba045206c716d98fc8ac46b5beb109dffa62885e6caa5b09f0e31e9a84b3df324e8dae96f30164782f8211deb66b29a0890ce6b71efbedc
7
- data.tar.gz: f2b2b6a0ea082757d333a6c68aabcb03d1ae8ec99a5b95cbe5013bb52af5a4adbcd95dd278103f7f125dea2dc04cdf8ad72ddf70077a85c25af8bdf36f9955b0
6
+ metadata.gz: 8a48d72c516eb52854102bb8620585317295b188d50a0dfb1184e2f548eac20489713932a3fadbcd0e56526f5b8f97c045a2d8a783e4c56ed481c56619733151
7
+ data.tar.gz: ac409e15e3f22fd082f222c19542418af0d78573066302f293fd0b025108bda0e7eaa401eecba6ff0b4bac1a0ffeb2b9958865a960130859d26f79b51f025cd7
data/CHANGELOG.md CHANGED
@@ -1,8 +1,21 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.14.1 (2021-03-13)
3
+ ## 0.18.0 (2021-07-14)
4
+
5
+ * Execute a snippet
6
+
7
+ ## 0.17.0 (2021-04-19)
8
+
9
+ * Run `git checkout .` before `git pull --rebase`
10
+
11
+ ## 0.16.0 (2021-03-24)
12
+
13
+ * Add `ruby_version` and `gem_spec` to json output
14
+
15
+ ## 0.15.0 (2021-03-23)
4
16
 
5
17
  * Fix reduce on empty array
18
+ * Update synvert-core when syncing snippets
6
19
 
7
20
  ## 0.14.0 (2021-03-13)
8
21
 
data/README.md CHANGED
@@ -7,8 +7,6 @@
7
7
  Synvert = syntax + convert, makes it easy to convert ruby code
8
8
  automatically.
9
9
 
10
- Synvert is tested against MRI 1.9.3, 2.0.0, 2.1.7 and 2.2.3.
11
-
12
10
  Synvert is composed by synvert-core and synvert-snippets.
13
11
 
14
12
  [synvert-core][1] provides a dsl to convert ruby code.
@@ -24,6 +22,12 @@ Install it using rubygems
24
22
  $ gem install synvert
25
23
  ```
26
24
 
25
+ then run
26
+
27
+ ```
28
+ $ synvert --sync
29
+ ```
30
+
27
31
  ## Usage
28
32
 
29
33
  ```
@@ -42,11 +46,19 @@ Usage: synvert [project_path]
42
46
  e.g.
43
47
 
44
48
  ```
45
- $ synvert --sync
49
+ $ synvert -r factory_girl/use_short_syntax,rails/upgrade_3_2_to_4_0 ~/Sites/railsbp/rails-bestpractices.com
46
50
  ```
47
51
 
52
+ ## Docker
53
+
54
+ We have a docker image to run synvert
55
+
48
56
  ```
49
- $ synvert -r factory_girl/use_short_syntax,rails/upgrade_3_2_to_4_0 ~/Sites/railsbp/rails-bestpractices.com
57
+ $ docker pull xinminlabs/awesomecode-synvert
58
+
59
+ $ docker run xinminlabs/awesomecode-synvert synvert --list
60
+
61
+ $ docker run -v <your project path>:/app xinminlabs/awesomecode-synvert synvert --run default/check_syntax /app
50
62
  ```
51
63
 
52
64
  ## Documentation
data/lib/synvert/cli.rb CHANGED
@@ -40,6 +40,8 @@ module Synvert
40
40
  sync_snippets
41
41
  when 'generate'
42
42
  generate_snippet
43
+ when 'execute'
44
+ execute_snippet
43
45
  else
44
46
  # run
45
47
  load_rewriters
@@ -94,6 +96,9 @@ module Synvert
94
96
  opts.on '--sync', 'sync snippets' do
95
97
  @options[:command] = 'sync'
96
98
  end
99
+ opts.on '--execute', 'execute snippet' do
100
+ @options[:command] = 'execute'
101
+ end
97
102
  opts.on '-r', '--run SNIPPET_NAME', 'run specified snippet, e.g. ruby/new_hash_syntax' do |snippet_name|
98
103
  @options[:snippet_name] = snippet_name
99
104
  end
@@ -158,12 +163,15 @@ module Synvert
158
163
  Core::Rewriter.availables.each do |group, rewriters|
159
164
  rewriters.each do |name, rewriter|
160
165
  rewriter.process_with_sandbox
161
- output << {
166
+ item = {
162
167
  group: group,
163
168
  name: name,
164
169
  description: rewriter.description,
165
170
  sub_snippets: rewriter.sub_snippets.map(&:name)
166
171
  }
172
+ item[:ruby_version] = rewriter.ruby_version.version if rewriter.ruby_version
173
+ item[:gem_spec] = { name: rewriter.gem_spec.name, version: rewriter.gem_spec.version } if rewriter.gem_spec
174
+ output << item
167
175
  end
168
176
  end
169
177
 
@@ -218,7 +226,8 @@ module Synvert
218
226
  puts 'synvert snippets are synced'
219
227
  core_version = Snippet.fetch_core_version
220
228
  if Gem::Version.new(core_version) > Gem::Version.new(Synvert::Core::VERSION)
221
- puts "synvert-core is updated, please install synvert-core #{core_version}"
229
+ puts "synvert-core is updated, installing synvert-core #{core_version}"
230
+ system('gem install synvert-core')
222
231
  end
223
232
  end
224
233
 
@@ -238,8 +247,30 @@ module Synvert
238
247
  group, name = snippet_name.split('/')
239
248
  rewriter = Core::Rewriter.call group, name
240
249
  output = {
241
- affected_files: rewriter.affected_files.union(rewriter.sub_snippets.map(&:affected_files).reduce([], :+)).to_a,
242
- warnings: rewriter.warnings.union(rewriter.sub_snippets.map(&:warnings).reduce([], :+)),
250
+ affected_files: rewriter.affected_files.union(rewriter.sub_snippets.sum([], &:affected_files)).to_a,
251
+ warnings: rewriter.warnings.union(rewriter.sub_snippets.sum([], &:warnings)),
252
+ todo: rewriter.todo
253
+ }
254
+ puts JSON.generate(output)
255
+ end
256
+ end
257
+
258
+ # execute snippet
259
+ def execute_snippet
260
+ input = STDIN.read
261
+ if plain_output?
262
+ puts "===== execute started ====="
263
+ rewriter = eval(input)
264
+ rewriter.warnings.each do |warning|
265
+ puts '[Warn] ' + warning.message
266
+ end
267
+ puts rewriter.todo if rewriter.todo
268
+ puts "===== execute done ====="
269
+ elsif json_output?
270
+ rewriter = eval(input)
271
+ output = {
272
+ affected_files: rewriter.affected_files.union(rewriter.sub_snippets.sum([], &:affected_files)).to_a,
273
+ warnings: rewriter.warnings.union(rewriter.sub_snippets.sum([], &:warnings)),
243
274
  todo: rewriter.todo
244
275
  }
245
276
  puts JSON.generate(output)
@@ -19,7 +19,7 @@ module Synvert
19
19
  def sync
20
20
  if File.exist?(@snippets_path)
21
21
  FileUtils.cd @snippets_path
22
- Kernel.system('git pull --rebase')
22
+ Kernel.system('git checkout .; git pull --rebase')
23
23
  else
24
24
  Kernel.system("git clone https://github.com/xinminlabs/synvert-snippets.git #{@snippets_path}")
25
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Synvert
4
- VERSION = '0.14.1'
4
+ VERSION = '0.18.0'
5
5
  end
@@ -27,7 +27,7 @@ module Synvert
27
27
 
28
28
  it 'git pull snippets' do
29
29
  FileUtils.mkdir snippets_path
30
- expect(Kernel).to receive(:system).with('git pull --rebase')
30
+ expect(Kernel).to receive(:system).with('git checkout .; git pull --rebase')
31
31
  snippet.sync
32
32
  FileUtils.cd File.dirname(__FILE__)
33
33
  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.22.0'
23
+ spec.add_runtime_dependency 'synvert-core', '>= 0.42.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.14.1
4
+ version: 0.18.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-03-13 00:00:00.000000000 Z
11
+ date: 2021-07-14 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.22.0
19
+ version: 0.42.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.22.0
26
+ version: 0.42.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.1.4
126
+ rubygems_version: 3.1.6
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: synvert = syntax + convert.