js_dependency 0.3.2 → 0.3.3

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: 2bcea60e75e368a74db588a569dcc71dac789988395940b9ae2ec8f8be965cef
4
- data.tar.gz: 3760510a51085c9842eaf0a2b49989c3c400b130bde282d6150f4d986c38c36b
3
+ metadata.gz: d117ec8b831e67223b243ed652261885f1bbffc4734f93ed2d386166d16d31e2
4
+ data.tar.gz: '008fe6a337a677fa62348ca4d76766f02d72affc2b851126f7f22cba45c32c4f'
5
5
  SHA512:
6
- metadata.gz: ba4acdf96d74072a3e439647bdd5817f622d11393961127af5ee88d112a53c4d4231a31bf2a08129dc889cc59bf69e7057e0074554d3572cf9396457dc98e2cd
7
- data.tar.gz: 285681ef4ebea7f2eb9a6cb8214316d0f7899bc275723bcf35be8bde33c2ae5824f3ba0be7e64d163fc3120971073f7c6bbe19bfc265eff0c44722ee2fd7d018
6
+ metadata.gz: 891fdc5a595134a7724a4f9bdf061ac6290025e3e624d1f33d362ba74ef22d696a1dd3355f6befdd8a11661a07b531eef7877ff9271b4f4bb1ca01dd83f3c31e
7
+ data.tar.gz: 574b0b04401c6b3d4b7a510cb0dbbe972a0539d8e052bed48395cc4c7c1f3ec656bf314f57229e6ac79a2524fbacadf89825d8b30fc410e8e6acb3efd50b438e
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 00:36:01 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
@@ -36,7 +36,7 @@ Style/MultilineBlockChain:
36
36
  Exclude:
37
37
  - 'lib/js_dependency/mermaid/root.rb'
38
38
 
39
- # Offense count: 7
39
+ # Offense count: 6
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,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.3] - 2022-07-26
4
+
5
+ - Add special style to target_paths in mermaid output CLI.
6
+
3
7
  ## [0.3.2] - 2022-07-26
4
8
 
5
9
  - 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.3)
5
5
  pathname
6
6
  thor
7
7
  yaml
@@ -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.3"
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.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-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