synvert-core 1.7.0 → 1.8.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/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/synvert/core/configuration.rb +16 -8
- data/lib/synvert/core/rewriter/gem_spec.rb +2 -2
- data/lib/synvert/core/rewriter/instance.rb +33 -13
- data/lib/synvert/core/rewriter/ruby_version.rb +3 -3
- data/lib/synvert/core/rewriter.rb +3 -3
- data/lib/synvert/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00661750a3522a9983d5eec1f064f62bf0d335e05e3b2a9cb7bb7222b04e20a2
|
4
|
+
data.tar.gz: 5a35b831ca678486f4a51db2ae8a57bed58617299a0c26c9cbc0c462351ffd3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b18bcf0f9f344c2c8661d7e4edf1a4f768d67175f45b34d2bb37b321f38681840c29b8e9a0fa61ee295329909f3093de4b7703e6dec21066190336ee8ceb1b5a
|
7
|
+
data.tar.gz: 0f334dc34d82d15235381f3a9be7651707b5a7a0e5614e29f48310407c70384ac6f1594f2b8643dc97577e0e55a4b6165f3174071e2887f424a76ed4d5f3b3cb
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,23 +4,31 @@ module Synvert::Core
|
|
4
4
|
# Synvert global configuration.
|
5
5
|
class Configuration
|
6
6
|
class << self
|
7
|
-
# @!attribute [w]
|
8
|
-
# @!attribute [w]
|
7
|
+
# @!attribute [w] root_path
|
8
|
+
# @!attribute [w] skip_paths
|
9
|
+
# @!attribute [w] only_paths
|
9
10
|
# @!attribute [w] show_run_process
|
10
|
-
attr_writer :
|
11
|
+
attr_writer :root_path, :skip_paths, :only_paths, :show_run_process
|
11
12
|
|
12
13
|
# Get the path.
|
13
14
|
#
|
14
15
|
# @return [String] default is '.'
|
15
|
-
def
|
16
|
-
@
|
16
|
+
def root_path
|
17
|
+
@root_path || '.'
|
17
18
|
end
|
18
19
|
|
19
|
-
# Get a list of skip
|
20
|
+
# Get a list of skip paths.
|
20
21
|
#
|
21
22
|
# @return [Array<String>] default is [].
|
22
|
-
def
|
23
|
-
@
|
23
|
+
def skip_paths
|
24
|
+
@skip_paths || []
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get a list of only paths.
|
28
|
+
#
|
29
|
+
# @return [Array<String>] default is [].
|
30
|
+
def only_paths
|
31
|
+
@only_paths || []
|
24
32
|
end
|
25
33
|
|
26
34
|
# Check if show run process.
|
@@ -22,12 +22,12 @@ module Synvert::Core
|
|
22
22
|
#
|
23
23
|
# @return [Boolean] true if matches, otherwise false.
|
24
24
|
def match?
|
25
|
-
gemfile_lock_path = File.expand_path(File.join(Configuration.
|
25
|
+
gemfile_lock_path = File.expand_path(File.join(Configuration.root_path, 'Gemfile.lock'))
|
26
26
|
|
27
27
|
# if Gemfile.lock does not exist, just ignore this check
|
28
28
|
return true unless File.exist?(gemfile_lock_path)
|
29
29
|
|
30
|
-
ENV['BUNDLE_GEMFILE'] = Configuration.
|
30
|
+
ENV['BUNDLE_GEMFILE'] = Configuration.root_path # make sure bundler reads Gemfile.lock in the correct path
|
31
31
|
parser = Bundler::LockfileParser.new(File.read(gemfile_lock_path))
|
32
32
|
parser.specs.any? { |spec| Gem::Dependency.new(@name, @version).match?(spec) }
|
33
33
|
end
|
@@ -32,12 +32,8 @@ module Synvert::Core
|
|
32
32
|
# It finds specified files, for each file, it executes the block code, rewrites the original code,
|
33
33
|
# then writes the code back to the original file.
|
34
34
|
def process
|
35
|
-
|
36
|
-
|
37
|
-
next if Configuration.skip_files.include?(file_path)
|
38
|
-
|
39
|
-
process_file(file_path)
|
40
|
-
end
|
35
|
+
get_file_paths.each do |file_path|
|
36
|
+
process_file(file_path)
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
@@ -45,13 +41,7 @@ module Synvert::Core
|
|
45
41
|
# It finds specified files, for each file, it executes the block code, tests the original code,
|
46
42
|
# then returns the actions.
|
47
43
|
def test
|
48
|
-
|
49
|
-
Dir.glob(File.join(Configuration.path, file_pattern))
|
50
|
-
end
|
51
|
-
|
52
|
-
paths.uniq.map do |file_path|
|
53
|
-
next if Configuration.skip_files.include?(file_path)
|
54
|
-
|
44
|
+
get_file_paths.each do |file_path|
|
55
45
|
test_file(file_path)
|
56
46
|
end
|
57
47
|
end
|
@@ -424,6 +414,36 @@ module Synvert::Core
|
|
424
414
|
end
|
425
415
|
end
|
426
416
|
|
417
|
+
# Get file paths.
|
418
|
+
# @return [Array<String>] file paths
|
419
|
+
def get_file_paths
|
420
|
+
Dir.chdir(Configuration.root_path) do
|
421
|
+
only_paths = Configuration.only_paths.size > 0 ? Configuration.only_paths : ["."]
|
422
|
+
only_paths.flat_map do |only_path|
|
423
|
+
@file_patterns.flat_map do |file_pattern|
|
424
|
+
pattern = only_path == "." ? file_pattern : File.join(only_path, file_pattern)
|
425
|
+
Dir.glob(pattern) - get_skip_files
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
# Get skip files.
|
432
|
+
# @return [Array<String>] skip files
|
433
|
+
def get_skip_files
|
434
|
+
@skip_files ||= Configuration.skip_paths.flat_map do |skip_path|
|
435
|
+
if File.directory?(skip_path)
|
436
|
+
Dir.glob(File.join(skip_path, "**/*"))
|
437
|
+
elsif File.file?(skip_path)
|
438
|
+
[skip_path]
|
439
|
+
elsif skip_path.end_with?("**") || skip_path.end_with?("**/")
|
440
|
+
Dir.glob(File.join(skip_path, "*"))
|
441
|
+
else
|
442
|
+
Dir.glob(skip_path)
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
427
447
|
# Read file source.
|
428
448
|
# @param file_path [String] file path
|
429
449
|
# @return [String] file source
|
@@ -16,14 +16,14 @@ module Synvert::Core
|
|
16
16
|
#
|
17
17
|
# @return [Boolean] true if matches, otherwise false.
|
18
18
|
def match?
|
19
|
-
if File.exist?(File.join(Configuration.
|
19
|
+
if File.exist?(File.join(Configuration.root_path, '.ruby-version'))
|
20
20
|
version_file = '.ruby-version'
|
21
|
-
elsif File.exist?(File.join(Configuration.
|
21
|
+
elsif File.exist?(File.join(Configuration.root_path, '.rvmrc'))
|
22
22
|
version_file = '.rvmrc'
|
23
23
|
end
|
24
24
|
return true unless version_file
|
25
25
|
|
26
|
-
version = File.read(File.join(Configuration.
|
26
|
+
version = File.read(File.join(Configuration.root_path, version_file))
|
27
27
|
Gem::Version.new(version) >= Gem::Version.new(@version)
|
28
28
|
end
|
29
29
|
end
|
@@ -76,7 +76,7 @@ module Synvert::Core
|
|
76
76
|
# @option options [Boolean] :run_instance (true) process the instance.
|
77
77
|
# @return [Synvert::Core::Rewriter] the registered rewriter.
|
78
78
|
# @raise [Synvert::Core::RewriterNotFound] if the registered rewriter is not found.
|
79
|
-
def call(group, name, options = {})
|
79
|
+
def call(group, name, options = { run_instance: true })
|
80
80
|
rewriter = fetch(group, name)
|
81
81
|
if options[:run_instance]
|
82
82
|
rewriter.process
|
@@ -274,7 +274,7 @@ module Synvert::Core
|
|
274
274
|
def add_file(filename, content)
|
275
275
|
return unless @options[:run_instance]
|
276
276
|
|
277
|
-
filepath = File.join(Configuration.
|
277
|
+
filepath = File.join(Configuration.root_path, filename)
|
278
278
|
if File.exist?(filepath)
|
279
279
|
puts "File #{filepath} already exists."
|
280
280
|
return
|
@@ -293,7 +293,7 @@ module Synvert::Core
|
|
293
293
|
def remove_file(filename)
|
294
294
|
return unless @options[:run_instance]
|
295
295
|
|
296
|
-
file_path = File.join(Configuration.
|
296
|
+
file_path = File.join(Configuration.root_path, filename)
|
297
297
|
File.delete(file_path) if File.exist?(file_path)
|
298
298
|
end
|
299
299
|
|
data/lib/synvert/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.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-09-
|
11
|
+
date: 2022-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|