js_dependency 0.3.11 → 0.3.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a61cec11e64fc475a0fb7838b11abf8ab6a1a0d8cfab0929e475eff2fcbef6c0
4
- data.tar.gz: 461e0b8503aec5ab25f7b3508ae420af41f72022e39a4e1388a8ae8217858ac1
3
+ metadata.gz: 249f9142ce332c3874696fb62d0478365ed719caea8088c75b4059ade79931cb
4
+ data.tar.gz: cf44ea94425033c0905d29f496c65d0bbf32c45d7fc8d3681ad1d5a66e9762d0
5
5
  SHA512:
6
- metadata.gz: c2e5483e130e608b4a21741ffccf44db1f812a6096b9f4c5df419cb97029f340c9c8ba770542133d528a213720f924282e9cd72bfd6cc135606904a594c20ed1
7
- data.tar.gz: ae67a36c93fdb56ddc5a59c6244d78b7c58f08399d72a725a6d655e945f518c2a14f517c6253dde5cf26516c1cf30a5834ac77cc752e0a67a51301c13d2576e2
6
+ metadata.gz: a4427662cc2db7567b4bb041416aea5b7b5d60f16a7c112e215670de211c20b4457265f95d087647bc934d96a3f5fa1052e7078c610f056fb0dbf0525c6cc0d9
7
+ data.tar.gz: 2ee5a1db44106a777b7b583204db51fcc37315635101a995bf79110cc99a3e05c0fb1434c2e9a6c4becbd7615237facd0e9ed9b53ca1522d98a85c07bd490302
data/.rubocop_todo.yml CHANGED
@@ -1,42 +1,42 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-08-13 05:13:43 UTC using RuboCop version 1.34.1.
3
+ # on 2022-08-21 04:15:24 UTC using RuboCop version 1.35.0.
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
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
9
+ # Offense count: 2
10
10
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
- Max: 29
12
+ Max: 31
13
13
 
14
- # Offense count: 3
14
+ # Offense count: 1
15
+ # Configuration parameters: CountComments, CountAsOne.
16
+ Metrics/ClassLength:
17
+ Max: 118
18
+
19
+ # Offense count: 2
15
20
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
16
21
  Metrics/CyclomaticComplexity:
17
22
  Max: 15
18
23
 
19
- # Offense count: 8
24
+ # Offense count: 10
20
25
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
21
26
  Metrics/MethodLength:
22
27
  Max: 19
23
28
 
24
- # Offense count: 3
29
+ # Offense count: 4
25
30
  # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
26
31
  Metrics/ParameterLists:
27
32
  Max: 9
28
33
 
29
- # Offense count: 3
34
+ # Offense count: 2
30
35
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
31
36
  Metrics/PerceivedComplexity:
32
37
  Max: 15
33
38
 
34
39
  # Offense count: 1
35
- Style/MultilineBlockChain:
36
- Exclude:
37
- - 'lib/js_dependency/mermaid/root.rb'
38
-
39
- # Offense count: 8
40
40
  # This cop supports safe autocorrection (--autocorrect).
41
41
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
42
42
  # URISchemes: http, https
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.14] - 2022-08-14
4
+
5
+ - Add export_markdown_report cli. This will export the markdown report to a file for GitHub comment.
6
+
7
+ ## [0.3.13] - 2022-08-14
8
+
9
+ - Add rspec test.
10
+
11
+ ## [0.3.12] - 2022-08-14
12
+
13
+ - Add rspec test.
14
+ - Fix script tag contents extraction if script tag has `src` like `<script src="">` .
15
+
3
16
  ## [0.3.11] - 2022-08-13
4
17
 
5
18
  - Add target_paths options in configuration file to use array.
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "codecov", require: false, group: "test"
13
+ gem "debug", ">= 1.0.0"
13
14
  gem "rubocop", "~> 1.21"
14
15
  gem "simplecov", require: false, group: :test
15
16
  gem "yarn"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- js_dependency (0.3.11)
4
+ js_dependency (0.3.14)
5
5
  pathname
6
6
  thor
7
7
  yaml
@@ -14,8 +14,14 @@ GEM
14
14
  codecov (0.6.0)
15
15
  simplecov (>= 0.15, < 0.22)
16
16
  coderay (1.1.3)
17
+ debug (1.6.2)
18
+ irb (>= 1.3.6)
19
+ reline (>= 0.3.1)
17
20
  diff-lcs (1.5.0)
18
21
  docile (1.4.0)
22
+ io-console (0.5.11)
23
+ irb (1.4.1)
24
+ reline (>= 0.3.0)
19
25
  json (2.6.2)
20
26
  parallel (1.22.1)
21
27
  parser (3.1.2.1)
@@ -30,6 +36,8 @@ GEM
30
36
  rainbow (3.1.1)
31
37
  rake (13.0.6)
32
38
  regexp_parser (2.5.0)
39
+ reline (0.3.1)
40
+ io-console (~> 0.5)
33
41
  rexml (3.2.5)
34
42
  rspec (3.11.0)
35
43
  rspec-core (~> 3.11.0)
@@ -50,14 +58,14 @@ GEM
50
58
  rspec (>= 2.13, < 4)
51
59
  unparser
52
60
  rspec-support (3.11.0)
53
- rubocop (1.34.1)
61
+ rubocop (1.35.0)
54
62
  json (~> 2.3)
55
63
  parallel (~> 1.10)
56
64
  parser (>= 3.1.2.1)
57
65
  rainbow (>= 2.2.2, < 4.0)
58
66
  regexp_parser (>= 1.8, < 3.0)
59
67
  rexml (>= 3.2.5, < 4.0)
60
- rubocop-ast (>= 1.20.0, < 2.0)
68
+ rubocop-ast (>= 1.20.1, < 2.0)
61
69
  ruby-progressbar (~> 1.7)
62
70
  unicode-display_width (>= 1.4.0, < 3.0)
63
71
  rubocop-ast (1.21.0)
@@ -94,6 +102,7 @@ PLATFORMS
94
102
 
95
103
  DEPENDENCIES
96
104
  codecov
105
+ debug (>= 1.0.0)
97
106
  js_dependency!
98
107
  rake (~> 13.0)
99
108
  rspec (~> 3.0)
data/README.md CHANGED
@@ -88,6 +88,70 @@ js_dependency -s ./src -t ./src/App.vue ./src/components/Sub.vue -o ./mermaid.tx
88
88
  js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1 -e excludeWord1 excludeWord2 -a @:./pages
89
89
  ```
90
90
 
91
+ #### Export Markdown report
92
+
93
+ ```shell
94
+ js_dependency export_markdown_report -s ./src -t ./src/App.vue -c 2 -p 2 -n 1 -a @:./pages --identifier your_uniq_identifier_for_upsert_report
95
+ ```
96
+
97
+ Like this:
98
+
99
+ ```
100
+ ## JsDependency Reports
101
+
102
+ ### Orphan modules
103
+
104
+ 3 orphaned modules.
105
+
106
+ * ``components/sub/Exclude.vue``
107
+ * ``pages/app.js``
108
+ * ``utils/calculation.js``
109
+
110
+ ### Module dependency
111
+
112
+ \```mermaid
113
+ flowchart LR
114
+ components_Button["components/Button"] --> components_sub_Title.vue["sub/Title.vue"]
115
+ components_Button["components/Button"] --> fixtures_index_creator_self_call_src_components_sub_Exclude["sub/Exclude"]
116
+ components_New.vue["components/New.vue"] --> components_Button["components/Button"]
117
+ components_New.vue["components/New.vue"] --> components_modal.js["components/modal.js"]
118
+ pages_app.js["pages/app.js"] --> components_New.vue["components/New.vue"]
119
+ utils_calculation.js["utils/calculation.js"] --> external_lib["external/lib"]
120
+ style components_New.vue stroke:#f9f,stroke-width:4px
121
+ style utils_calculation.js stroke:#f9f,stroke-width:4px
122
+ \```
123
+
124
+ <!-- identifier -->
125
+
126
+ ```
127
+
128
+ ## JsDependency Reports
129
+
130
+ ### Orphan modules
131
+
132
+ 3 orphaned modules.
133
+
134
+ * ``components/sub/Exclude.vue``
135
+ * ``pages/app.js``
136
+ * ``utils/calculation.js``
137
+
138
+ ### Module dependency
139
+
140
+ ```mermaid
141
+ flowchart LR
142
+ components_Button["components/Button"] --> components_sub_Title.vue["sub/Title.vue"]
143
+ components_Button["components/Button"] --> fixtures_index_creator_self_call_src_components_sub_Exclude["sub/Exclude"]
144
+ components_New.vue["components/New.vue"] --> components_Button["components/Button"]
145
+ components_New.vue["components/New.vue"] --> components_modal.js["components/modal.js"]
146
+ pages_app.js["pages/app.js"] --> components_New.vue["components/New.vue"]
147
+ utils_calculation.js["utils/calculation.js"] --> external_lib["external/lib"]
148
+ style components_New.vue stroke:#f9f,stroke-width:4px
149
+ style utils_calculation.js stroke:#f9f,stroke-width:4px
150
+ ```
151
+
152
+ <!-- identifier -->
153
+
154
+
91
155
  #### Export parents components list
92
156
 
93
157
  ```shell
@@ -109,5 +109,32 @@ module JsDependency
109
109
  def version
110
110
  puts JsDependency::VERSION
111
111
  end
112
+
113
+ desc "export_markdown_report", "Output markdown formatted report."
114
+ method_option :src_path, type: :string, aliases: "-s", desc: "Root folder."
115
+ method_option :target_paths, type: :array, aliases: "-t", desc: "Target file that you want to analyze."
116
+ method_option :output_path, type: :string, aliases: "-o", desc: "Output file path"
117
+ method_option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
118
+ method_option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
119
+ method_option :name_level, type: :numeric, aliases: "-n", desc: "Output name level"
120
+ method_option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
121
+ method_option :alias_paths, type: :hash, aliases: "-a", desc: "Alias paths by hash format."
122
+ method_option :file_config, type: :string, aliases: "-f", desc: "Configuration file path."
123
+ method_option :identifier, type: :string, desc: "Embed id in markdown."
124
+
125
+ def export_markdown_report
126
+ args = JsDependency::CliUtils::Yaml.new(path: options[:file_config]).args
127
+ config = JsDependency::CliUtils::Config.new(options, args)
128
+ puts JsDependency.export_markdown_report(
129
+ config.src_path,
130
+ config.target_paths,
131
+ child_analyze_level: config.child_analyze_level,
132
+ parent_analyze_level: config.parent_analyze_level,
133
+ alias_paths: config.alias_paths,
134
+ name_level: config.name_level,
135
+ excludes: config.excludes,
136
+ identifier: config.identifier
137
+ )
138
+ end
112
139
  end
113
140
  end
@@ -4,7 +4,7 @@ module JsDependency
4
4
  module CliUtils
5
5
  class Config
6
6
  attr_reader :src_path, :target_paths, :target_path, :child_analyze_level, :parent_analyze_level, :output_path,
7
- :alias_paths, :name_level, :excludes
7
+ :alias_paths, :name_level, :excludes, :identifier
8
8
 
9
9
  # @param [Hash] options
10
10
  # @param [Hash] args
@@ -20,6 +20,7 @@ module JsDependency
20
20
  @alias_paths = options[:alias_paths] || args[:alias_paths] || {}
21
21
  @name_level = options[:name_level] || args[:name_level] || 1
22
22
  @excludes = calc_excludes(options[:excludes], args[:excludes])
23
+ @identifier = options[:identifier] || nil
23
24
  end
24
25
 
25
26
  private
@@ -15,6 +15,10 @@ module JsDependency
15
15
  list << Regexp.last_match(1)
16
16
  end
17
17
 
18
+ scripts += str.gsub(%r{<script.+src=".+">(.+)</script>}m).with_object([]) do |_, list|
19
+ list << Regexp.last_match(1)
20
+ end
21
+
18
22
  scripts.uniq.sort.join("\n")
19
23
  end
20
24
 
@@ -26,10 +26,32 @@ module JsDependency
26
26
  mermaid_str(@child, level)
27
27
  end
28
28
 
29
+ # @param [String] src_path
30
+ # @return [JsDependency::Mermaid::NodesLink]
31
+ def relative_path_from(src_path)
32
+ NodesLink.new(
33
+ relative_parent_path(src_path),
34
+ relative_child_path(src_path)
35
+ )
36
+ end
37
+
29
38
  private
30
39
 
40
+ # @param [String] src_path
41
+ # @return [String]
42
+ def relative_parent_path(src_path)
43
+ parent.exist? ? parent.realpath.relative_path_from(Pathname.new(src_path).realpath.to_s).to_s : parent.to_s
44
+ end
45
+
46
+ # @param [String] src_path
47
+ # @return [String]
48
+ def relative_child_path(src_path)
49
+ child.exist? ? child.realpath.relative_path_from(Pathname.new(src_path).realpath.to_s).to_s : child.to_s
50
+ end
51
+
31
52
  # @param [Pathname] pathname
32
53
  # @param [Integer] level
54
+ # @return [String]
33
55
  def mermaid_str(pathname, level = 0)
34
56
  "#{parse(pathname).join("_")}[\"#{parse(pathname, level).join("/")}\"]"
35
57
  end
@@ -5,6 +5,7 @@ module JsDependency
5
5
  module Mermaid
6
6
  class Root
7
7
  attr_accessor :orientation
8
+ attr_reader :list
8
9
 
9
10
  # @param [String] orientation
10
11
  def initialize(orientation = "LR")
@@ -35,18 +36,14 @@ module JsDependency
35
36
  # @return [Array<String>]
36
37
  def export_nodes(name_level: 1, src_path: nil)
37
38
  nodes_links = if src_path
38
- src_pathname = Pathname.new(src_path).realpath
39
- @list.map do |nodes_link|
40
- NodesLink.new(nodes_link.parent.exist? ? nodes_link.parent.relative_path_from(src_pathname.to_s) : nodes_link.parent.to_s,
41
- nodes_link.child.exist? ? nodes_link.child.relative_path_from(src_pathname.to_s) : nodes_link.child.to_s)
42
- end
39
+ @list.map { |nodes_link| nodes_link.relative_path_from(src_path) }
43
40
  else
44
41
  @list
45
42
  end
46
- nodes_links.uniq do |link|
47
- "#{link.parent}__#{link.child}"
48
- end.sort_by { |link| "#{link.parent}__#{link.child}" }.map do |link|
49
- "#{link.parent_module_name(name_level)} --> #{link.child_module_name(name_level)}"
43
+ nodes_links = nodes_links.uniq { |nodes_link| "#{nodes_link.parent}__#{nodes_link.child}" }
44
+ nodes_links = nodes_links.sort_by { |nodes_link| "#{nodes_link.parent}__#{nodes_link.child}" }
45
+ nodes_links.map do |nodes_link|
46
+ "#{nodes_link.parent_module_name(name_level)} --> #{nodes_link.child_module_name(name_level)}"
50
47
  end
51
48
  end
52
49
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsDependency
4
+ module Report
5
+ class Markdown
6
+ attr_reader :orphan_list, :mermaid_markdown, :identifier
7
+
8
+ # @param [Array] orphan_list
9
+ # @param [String] mermaid_markdown
10
+ # @param [nil, String] identifier
11
+ def initialize(orphan_list, mermaid_markdown, identifier: nil)
12
+ @orphan_list = orphan_list || []
13
+ @mermaid_markdown = mermaid_markdown || ""
14
+ @identifier = identifier || "js_dependency_report_identifier"
15
+ end
16
+
17
+ # @return [String]
18
+ def export
19
+ markdown = <<~"MAKRDOWNTEXT"
20
+ ## JsDependency Reports
21
+
22
+ ### Orphan modules
23
+
24
+ MAKRDOWNTEXT
25
+
26
+ if @orphan_list.empty?
27
+ markdown += "No orphaned module !\n\n"
28
+ else
29
+ markdown += "#{@orphan_list.size} orphaned modules.\n\n"
30
+ markdown += "#{@orphan_list.map { |str| "* ``#{str}``" }.join("\n")}\n\n"
31
+ end
32
+
33
+ markdown += <<~"MAKRDOWNTEXT"
34
+ ### Module dependency
35
+
36
+ ```mermaid
37
+ MAKRDOWNTEXT
38
+ markdown += @mermaid_markdown.to_s
39
+
40
+ markdown += <<~"MAKRDOWNTEXT"
41
+ ```
42
+
43
+ MAKRDOWNTEXT
44
+
45
+ markdown += "<!-- #{@identifier} -->"
46
+ markdown
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsDependency
4
- VERSION = "0.3.11"
4
+ VERSION = "0.3.14"
5
5
  end
data/lib/js_dependency.rb CHANGED
@@ -9,6 +9,7 @@ require_relative "js_dependency/mermaid/target_pathname"
9
9
  require_relative "js_dependency/source_analysis/leave"
10
10
  require_relative "js_dependency/source_analysis/orphan"
11
11
  require_relative "js_dependency/pathname_utility"
12
+ require_relative "js_dependency/report/markdown"
12
13
  require_relative "js_dependency/cli_utils/yaml"
13
14
  require_relative "js_dependency/cli_utils/config"
14
15
  require "pathname"
@@ -71,7 +72,7 @@ module JsDependency
71
72
  nodes += mermaid_root.export_nodes(name_level: name_level, src_path: src_path)
72
73
  end
73
74
 
74
- output = (["flowchart LR"] + nodes.uniq + styles.uniq).join("\n")
75
+ output = "#{(["flowchart LR"] + nodes.uniq + styles.uniq).join("\n")}\n"
75
76
  output_pathname&.write(output)
76
77
  output
77
78
  end
@@ -123,4 +124,33 @@ module JsDependency
123
124
  output_pathname&.write(output.sort.join("\n"))
124
125
  output
125
126
  end
127
+
128
+ # @param [String] src_path
129
+ # @param [Array<String>] target_paths
130
+ # @param [String] orientation
131
+ # @param [Hash, nil] alias_paths
132
+ # @param [Integer] child_analyze_level
133
+ # @param [Integer] parent_analyze_level
134
+ # @param [Integer] name_level
135
+ # @param [String, nil] output_path
136
+ # @param [Array, nil] excludes
137
+ # @param [String, nil] identifier
138
+ # @return [String]
139
+ def self.export_markdown_report(src_path, target_paths, orientation: "LR", alias_paths: nil, child_analyze_level: 1,
140
+ parent_analyze_level: 1, name_level: 1, excludes: nil, identifier: nil)
141
+ mermaid_markdown = JsDependency.export_mermaid(
142
+ src_path,
143
+ target_paths,
144
+ orientation: orientation,
145
+ alias_paths: alias_paths,
146
+ child_analyze_level: child_analyze_level,
147
+ parent_analyze_level: parent_analyze_level,
148
+ name_level: name_level,
149
+ excludes: excludes
150
+ )
151
+
152
+ orphan_list = JsDependency.orphan(src_path, alias_paths: alias_paths)
153
+
154
+ JsDependency::Report::Markdown.new(orphan_list, mermaid_markdown, identifier: identifier).export
155
+ end
126
156
  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.3.11
4
+ version: 0.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - junara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-13 00:00:00.000000000 Z
11
+ date: 2022-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pathname
@@ -170,6 +170,7 @@ files:
170
170
  - lib/js_dependency/mermaid/target_pathname.rb
171
171
  - lib/js_dependency/pathname_utility.rb
172
172
  - lib/js_dependency/replace_path_alias.rb
173
+ - lib/js_dependency/report/markdown.rb
173
174
  - lib/js_dependency/source_analysis/leave.rb
174
175
  - lib/js_dependency/source_analysis/orphan.rb
175
176
  - lib/js_dependency/target_pathname.rb