js_dependency 0.3.1 → 0.3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +2 -8
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -0
- data/lib/js_dependency/cli.rb +11 -11
- data/lib/js_dependency/index_creator.rb +2 -1
- data/lib/js_dependency/mermaid/nodes_link.rb +3 -1
- data/lib/js_dependency/mermaid/root.rb +1 -1
- data/lib/js_dependency/pathname_utility.rb +6 -0
- data/lib/js_dependency/target_pathname.rb +23 -5
- data/lib/js_dependency/version.rb +1 -1
- data/lib/js_dependency.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 213b92143fa1ae05bd0c3ab2a94351fc6b1d990d82ff560dc4ac1f4d737a8201
|
4
|
+
data.tar.gz: 8ce2ca6a8858adef25577702be473c50fcb56e7c5f5987cd934480bff5d2cfab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ede1bf2786104d0e6246d8becdc27ea0b57332fd93ce0db9ff258f63f6550cdf2ee44759852bb751fcf83e08dce759e6c1d4ed3c2836629826ace1eb95bbfc89
|
7
|
+
data.tar.gz: ccc8d0a032339c59cd745f34e5ec9d3461d96f1fad35981034f6746ab31f05e7936320347fca67c1dde28f99913d2c4b5700a98c047b35cfa45ef8bb0c8bc5bb
|
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-
|
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
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# Offense count: 7
|
10
10
|
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
11
11
|
Metrics/AbcSize:
|
12
|
-
Max:
|
12
|
+
Max: 41
|
13
13
|
|
14
14
|
# Offense count: 5
|
15
15
|
# Configuration parameters: IgnoredMethods.
|
@@ -31,12 +31,6 @@ Metrics/ParameterLists:
|
|
31
31
|
Metrics/PerceivedComplexity:
|
32
32
|
Max: 17
|
33
33
|
|
34
|
-
# Offense count: 1
|
35
|
-
# This cop supports safe autocorrection (--autocorrect).
|
36
|
-
Style/IfUnlessModifier:
|
37
|
-
Exclude:
|
38
|
-
- 'lib/js_dependency/index_creator.rb'
|
39
|
-
|
40
34
|
# Offense count: 1
|
41
35
|
Style/MultilineBlockChain:
|
42
36
|
Exclude:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
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
|
+
|
7
|
+
## [0.3.2] - 2022-07-26
|
8
|
+
|
9
|
+
- Multiple excludes option for CLI.
|
10
|
+
|
3
11
|
## [0.3.1] - 2022-07-25
|
4
12
|
|
5
13
|
- Multiple target paths for JsDependency.export and export_mermaid CLI.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -61,6 +61,12 @@ js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1
|
|
61
61
|
js_dependency -s ./src -t ./src/App.vue ./src/components/Sub.vue -o ./mermaid.txt -c 2 -p 2 -n 1
|
62
62
|
```
|
63
63
|
|
64
|
+
##### Exclude path which iclude exclude words `-e` from output
|
65
|
+
|
66
|
+
```shell
|
67
|
+
js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1 -e excludeWord1 excludeWord2
|
68
|
+
```
|
69
|
+
|
64
70
|
#### Export parents components list
|
65
71
|
|
66
72
|
```shell
|
data/lib/js_dependency/cli.rb
CHANGED
@@ -9,12 +9,12 @@ module JsDependency
|
|
9
9
|
|
10
10
|
desc "export_mermaid", "Output mermaid flowchart string."
|
11
11
|
option :src_path, type: :string, aliases: "-s", desc: "Root folder."
|
12
|
-
option :
|
12
|
+
option :target_paths, type: :array, aliases: "-t", desc: "Target file that you want to analyze."
|
13
13
|
option :output_path, type: :string, aliases: "-o", desc: "Output file path"
|
14
14
|
option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
|
15
15
|
option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
|
16
16
|
option :name_level, type: :numeric, aliases: "-n", desc: "Output name level"
|
17
|
-
option :
|
17
|
+
option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
|
18
18
|
|
19
19
|
def export_mermaid
|
20
20
|
pathname = Pathname.new(".js_dependency.yml")
|
@@ -22,14 +22,14 @@ module JsDependency
|
|
22
22
|
args = YAML.safe_load(pathname.read) if pathname.exist?
|
23
23
|
|
24
24
|
src_path = options[:src_path] || args["src_path"]
|
25
|
-
target_paths = options[:
|
25
|
+
target_paths = options[:target_paths] || (args["target_path"].is_a?(String) ? [args["target_path"]] : args["target_path"])
|
26
26
|
child_analyze_level = options[:child_analyze_level] || args["child_analyze_level"] || 2
|
27
27
|
parent_analyze_level = options[:parent_analyze_level] || args["parent_analyze_level"] || 2
|
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[:
|
32
|
-
|
31
|
+
excludes = if options[:excludes]&.length&.positive?
|
32
|
+
options[:excludes]
|
33
33
|
elsif args["excludes"]
|
34
34
|
args["excludes"]
|
35
35
|
end
|
@@ -53,7 +53,7 @@ module JsDependency
|
|
53
53
|
option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
|
54
54
|
option :output_path, type: :string, aliases: "-o", desc: "Output file path"
|
55
55
|
option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
|
56
|
-
option :
|
56
|
+
option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
|
57
57
|
|
58
58
|
def parents
|
59
59
|
pathname = Pathname.new(".js_dependency.yml")
|
@@ -65,8 +65,8 @@ 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[:
|
69
|
-
|
68
|
+
excludes = if options[:excludes].length.positive?
|
69
|
+
options[:excludes]
|
70
70
|
elsif args["excludes"]
|
71
71
|
args["excludes"]
|
72
72
|
end
|
@@ -88,7 +88,7 @@ module JsDependency
|
|
88
88
|
option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
|
89
89
|
option :output_path, type: :string, aliases: "-o", desc: "Output file path"
|
90
90
|
option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
|
91
|
-
option :
|
91
|
+
option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
|
92
92
|
|
93
93
|
def children
|
94
94
|
pathname = Pathname.new(".js_dependency.yml")
|
@@ -100,8 +100,8 @@ 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[:
|
104
|
-
|
103
|
+
excludes = if options[:excludes].length.positive?
|
104
|
+
options[:excludes]
|
105
105
|
elsif args["excludes"]
|
106
106
|
args["excludes"]
|
107
107
|
end
|
@@ -48,7 +48,8 @@ module JsDependency
|
|
48
48
|
|
49
49
|
obj[component_pathname.to_s] = import_pathnames.map(&:to_s)
|
50
50
|
if component_pathname.basename.to_s == "index.js"
|
51
|
-
obj[component_pathname.dirname.to_s] =
|
51
|
+
obj[component_pathname.dirname.to_s] =
|
52
|
+
import_pathnames.map(&:to_s)
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -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
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
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.1
|
4
|
+
version: 0.3.3.1
|
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-
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pathname
|