js_dependency 0.3.12 → 0.3.15

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: 8a4e8c31528eb944e9acf98aaf37710cffb27728f6e5c9b7337f85dcf5a3ca13
4
- data.tar.gz: fb428fe8a8eca603ebef72f19771d8b8d94235d782ccb301e2de7bb11da0a004
3
+ metadata.gz: c40c515c695755869134ea2cda376981c48e4202648fc4946d66219b93d5917b
4
+ data.tar.gz: c185eaf95efb2f6a8c11abd91380b2f736c8ddee5dc410f7ea0dab44641eb0aa
5
5
  SHA512:
6
- metadata.gz: 7531ac4e27d5ec92a7efeea5e13051baed6471d7b059c622bd2aa21885a9d09bfcf9767c99bc59812adf1de6b333e60374518a888a7f3ef704d64a0d827ac812
7
- data.tar.gz: 818a5e4210088a3f3d240a18d437909842c46619636e0c38cac1ffd3444659812e2b3a13dfe10b98f39bc4561fb8f52594696374159215f8d4bd29214f436cd1
6
+ metadata.gz: af9562638595533ae8cda360e0a5575909a3d36f376e47d863988b0e2ced296853cafda54468530c8484c63516d304ce8e7180e7491491461748778df340eb06
7
+ data.tar.gz: f2f0046905e4906585b47b89b50d37e767b96498d49680202346105ac78f07322cb4eb69471611e326031d654c37e6bb3ef4d37c72d7b1e29c8f4a45220d106b
@@ -12,3 +12,5 @@ alias_paths:
12
12
  excludes:
13
13
  - excludedWord1
14
14
  - excludedWord2
15
+ exclude_output_names:
16
+ - pages
data/.rubocop_todo.yml CHANGED
@@ -1,44 +1,49 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-08-13 15:05:03 UTC using RuboCop version 1.35.0.
3
+ # on 2022-08-21 08:22:13 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: 2
10
- Lint/UselessAssignment:
11
- Exclude:
12
- - 'spec/js_dependency_spec.rb'
13
-
14
- # Offense count: 2
9
+ # Offense count: 3
15
10
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
16
11
  Metrics/AbcSize:
17
- Max: 29
12
+ Max: 32
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: CountComments, CountAsOne.
16
+ Metrics/ClassLength:
17
+ Max: 120
18
18
 
19
19
  # Offense count: 2
20
20
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
21
21
  Metrics/CyclomaticComplexity:
22
22
  Max: 15
23
23
 
24
- # Offense count: 7
24
+ # Offense count: 10
25
25
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
26
26
  Metrics/MethodLength:
27
- Max: 19
27
+ Max: 22
28
28
 
29
- # Offense count: 3
29
+ # Offense count: 4
30
30
  # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
31
31
  Metrics/ParameterLists:
32
- Max: 9
32
+ Max: 10
33
33
 
34
34
  # Offense count: 2
35
35
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
36
36
  Metrics/PerceivedComplexity:
37
37
  Max: 15
38
38
 
39
- # Offense count: 18
39
+ # Offense count: 1
40
+ # Configuration parameters: CountAsOne.
41
+ RSpec/ExampleLength:
42
+ Max: 6
43
+
44
+ # Offense count: 2
40
45
  # This cop supports safe autocorrection (--autocorrect).
41
46
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
42
47
  # URISchemes: http, https
43
48
  Layout/LineLength:
44
- Max: 187
49
+ Max: 183
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.15] - 2022-08-21
4
+
5
+ - Add exclude_output_names option for export_markdown_report.
6
+
7
+ ## [0.3.14] - 2022-08-21
8
+
9
+ - Add export_markdown_report cli. This will export the markdown report to a file for GitHub comment.
10
+
11
+ ## [0.3.13] - 2022-08-14
12
+
13
+ - Add rspec test.
14
+
3
15
  ## [0.3.12] - 2022-08-14
4
16
 
5
17
  - Add rspec test.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- js_dependency (0.3.12)
4
+ js_dependency (0.3.15)
5
5
  pathname
6
6
  thor
7
7
  yaml
@@ -14,9 +14,9 @@ GEM
14
14
  codecov (0.6.0)
15
15
  simplecov (>= 0.15, < 0.22)
16
16
  coderay (1.1.3)
17
- debug (1.5.0)
17
+ debug (1.6.2)
18
18
  irb (>= 1.3.6)
19
- reline (>= 0.2.7)
19
+ reline (>= 0.3.1)
20
20
  diff-lcs (1.5.0)
21
21
  docile (1.4.0)
22
22
  io-console (0.5.11)
@@ -58,14 +58,14 @@ GEM
58
58
  rspec (>= 2.13, < 4)
59
59
  unparser
60
60
  rspec-support (3.11.0)
61
- rubocop (1.34.1)
61
+ rubocop (1.35.0)
62
62
  json (~> 2.3)
63
63
  parallel (~> 1.10)
64
64
  parser (>= 3.1.2.1)
65
65
  rainbow (>= 2.2.2, < 4.0)
66
66
  regexp_parser (>= 1.8, < 3.0)
67
67
  rexml (>= 3.2.5, < 4.0)
68
- rubocop-ast (>= 1.20.0, < 2.0)
68
+ rubocop-ast (>= 1.20.1, < 2.0)
69
69
  ruby-progressbar (~> 1.7)
70
70
  unicode-display_width (>= 1.4.0, < 3.0)
71
71
  rubocop-ast (1.21.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 --exclude_output_names pages
95
+ ```
96
+
97
+ ``--exclude_output_names`` option is used to exclude outputs from orphan list by name matching. In following results, include pages file is excluded from orphan.
98
+
99
+ Like this:
100
+
101
+ ```
102
+ ## JsDependency Reports
103
+
104
+ ### Orphan modules
105
+
106
+ 2 orphaned modules.
107
+
108
+ * ``components/sub/Exclude.vue``
109
+ * ``utils/calculation.js``
110
+
111
+ ### Module dependency
112
+
113
+ \```mermaid
114
+ flowchart LR
115
+ components_Button["components/Button"] --> components_sub_Title.vue["sub/Title.vue"]
116
+ components_Button["components/Button"] --> fixtures_index_creator_self_call_src_components_sub_Exclude["sub/Exclude"]
117
+ components_New.vue["components/New.vue"] --> components_Button["components/Button"]
118
+ components_New.vue["components/New.vue"] --> components_modal.js["components/modal.js"]
119
+ pages_app.js["pages/app.js"] --> components_New.vue["components/New.vue"]
120
+ utils_calculation.js["utils/calculation.js"] --> external_lib["external/lib"]
121
+ style components_New.vue stroke:#f9f,stroke-width:4px
122
+ style utils_calculation.js stroke:#f9f,stroke-width:4px
123
+ \```
124
+
125
+ <!-- identifier -->
126
+
127
+ ```
128
+
129
+ ## JsDependency Reports
130
+
131
+ ### Orphan modules
132
+
133
+ 2 orphaned modules.
134
+
135
+ * ``components/sub/Exclude.vue``
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,33 @@ 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
+ method_option :exclude_output_names, type: :array, desc: "Exclude output names"
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
+ exclude_output_names: config.exclude_output_names
138
+ )
139
+ end
112
140
  end
113
141
  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, :exclude_output_names
8
8
 
9
9
  # @param [Hash] options
10
10
  # @param [Hash] args
@@ -20,6 +20,8 @@ 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
24
+ @exclude_output_names = options[:exclude_output_names] || []
23
25
  end
24
26
 
25
27
  private
@@ -46,5 +46,14 @@ module JsDependency
46
46
  pathname.to_s
47
47
  end
48
48
  end
49
+
50
+ # @param [Array<String>] paths
51
+ # @return [Array<String>]
52
+ def self.filter_js_files(paths)
53
+ return paths if paths.nil? || paths.empty?
54
+
55
+ permitted_extnames = %w[.js .vue .jsx]
56
+ paths.filter { |path| permitted_extnames.include?(Pathname.new(path).extname) }
57
+ end
49
58
  end
50
59
  end
@@ -0,0 +1,55 @@
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 += "### Module dependency\n\n"
34
+
35
+ if @mermaid_markdown.nil? || @mermaid_markdown.empty?
36
+ markdown += ".vue or .js or .jsx files are not changed.\n\n"
37
+ else
38
+ markdown += <<~"MAKRDOWNTEXT"
39
+ ```mermaid
40
+ MAKRDOWNTEXT
41
+
42
+ markdown += @mermaid_markdown.to_s
43
+
44
+ markdown += <<~"MAKRDOWNTEXT"
45
+ ```
46
+
47
+ MAKRDOWNTEXT
48
+ end
49
+
50
+ markdown += "<!-- #{@identifier} -->"
51
+ markdown
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsDependency
4
- VERSION = "0.3.12"
4
+ VERSION = "0.3.15"
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"
@@ -35,9 +36,13 @@ module JsDependency
35
36
  # @param [String] src_path
36
37
  # @param [Hash, nil] alias_paths
37
38
  # @return [Array<String>]
38
- def self.orphan(src_path, alias_paths: nil)
39
+ def self.orphan(src_path, alias_paths: nil, exclude_output_names: [])
39
40
  index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
40
- JsDependency::SourceAnalysis::Orphan.new(index, src_path).call
41
+ JsDependency::SourceAnalysis::Orphan.new(index, src_path).call.filter do |path|
42
+ exclude_output_names.none? do |name|
43
+ path.include?(name)
44
+ end
45
+ end
41
46
  end
42
47
 
43
48
  # @param [String] src_path
@@ -123,4 +128,37 @@ module JsDependency
123
128
  output_pathname&.write(output.sort.join("\n"))
124
129
  output
125
130
  end
131
+
132
+ # @param [String] src_path
133
+ # @param [Array<String>] target_paths
134
+ # @param [String] orientation
135
+ # @param [Hash, nil] alias_paths
136
+ # @param [Integer] child_analyze_level
137
+ # @param [Integer] parent_analyze_level
138
+ # @param [Integer] name_level
139
+ # @param [String, nil] output_path
140
+ # @param [Array, nil] excludes
141
+ # @param [String, nil] identifier
142
+ # @return [String]
143
+ def self.export_markdown_report(src_path, target_paths, orientation: "LR", alias_paths: nil, child_analyze_level: 1,
144
+ parent_analyze_level: 1, name_level: 1, excludes: nil, identifier: nil, exclude_output_names: [])
145
+ permitted_target_paths = JsDependency::PathnameUtility.filter_js_files(target_paths)
146
+ mermaid_markdown = if target_paths.nil? || target_paths.empty?
147
+ nil
148
+ else
149
+ JsDependency.export_mermaid(
150
+ src_path,
151
+ permitted_target_paths,
152
+ orientation: orientation,
153
+ alias_paths: alias_paths,
154
+ child_analyze_level: child_analyze_level,
155
+ parent_analyze_level: parent_analyze_level,
156
+ name_level: name_level,
157
+ excludes: excludes
158
+ )
159
+ end
160
+ orphan_list = JsDependency.orphan(src_path, alias_paths: alias_paths, exclude_output_names: exclude_output_names)
161
+
162
+ JsDependency::Report::Markdown.new(orphan_list, mermaid_markdown, identifier: identifier).export
163
+ end
126
164
  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.12
4
+ version: 0.3.15
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