js_dependency 0.3.10 → 0.3.13

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: 153a609f4227a43182ed6e6a469bcfe466ffe130c5f6d8033771545ca13b4198
4
- data.tar.gz: 32cd8dd2ec33e8906b0bad39c8a4a6378e4909285486f52b6c93915891bed8bb
3
+ metadata.gz: a9b9f351689b4d75a421eda510b534970d54309e031496ed3b1e01e25b0ff0a2
4
+ data.tar.gz: bc0d1e40069754c33aa375b14dbc4d7e29a4d3ae09125dc330a03d4daf0dc4ab
5
5
  SHA512:
6
- metadata.gz: 63e3437906da40a60ed9e129dc8b2a3157221a61d34982bce433dfb8f8b3c7ee198cba9c85b6f230079db5a3a08fe9bb1c103d38763ce139a5aed81ecf5c9e10
7
- data.tar.gz: cf47aa344e700868b2dd76c67ad4323acc2a47e9f0e4d9736d0ae30a981715bb639c52b4d9322b243122879abaf892b314479d39a3c29e4dba56df848cfbe0a0
6
+ metadata.gz: 43af3b1752058c11f4d549275a2cb0bc969fc00cf57c00c72ad5af857fc4af321e918e7858fc79677c8822a5a73c9c3d43995239574be5975603fa03f60a9da8
7
+ data.tar.gz: 931e374285441b95d3a00de41318532e62ce40933969e30a937c8cc175bd1615eb29f5f2e2464db24966bd59ff3ee86f13e103e8f8b61ffe45ee5f0ad8f40938
@@ -1,5 +1,8 @@
1
1
  src_path: ./src
2
2
  target_path: ./src/App.vue
3
+ target_paths:
4
+ - ./src/App1.vue
5
+ - ./src/App2.vue
3
6
  child_analyze_level: 2
4
7
  parent_analyze_level: 2
5
8
  name_level: 1
data/.rubocop_todo.yml CHANGED
@@ -1,22 +1,22 @@
1
1
  # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2022-08-13 03:35:35 UTC using RuboCop version 1.34.1.
2
+ # `rubocop --auto-gen-config --exclude-limit 1`
3
+ # on 2022-08-14 11:04:22 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: 33
12
+ Max: 29
13
13
 
14
- # Offense count: 3
14
+ # Offense count: 2
15
15
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
16
16
  Metrics/CyclomaticComplexity:
17
- Max: 19
17
+ Max: 15
18
18
 
19
- # Offense count: 8
19
+ # Offense count: 7
20
20
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
21
21
  Metrics/MethodLength:
22
22
  Max: 19
@@ -26,17 +26,12 @@ Metrics/MethodLength:
26
26
  Metrics/ParameterLists:
27
27
  Max: 9
28
28
 
29
- # Offense count: 3
29
+ # Offense count: 2
30
30
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
31
31
  Metrics/PerceivedComplexity:
32
- Max: 20
32
+ Max: 15
33
33
 
34
34
  # Offense count: 1
35
- Style/MultilineBlockChain:
36
- Exclude:
37
- - 'lib/js_dependency/mermaid/root.rb'
38
-
39
- # Offense count: 9
40
35
  # This cop supports safe autocorrection (--autocorrect).
41
36
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
42
37
  # URISchemes: http, https
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.13] - 2022-08-14
4
+
5
+ - Add rspec test.
6
+
7
+ ## [0.3.12] - 2022-08-14
8
+
9
+ - Add rspec test.
10
+ - Fix script tag contents extraction if script tag has `src` like `<script src="">` .
11
+
12
+ ## [0.3.11] - 2022-08-13
13
+
14
+ - Add target_paths options in configuration file to use array.
15
+
3
16
  ## [0.3.10] - 2022-08-13
4
17
 
5
18
  - Add file_config options to specify configuration yaml which user like.
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.10)
4
+ js_dependency (0.3.13)
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
@@ -35,6 +35,9 @@ Configuration file is `./.js_dependency.yml`. This file includes parameters for
35
35
  ```yaml
36
36
  src_path: ./src # Root folder
37
37
  target_path: ./src/App.vue # Target file tha you want to analyze
38
+ target_paths: # Target files tha you want to analyze
39
+ - ./src/App1.vue
40
+ - ./src/App2.vue
38
41
  child_analyze_level: 2 # Output level of child analyze
39
42
  parent_analyze_level: 2 # Output level of parent analyze
40
43
  name_level: 1 # Output name level
@@ -10,18 +10,82 @@ module JsDependency
10
10
  # @param [Hash] args
11
11
  def initialize(options, args)
12
12
  @src_path = options[:src_path] || args[:src_path]
13
- @target_paths = options[:target_paths] || (args[:target_path].is_a?(String) ? [args[:target_path]] : args[:target_path])
14
- @target_path = options[:target_path] || args[:target_path]
13
+ @target_paths = calc_target_paths(options[:target_path], options[:target_paths], args[:target_path],
14
+ args[:target_paths])
15
+ @target_path = calc_target_path(options[:target_path], options[:target_paths], args[:target_path],
16
+ args[:target_paths])
15
17
  @child_analyze_level = options[:child_analyze_level] || args[:child_analyze_level] || 2
16
18
  @parent_analyze_level = options[:parent_analyze_level] || args[:parent_analyze_level] || 2
17
19
  @output_path = options[:output_path] || args[:output_path] || nil
18
20
  @alias_paths = options[:alias_paths] || args[:alias_paths] || {}
19
21
  @name_level = options[:name_level] || args[:name_level] || 1
20
- @excludes = if options[:excludes]&.length&.positive?
21
- options[:excludes]
22
- elsif args[:excludes]
23
- args[:excludes]
24
- end
22
+ @excludes = calc_excludes(options[:excludes], args[:excludes])
23
+ end
24
+
25
+ private
26
+
27
+ # @param [String, Array, nil] option_target_path
28
+ # @param [String, Array, nil] option_target_paths
29
+ # @param [String, Array, nil] args_target_path
30
+ # @param [String, Array, nil] args_target_paths
31
+ # @return [nil, Array]
32
+ def calc_target_paths(option_target_path, option_target_paths, args_target_path, args_target_paths)
33
+ [option_target_paths, option_target_path, args_target_paths, args_target_path].each do |obj|
34
+ return as_array(obj) if present?(obj)
35
+ end
36
+
37
+ nil
38
+ end
39
+
40
+ # @param [String, Array, nil] option_target_path
41
+ # @param [String, Array, nil] option_target_paths
42
+ # @param [String, Array, nil] args_target_path
43
+ # @param [String, Array, nil] args_target_paths
44
+ # @return [nil, String]
45
+ def calc_target_path(option_target_path, option_target_paths, args_target_path, args_target_paths)
46
+ [option_target_path, option_target_paths, args_target_path, args_target_paths].each do |obj|
47
+ return as_string_or_first(obj) if present?(obj)
48
+ end
49
+
50
+ nil
51
+ end
52
+
53
+ # @param [Object] option_excludes
54
+ # @param [Object] args_excludes
55
+ # @return [nil, Array]
56
+ def calc_excludes(option_excludes, args_excludes)
57
+ [option_excludes, args_excludes].each do |obj|
58
+ return as_array(obj) if present?(obj)
59
+ end
60
+
61
+ nil
62
+ end
63
+
64
+ # @param [Array, String, nil] obj
65
+ # @return [TrueClass, FalseClass]
66
+ def present?(obj)
67
+ return false if obj.nil?
68
+ return false if obj.empty?
69
+
70
+ true
71
+ end
72
+
73
+ # @param [Array, String, nil] obj
74
+ # @return [Array, nil]
75
+ def as_array(obj)
76
+ return nil if obj.nil?
77
+ return obj if obj.is_a?(Array)
78
+
79
+ [obj]
80
+ end
81
+
82
+ # @param [Array, String, nil] obj
83
+ # @return [String, nil]
84
+ def as_string_or_first(obj)
85
+ return nil if obj.nil?
86
+ return obj if obj.is_a?(String)
87
+
88
+ return obj.first if obj.is_a?(Array)
25
89
  end
26
90
  end
27
91
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsDependency
4
- VERSION = "0.3.10"
4
+ VERSION = "0.3.13"
5
5
  end
data/lib/js_dependency.rb CHANGED
@@ -71,7 +71,7 @@ module JsDependency
71
71
  nodes += mermaid_root.export_nodes(name_level: name_level, src_path: src_path)
72
72
  end
73
73
 
74
- output = (["flowchart LR"] + nodes.uniq + styles.uniq).join("\n")
74
+ output = "#{(["flowchart LR"] + nodes.uniq + styles.uniq).join("\n")}\n"
75
75
  output_pathname&.write(output)
76
76
  output
77
77
  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.10
4
+ version: 0.3.13
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-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pathname