pocky 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/pocky/packwerk.rb +55 -20
- data/lib/pocky/version.rb +1 -1
- 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: ab45111779ec64a861557a7efeb7fefb02a255e0aa34ab791b8ae747475e7614
|
4
|
+
data.tar.gz: e9b23a9174780956f67ab1db2746050e94649b7a56243b8a201598e18cb49181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29bcf083442dfe4e2267b8475fcc872a90161f6ee9a0bc4321fec130acfaad2598557ebd2084ef106ea41887a9d86de9e35c36e2c73b74690c2b4bd1f567a3ca
|
7
|
+
data.tar.gz: c843b24dcc15b025d7426821abfd58da27dcfdef877752e75c53b6750dce4783a618ba7a1df0125658888c6b1c688ef8fe1cd35b82a5fab522e25d754ebde013
|
data/README.md
CHANGED
@@ -10,9 +10,9 @@ Invoke from irb or code, only `root_path` is required.
|
|
10
10
|
```ruby
|
11
11
|
Pocky::Packwerk.generate(
|
12
12
|
root_path: 'path/to/app/packages',
|
13
|
-
default_package: '
|
13
|
+
default_package: 'app', # The default package listed as "." in deprecated_references.yml
|
14
14
|
filename: 'packwerk-viz.png', # Name of output file
|
15
|
-
dpi:
|
15
|
+
dpi: 100 # Output file resolution
|
16
16
|
)
|
17
17
|
```
|
18
18
|
|
data/lib/pocky/packwerk.rb
CHANGED
@@ -8,7 +8,8 @@ module Pocky
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class Packwerk
|
11
|
-
|
11
|
+
DEPENDENCIES_FILENAME = 'package.yml'
|
12
|
+
DEPRECATED_REFERENCES_FILENAME = 'deprecated_references.yml'
|
12
13
|
MAX_EDGE_WIDTH = 5
|
13
14
|
|
14
15
|
def self.generate(params)
|
@@ -18,9 +19,9 @@ module Pocky
|
|
18
19
|
private_class_method :new
|
19
20
|
def initialize(
|
20
21
|
root_path:,
|
21
|
-
default_package: '
|
22
|
+
default_package: 'app',
|
22
23
|
filename: 'packwerk-viz.png',
|
23
|
-
dpi:
|
24
|
+
dpi: 100
|
24
25
|
)
|
25
26
|
@root_paths = [*root_path]
|
26
27
|
raise InvalidRootPathError, 'root_path is required' if @root_paths.empty?
|
@@ -29,33 +30,54 @@ module Pocky
|
|
29
30
|
@filename = filename
|
30
31
|
@dpi = dpi.to_i
|
31
32
|
@deprecated_references = {}
|
33
|
+
@package_dependencies = {}
|
32
34
|
@nodes = {}
|
33
35
|
end
|
34
36
|
|
35
37
|
def generate
|
36
|
-
|
38
|
+
load_dependencies
|
39
|
+
load_deprecated_references
|
37
40
|
build_directed_graph
|
38
41
|
end
|
39
42
|
|
40
43
|
private
|
41
44
|
|
42
45
|
def build_directed_graph
|
43
|
-
graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
|
46
|
+
@graph = GraphViz.new(:G, type: :digraph, dpi: @dpi)
|
47
|
+
draw_dependencies
|
48
|
+
draw_deprecated_references
|
49
|
+
@graph.output(png: @filename)
|
50
|
+
end
|
51
|
+
|
52
|
+
def draw_dependencies
|
53
|
+
@package_dependencies.each do |package, file|
|
54
|
+
@nodes[package] ||= @graph.add_nodes(package)
|
55
|
+
file['dependencies'].each do |provider|
|
56
|
+
provider_package = package_name_for_dependency(provider)
|
57
|
+
@nodes[provider_package] ||= @graph.add_nodes(provider_package)
|
58
|
+
|
59
|
+
@graph.add_edges(
|
60
|
+
@nodes[package],
|
61
|
+
@nodes[provider_package]
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def draw_deprecated_references
|
44
68
|
@deprecated_references.each do |package, references|
|
45
|
-
@nodes[package] ||= graph.add_nodes(package)
|
46
|
-
references.each do |provider,
|
69
|
+
@nodes[package] ||= @graph.add_nodes(package)
|
70
|
+
references.each do |provider, invocations|
|
47
71
|
provider_package = package_name_for_dependency(provider)
|
48
|
-
@nodes[provider_package] ||= graph.add_nodes(provider_package)
|
72
|
+
@nodes[provider_package] ||= @graph.add_nodes(provider_package)
|
49
73
|
|
50
|
-
graph.add_edges(
|
74
|
+
@graph.add_edges(
|
51
75
|
@nodes[package],
|
52
76
|
@nodes[provider_package],
|
53
|
-
|
77
|
+
pendwidth: edge_width(invocations.length)
|
54
78
|
)
|
55
79
|
end
|
56
80
|
end
|
57
|
-
|
58
|
-
graph.output(png: @filename)
|
59
81
|
end
|
60
82
|
|
61
83
|
def edge_width(count)
|
@@ -65,18 +87,31 @@ module Pocky
|
|
65
87
|
].min
|
66
88
|
end
|
67
89
|
|
68
|
-
def
|
69
|
-
@
|
70
|
-
Dir["#{path}/**/#{
|
90
|
+
def deprecated_references_files
|
91
|
+
@deprecated_references_files ||= @root_paths.flat_map do |path|
|
92
|
+
Dir["#{path}/**/#{DEPRECATED_REFERENCES_FILENAME}"]
|
71
93
|
end
|
72
94
|
end
|
73
95
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
96
|
+
def dependencies_files
|
97
|
+
@dependencies_files ||= @root_paths.flat_map do |path|
|
98
|
+
Dir["#{path}/**/#{DEPENDENCIES_FILENAME}"]
|
77
99
|
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def load_dependencies
|
103
|
+
return if dependencies_files.empty?
|
104
|
+
|
105
|
+
dependencies_files.each do |filename|
|
106
|
+
package = parse_package_name(filename)
|
107
|
+
@package_dependencies[package] ||= YAML.load_file(filename) || {}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def load_deprecated_references
|
112
|
+
return if deprecated_references_files.empty?
|
78
113
|
|
79
|
-
|
114
|
+
deprecated_references_files.each do |filename|
|
80
115
|
package = parse_package_name(filename)
|
81
116
|
@deprecated_references[package] ||= YAML.load_file(filename) || {}
|
82
117
|
end
|
@@ -89,7 +124,7 @@ module Pocky
|
|
89
124
|
def package_name_for_dependency(name)
|
90
125
|
return @default_package if name == '.'
|
91
126
|
|
92
|
-
reference_filename =
|
127
|
+
reference_filename = deprecated_references.find do |ref|
|
93
128
|
ref.match(/#{name}\/#{REFERENCE_FILE_NAME}$/)
|
94
129
|
end
|
95
130
|
|
data/lib/pocky/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pocky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Quan Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-graphviz
|