js_dependency 0.2.0 → 0.2.3

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: 1c3c24ad458ab62df198ebb779c5a9142a7bff0aee92bb95a9bc88061192045c
4
- data.tar.gz: e9d6e041aee4a8df90c3ebc850474f2c8f6ad808ac07368fdfc8bec009a7b463
3
+ metadata.gz: 7b8953dd4a8b764b770e0f8cb04d2699f5b5c8bf5248b49b13e7be9292458146
4
+ data.tar.gz: ce935f0e5035762546570a0bce1971cf82279ebdfe39af47fbc225c0c836e907
5
5
  SHA512:
6
- metadata.gz: 2fdda6bc1addc027df2fcfdb802bd5fa2c413422e80bf7c89d99532cc0bdff1fd47fed2c17fdfb675662b5ea8fc545235e0764a804db67d1e8a49ebf66f76c19
7
- data.tar.gz: 38923fd2655a8c60b2e844df0075256eb1e8bbb7d92bd07cc9330551846fbd730f3a7e1f75ac2a8a93f680c6beff8eafcec10f2b407f9a69c4df78ab160aad2d
6
+ metadata.gz: 8fca2ad58152cb2f955c7df0bb067f8b6fcbdeecd7bf44716a11eac776c433325b87b7f5ff240c261efe31c81d8484bf2642aa819437c7c56ec8e45bb90a2fb6
7
+ data.tar.gz: c0d65e0fddd984a85fcf2c26d4233bec7b9d90f8c999d370c876889b813d182beaf0eecc6aefe815496f4bd4db2fa5a0e9cc12b912c267df0c111a8bb707c053
@@ -5,4 +5,7 @@ parent_analyze_level: 2
5
5
  name_level: 1
6
6
  output_path: ./mermaid.txt
7
7
  alias_paths:
8
- "@": ./src
8
+ "@": ./pages
9
+ excludes:
10
+ - excludedWord1
11
+ - excludedWord2
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-07-19 16:03:39 UTC using RuboCop version 1.31.2.
3
+ # on 2022-07-20 23:10:21 UTC using RuboCop version 1.31.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -9,32 +9,32 @@
9
9
  # Offense count: 6
10
10
  # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
- Max: 30
12
+ Max: 37
13
13
 
14
- # Offense count: 3
14
+ # Offense count: 6
15
15
  # Configuration parameters: IgnoredMethods.
16
16
  Metrics/CyclomaticComplexity:
17
- Max: 13
17
+ Max: 15
18
18
 
19
19
  # Offense count: 8
20
20
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
21
21
  Metrics/MethodLength:
22
- Max: 20
22
+ Max: 26
23
23
 
24
24
  # Offense count: 1
25
25
  # Configuration parameters: CountComments, CountAsOne.
26
26
  Metrics/ModuleLength:
27
- Max: 112
27
+ Max: 114
28
28
 
29
- # Offense count: 1
29
+ # Offense count: 3
30
30
  # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
31
31
  Metrics/ParameterLists:
32
- Max: 8
32
+ Max: 9
33
33
 
34
- # Offense count: 3
34
+ # Offense count: 6
35
35
  # Configuration parameters: IgnoredMethods.
36
36
  Metrics/PerceivedComplexity:
37
- Max: 13
37
+ Max: 16
38
38
 
39
39
  # Offense count: 1
40
40
  # This cop supports safe autocorrection (--autocorrect).
@@ -42,9 +42,9 @@ Style/IfUnlessModifier:
42
42
  Exclude:
43
43
  - 'lib/js_dependency/index_creator.rb'
44
44
 
45
- # Offense count: 1
45
+ # Offense count: 2
46
46
  # This cop supports safe autocorrection (--autocorrect).
47
47
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
48
48
  # URISchemes: http, https
49
49
  Layout/LineLength:
50
- Max: 167
50
+ Max: 182
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.3] - 2022-07-21
4
+
5
+ - Fix for script tag with line brake.
6
+
7
+ ## [0.2.2] - 2022-07-21
8
+
9
+ - Add CLI option parameter "exclude".
10
+ - Add yaml configuration option parameter "excludes" that is array of "exclude".
11
+
12
+ ## [0.2.1] - 2022-07-20
13
+
14
+ - Output parents and children cli with line brake and sort.
15
+ - Output mermaid with parent and child string sorting.
16
+
3
17
  ## [0.2.0] - 2022-07-19
4
18
 
5
19
  - Add CLI interface.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- js_dependency (0.2.0)
4
+ js_dependency (0.2.3)
5
5
  pathname
6
6
  thor
7
7
  yaml
data/README.md CHANGED
@@ -29,7 +29,22 @@ parent_analyze_level: 2 # Output level of parent analyze
29
29
  name_level: 1 # Output name level
30
30
  output_path: ./mermaid.txt # Output file path
31
31
  alias_paths: # Alias path
32
- "@": ./src
32
+ "@": ./pages # absolute path or relative path of src_path
33
+ excludes: # Exclude words that you want to skip from export.
34
+ - excludeWord1
35
+ - excludeWord2
36
+ ```
37
+
38
+ Each parameter is overridden by the command line.
39
+
40
+ ```
41
+ src_path -> -s
42
+ target_path -> -t
43
+ child_analyze_level -> -c
44
+ parent_analyze_level -> -p
45
+ name_level -> -n
46
+ output_path -> -o
47
+ exclude -> -e
33
48
  ```
34
49
 
35
50
  #### Export Mermaid Format
@@ -14,6 +14,8 @@ module JsDependency
14
14
  option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
15
15
  option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
16
16
  option :name_level, type: :numeric, aliases: "-n", desc: "Output name level"
17
+ option :exclude, type: :string, aliases: "-e", desc: "Exclude the word that is included in the path"
18
+
17
19
  def export_mermaid
18
20
  pathname = Pathname.new(".js_dependency.yml")
19
21
  args = {}
@@ -26,6 +28,11 @@ module JsDependency
26
28
  output_path = options[:output_path] || args["output_path"] || nil
27
29
  alias_paths = args["alias_paths"] || nil
28
30
  name_level = options[:name_level] || args["name_level"] || 1
31
+ excludes = if options[:exclude]
32
+ [options[:exclude]]
33
+ elsif args["excludes"]
34
+ args["excludes"]
35
+ end
29
36
 
30
37
  str = JsDependency.export_mermaid(
31
38
  src_path,
@@ -34,7 +41,8 @@ module JsDependency
34
41
  parent_analyze_level: parent_analyze_level,
35
42
  output_path: output_path,
36
43
  alias_paths: alias_paths,
37
- name_level: name_level
44
+ name_level: name_level,
45
+ excludes: excludes
38
46
  )
39
47
 
40
48
  puts str
@@ -45,6 +53,8 @@ module JsDependency
45
53
  option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
46
54
  option :output_path, type: :string, aliases: "-o", desc: "Output file path"
47
55
  option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
56
+ option :exclude, type: :string, aliases: "-e", desc: "Exclude the word that is included in the path"
57
+
48
58
  def parents
49
59
  pathname = Pathname.new(".js_dependency.yml")
50
60
  args = {}
@@ -55,13 +65,19 @@ module JsDependency
55
65
  parent_analyze_level = options[:parent_analyze_level] || args["parent_analyze_level"] || 1
56
66
  output_path = options[:output_path] || args["output_path"] || nil
57
67
  alias_paths = args["alias_paths"] || nil
68
+ excludes = if options[:exclude]
69
+ [options[:exclude]]
70
+ elsif args["excludes"]
71
+ args["excludes"]
72
+ end
58
73
 
59
74
  str = JsDependency.parents(
60
75
  src_path,
61
76
  target_path,
62
77
  parent_analyze_level: parent_analyze_level,
63
78
  output_path: output_path,
64
- alias_paths: alias_paths
79
+ alias_paths: alias_paths,
80
+ excludes: excludes
65
81
  ).sort.uniq.join("\n")
66
82
 
67
83
  puts str
@@ -72,6 +88,8 @@ module JsDependency
72
88
  option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
73
89
  option :output_path, type: :string, aliases: "-o", desc: "Output file path"
74
90
  option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
91
+ option :exclude, type: :string, aliases: "-e", desc: "Exclude the word that is included in the path"
92
+
75
93
  def children
76
94
  pathname = Pathname.new(".js_dependency.yml")
77
95
  args = {}
@@ -82,13 +100,19 @@ module JsDependency
82
100
  child_analyze_level = options[:child_analyze_level] || args["child_analyze_level"] || 1
83
101
  output_path = options[:output_path] || args["output_path"] || nil
84
102
  alias_paths = args["alias_paths"] || nil
103
+ excludes = if options[:exclude]
104
+ [options[:exclude]]
105
+ elsif args["excludes"]
106
+ args["excludes"]
107
+ end
85
108
 
86
109
  str = JsDependency.children(
87
110
  src_path,
88
111
  target_path,
89
112
  child_analyze_level: child_analyze_level,
90
113
  output_path: output_path,
91
- alias_paths: alias_paths
114
+ alias_paths: alias_paths,
115
+ excludes: excludes
92
116
  ).sort.uniq.join("\n")
93
117
 
94
118
  puts str
@@ -7,7 +7,7 @@ module JsDependency
7
7
  @str = str
8
8
  end
9
9
 
10
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
10
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
11
11
  # @return [Array<String>]
12
12
  def call
13
13
  str = @str
@@ -68,7 +68,7 @@ module JsDependency
68
68
  end
69
69
  paths.uniq.sort
70
70
  end
71
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
71
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
72
72
 
73
73
  def self.call(str)
74
74
  new(str).call
@@ -10,7 +10,7 @@ module JsDependency
10
10
  # @return [Array<String>]
11
11
  def call
12
12
  str = @str
13
- scripts = str.gsub(%r{<script>(.+)</script>}m).with_object([]) do |_, list|
13
+ scripts = str.gsub(%r{<script.*>(.+)</script>}m).with_object([]) do |_, list|
14
14
  list << Regexp.last_match(1)
15
15
  end
16
16
 
@@ -17,7 +17,7 @@ module JsDependency
17
17
 
18
18
  def export(name_level: 1)
19
19
  str = "flowchart #{orientation}\n"
20
- str + @list.sort_by(&:parent).uniq { |link| "#{link.parent}__#{link.child}" }.map do |link|
20
+ str + @list.uniq { |link| "#{link.parent}__#{link.child}" }.sort_by { |link| "#{link.parent}__#{link.child}" }.map do |link|
21
21
  "#{link.parent_module_name(name_level)} --> #{link.child_module_name(name_level)}"
22
22
  end.join("\n")
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsDependency
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.3"
5
5
  end
data/lib/js_dependency.rb CHANGED
@@ -17,8 +17,9 @@ module JsDependency
17
17
  # @param [Integer] parent_analyze_level
18
18
  # @param [Integer] name_level
19
19
  # @param [String, nil] output_path
20
+ # @param [Array, nil] excludes
20
21
  # @return [String]
21
- def self.export_mermaid(src_path, target_path, orientation: "LR", alias_paths: nil, child_analyze_level: 1, parent_analyze_level: 1, name_level: 1, output_path: nil)
22
+ def self.export_mermaid(src_path, target_path, orientation: "LR", alias_paths: nil, child_analyze_level: 1, parent_analyze_level: 1, name_level: 1, output_path: nil, excludes: nil)
22
23
  output_pathname = Pathname.new(output_path) if output_path
23
24
  index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
24
25
 
@@ -30,11 +31,11 @@ module JsDependency
30
31
 
31
32
  root = JsDependency::Mermaid::Root.new(orientation)
32
33
 
33
- parents_paths(target_pathname, parent_analyze_level, index) do |parent_path, child_path|
34
+ parents_paths(target_pathname, parent_analyze_level, index, excludes: excludes) do |parent_path, child_path|
34
35
  root.add(parent_path, child_path)
35
36
  end
36
37
 
37
- children_paths(target_pathname, child_analyze_level, index) do |parent_path, child_path|
38
+ children_paths(target_pathname, child_analyze_level, index, excludes: excludes) do |parent_path, child_path|
38
39
  root.add(parent_path, child_path)
39
40
  end
40
41
 
@@ -43,7 +44,7 @@ module JsDependency
43
44
  output
44
45
  end
45
46
 
46
- def self.parents(src_path, target_path, alias_paths: nil, parent_analyze_level: 1, output_path: nil)
47
+ def self.parents(src_path, target_path, alias_paths: nil, parent_analyze_level: 1, output_path: nil, excludes: nil)
47
48
  output_pathname = Pathname.new(output_path) if output_path
48
49
  index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
49
50
 
@@ -53,15 +54,15 @@ module JsDependency
53
54
  Pathname.new(target_path)
54
55
  end
55
56
  list = []
56
- parents_paths(target_pathname, parent_analyze_level, index) do |parent_path, _child_path|
57
+ parents_paths(target_pathname, parent_analyze_level, index, excludes: excludes) do |parent_path, _child_path|
57
58
  list << parent_path
58
59
  end
59
60
  output = list.uniq
60
- output_pathname&.write(output)
61
+ output_pathname&.write(output.sort.join("\n"))
61
62
  output
62
63
  end
63
64
 
64
- def self.children(src_path, target_path, alias_paths: nil, child_analyze_level: 1, output_path: nil)
65
+ def self.children(src_path, target_path, alias_paths: nil, child_analyze_level: 1, output_path: nil, excludes: nil)
65
66
  output_pathname = Pathname.new(output_path) if output_path
66
67
  index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
67
68
 
@@ -71,11 +72,11 @@ module JsDependency
71
72
  Pathname.new(target_path)
72
73
  end
73
74
  list = []
74
- children_paths(target_pathname, child_analyze_level, index) do |_parent_path, child_path|
75
+ children_paths(target_pathname, child_analyze_level, index, excludes: excludes) do |_parent_path, child_path|
75
76
  list << child_path
76
77
  end
77
78
  output = list.uniq
78
- output_pathname&.write(output)
79
+ output_pathname&.write(output.sort.join("\n"))
79
80
  output
80
81
  end
81
82
 
@@ -92,6 +93,7 @@ module JsDependency
92
93
  list << parent if children.any?(target_pathname.to_s)
93
94
  end
94
95
  end
96
+
95
97
  private_class_method :extract_parent_paths
96
98
 
97
99
  # @param [String] target_path
@@ -105,6 +107,7 @@ module JsDependency
105
107
  end
106
108
  index[target_pathname.to_s] || []
107
109
  end
110
+
108
111
  private_class_method :extract_children_paths
109
112
 
110
113
  # @param [String] src
@@ -112,9 +115,10 @@ module JsDependency
112
115
  def self.create_index(src_path, alias_paths: nil)
113
116
  JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
114
117
  end
118
+
115
119
  private_class_method :create_index
116
120
 
117
- def self.parents_paths(target_pathname, analyze_level, index)
121
+ def self.parents_paths(target_pathname, analyze_level, index, excludes: nil)
118
122
  temp_paths = [target_pathname.to_s]
119
123
  analyze_level.times do
120
124
  list = []
@@ -126,15 +130,18 @@ module JsDependency
126
130
  end
127
131
 
128
132
  list += extract_parent_paths(temp_pathname.to_s, index).each do |parent_path|
133
+ next if excludes&.any? { |ignore| parent_path.to_s.include?(ignore) }
134
+
129
135
  yield parent_path, temp_pathname.to_s
130
136
  end
131
137
  end
132
138
  temp_paths = list
133
139
  end
134
140
  end
141
+
135
142
  private_class_method :parents_paths
136
143
 
137
- def self.children_paths(target_pathname, analyze_level, index)
144
+ def self.children_paths(target_pathname, analyze_level, index, excludes: nil)
138
145
  temp_paths = [target_pathname.to_s]
139
146
  analyze_level.times do
140
147
  list = []
@@ -146,11 +153,14 @@ module JsDependency
146
153
  end
147
154
 
148
155
  list += extract_children_paths(temp_pathname.to_s, index).each do |child_path|
156
+ next if excludes&.any? { |ignore| child_path.to_s.include?(ignore) }
157
+
149
158
  yield temp_pathname.to_s, child_path
150
159
  end
151
160
  end
152
161
  temp_paths = list
153
162
  end
154
163
  end
164
+
155
165
  private_class_method :children_paths
156
166
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_dependency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - junara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-19 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pathname