js_dependency 0.3.2 → 0.3.4

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: 2bcea60e75e368a74db588a569dcc71dac789988395940b9ae2ec8f8be965cef
4
- data.tar.gz: 3760510a51085c9842eaf0a2b49989c3c400b130bde282d6150f4d986c38c36b
3
+ metadata.gz: 5997d0d9bed36c8023b64258e0aef13ffe5941ef3c7a5a79b289066e52585b56
4
+ data.tar.gz: eff45da134d5d2f0444ad558c6bdee75133b484efb305c757dce37e2b92635d3
5
5
  SHA512:
6
- metadata.gz: ba4acdf96d74072a3e439647bdd5817f622d11393961127af5ee88d112a53c4d4231a31bf2a08129dc889cc59bf69e7057e0074554d3572cf9396457dc98e2cd
7
- data.tar.gz: 285681ef4ebea7f2eb9a6cb8214316d0f7899bc275723bcf35be8bde33c2ae5824f3ba0be7e64d163fc3120971073f7c6bbe19bfc265eff0c44722ee2fd7d018
6
+ metadata.gz: f33a3de170b77efa529e03beaa39d90b98895e714cb53a06754301bee696aae3ffc4e609e218ac9d03df78ed0cef2fea521c046943459f1261791548b40a6da6
7
+ data.tar.gz: 294f67b0e4149cf112cf6766d36555d3a16c5f073c516b9919b8291209f603005bc81ace2d8879a6d352cc7470a4ede2f552ab07200634a358b64609f641ecd2
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-25 14:50:54 UTC using RuboCop version 1.31.2.
3
+ # on 2022-07-26 10:57:59 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,12 +9,17 @@
9
9
  # Offense count: 7
10
10
  # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
- Max: 41
12
+ Max: 42
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: CountComments, CountAsOne.
16
+ Metrics/ClassLength:
17
+ Max: 101
13
18
 
14
19
  # Offense count: 5
15
20
  # Configuration parameters: IgnoredMethods.
16
21
  Metrics/CyclomaticComplexity:
17
- Max: 16
22
+ Max: 18
18
23
 
19
24
  # Offense count: 9
20
25
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
@@ -29,14 +34,14 @@ Metrics/ParameterLists:
29
34
  # Offense count: 5
30
35
  # Configuration parameters: IgnoredMethods.
31
36
  Metrics/PerceivedComplexity:
32
- Max: 17
37
+ Max: 19
33
38
 
34
39
  # Offense count: 1
35
40
  Style/MultilineBlockChain:
36
41
  Exclude:
37
42
  - 'lib/js_dependency/mermaid/root.rb'
38
43
 
39
- # Offense count: 7
44
+ # Offense count: 6
40
45
  # This cop supports safe autocorrection (--autocorrect).
41
46
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
42
47
  # URISchemes: http, https
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.4] - 2022-07-26
4
+
5
+ - Add version CLI command
6
+ - Bug fix excludes option in parents and children commands.
7
+
8
+ ## [0.3.3] - 2022-07-26
9
+
10
+ - Add special style to target_paths in mermaid output CLI.
11
+
3
12
  ## [0.3.2] - 2022-07-26
4
13
 
5
14
  - Multiple excludes option for CLI.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- js_dependency (0.3.2)
4
+ js_dependency (0.3.4)
5
5
  pathname
6
6
  thor
7
7
  yaml
data/README.md CHANGED
@@ -19,6 +19,15 @@ If bundler is not being used to manage dependencies, install the gem by executin
19
19
  ## Usage
20
20
  ### By Command Line
21
21
 
22
+ #### Version
23
+
24
+ ```shell
25
+ js_dependency version
26
+ # => "X.X.X"
27
+ ```
28
+
29
+ #### yaml configuration file
30
+
22
31
  Configuration file is `./.js_dependency.yml`. This file includes parameters for the analysis.
23
32
 
24
33
  ```yaml
@@ -28,7 +28,7 @@ module JsDependency
28
28
  output_path = options[:output_path] || args["output_path"] || nil
29
29
  alias_paths = args["alias_paths"] || nil
30
30
  name_level = options[:name_level] || args["name_level"] || 1
31
- excludes = if options[:excludes].length.positive?
31
+ excludes = if options[:excludes]&.length&.positive?
32
32
  options[:excludes]
33
33
  elsif args["excludes"]
34
34
  args["excludes"]
@@ -65,7 +65,7 @@ module JsDependency
65
65
  parent_analyze_level = options[:parent_analyze_level] || args["parent_analyze_level"] || 1
66
66
  output_path = options[:output_path] || args["output_path"] || nil
67
67
  alias_paths = args["alias_paths"] || nil
68
- excludes = if options[:excludes].length.positive?
68
+ excludes = if options[:excludes]&.length&.positive?
69
69
  options[:excludes]
70
70
  elsif args["excludes"]
71
71
  args["excludes"]
@@ -100,7 +100,7 @@ module JsDependency
100
100
  child_analyze_level = options[:child_analyze_level] || args["child_analyze_level"] || 1
101
101
  output_path = options[:output_path] || args["output_path"] || nil
102
102
  alias_paths = args["alias_paths"] || nil
103
- excludes = if options[:excludes].length.positive?
103
+ excludes = if options[:excludes]&.length&.positive?
104
104
  options[:excludes]
105
105
  elsif args["excludes"]
106
106
  args["excludes"]
@@ -117,5 +117,10 @@ module JsDependency
117
117
 
118
118
  puts str
119
119
  end
120
+
121
+ desc "version", "show version"
122
+ def version
123
+ puts JsDependency::VERSION
124
+ end
120
125
  end
121
126
  end
@@ -47,7 +47,10 @@ module JsDependency
47
47
  import_pathnames = import_pathnames_from(component_pathname, alias_paths)
48
48
 
49
49
  obj[component_pathname.to_s] = import_pathnames.map(&:to_s)
50
- obj[component_pathname.dirname.to_s] = import_pathnames.map(&:to_s) if component_pathname.basename.to_s == "index.js"
50
+ if component_pathname.basename.to_s == "index.js"
51
+ obj[component_pathname.dirname.to_s] =
52
+ import_pathnames.map(&:to_s)
53
+ end
51
54
  end
52
55
  end
53
56
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../pathname_utility"
4
+
3
5
  module JsDependency
4
6
  module Mermaid
5
7
  class NodesLink
@@ -35,7 +37,7 @@ module JsDependency
35
37
  # @param [Pathname] pathname
36
38
  # @param [Integer] level
37
39
  def parse(pathname, level = -1)
38
- pathname.each_filename.with_object([]) { |filename, array| array << filename }.reverse[0..level].reverse
40
+ JsDependency::PathnameUtility.parse(pathname, level)
39
41
  end
40
42
  end
41
43
  end
@@ -32,7 +32,7 @@ module JsDependency
32
32
 
33
33
  # @param [Integer] name_level
34
34
  # @param [nil, String] src_path
35
- # @return [Array]
35
+ # @return [Array<String>]
36
36
  def export_nodes(name_level: 1, src_path: nil)
37
37
  nodes_links = if src_path
38
38
  src_pathname = Pathname.new(src_path).realpath
@@ -25,5 +25,11 @@ module JsDependency
25
25
  Pathname.new(target_path)
26
26
  end
27
27
  end
28
+
29
+ # @param [Pathname] pathname
30
+ # @param [Integer] level
31
+ def self.parse(pathname, level = -1)
32
+ pathname.each_filename.with_object([]) { |filename, array| array << filename }.reverse[0..level].reverse
33
+ end
28
34
  end
29
35
  end
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "pathname_utility"
3
4
  module JsDependency
4
5
  class TargetPathname
6
+ attr_accessor :color_css, :font_size_css
7
+
5
8
  # @param [String] target_path
6
9
  def initialize(target_path)
7
10
  @pathname = if Pathname.new(target_path).relative? && Pathname.new(target_path).exist?
@@ -9,6 +12,8 @@ module JsDependency
9
12
  else
10
13
  Pathname.new(target_path)
11
14
  end
15
+ @color_css = "#f9f"
16
+ @font_size_css = "4px"
12
17
  end
13
18
 
14
19
  # @param [Integer] analyze_level
@@ -45,8 +50,19 @@ module JsDependency
45
50
  end
46
51
  end
47
52
 
53
+ def mermaid_style(src_path)
54
+ src_pathname = Pathname.new(src_path).realpath
55
+ export_style(parse(@pathname.exist? ? @pathname.relative_path_from(src_pathname) : @pathname).join("_"))
56
+ end
57
+
48
58
  private
49
59
 
60
+ # @param [String] path
61
+ # @return [String]
62
+ def export_style(path)
63
+ "style #{path} stroke:#{@color_css},stroke-width:#{@font_size_css}"
64
+ end
65
+
50
66
  # @param [String] target_path
51
67
  # @param [Hash] index
52
68
  # @return [Array]
@@ -66,11 +82,13 @@ module JsDependency
66
82
  # @param [String] target_path
67
83
  # @return [Pathname]
68
84
  def to_target_pathname(target_path)
69
- if Pathname.new(target_path).relative? && Pathname.new(target_path).exist?
70
- Pathname.new(target_path).realpath
71
- else
72
- Pathname.new(target_path)
73
- end
85
+ JsDependency::PathnameUtility.to_target_pathname(target_path)
86
+ end
87
+
88
+ # @param [Pathname] pathname
89
+ # @param [Integer] level
90
+ def parse(pathname, level = -1)
91
+ JsDependency::PathnameUtility.parse(pathname, level)
74
92
  end
75
93
  end
76
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsDependency
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.4"
5
5
  end
data/lib/js_dependency.rb CHANGED
@@ -33,9 +33,10 @@ module JsDependency
33
33
  index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths, excludes: excludes)
34
34
 
35
35
  nodes = []
36
+ styles = []
36
37
  target_paths.each do |target_path|
37
38
  target_pathname = JsDependency::TargetPathname.new(target_path)
38
-
39
+ styles += [target_pathname.mermaid_style(src_path)]
39
40
  mermaid_root = JsDependency::Mermaid::Root.new(orientation)
40
41
 
41
42
  target_pathname.each_parent_path(parent_analyze_level, index) do |parent_path, child_path|
@@ -48,7 +49,7 @@ module JsDependency
48
49
  nodes += mermaid_root.export_nodes(name_level: name_level, src_path: src_path)
49
50
  end
50
51
 
51
- output = (["flowchart LR"] + nodes.uniq).join("\n")
52
+ output = (["flowchart LR"] + nodes.uniq + styles.uniq).join("\n")
52
53
  output_pathname&.write(output)
53
54
  output
54
55
  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.2
4
+ version: 0.3.4
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-25 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pathname