pocky 1.9.2 → 2.0.0

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: 8ad303bcc76eff49ab35053c61a7ad277165d40b999fcadac1d310be525ab69b
4
- data.tar.gz: 16e002a3989465994fa932da11696b166468da711336f354fae58ece194087c4
3
+ metadata.gz: 817ec28553db2266db7aad79d4a6a007c185f72e07473e08f3cd406bd55da240
4
+ data.tar.gz: 1f35a2c830b7462c57a1860c851a349d11f5387d1ba9f04b0e91a44615ef8270
5
5
  SHA512:
6
- metadata.gz: 9bc982c815e4becd96436596522ea9adf543ec3830e04e812185a452a263ee8715572dd260d2b912d2fd7ffaa2f2866ab5d9445b3ea841fa6486a9fd4bc1880e
7
- data.tar.gz: 82a64fb0e51915f78085510a3b1aa78ea1e9a9b48a2a163f29610b280e613e2cfccfb7fb9e1bd6ff59df7b053b8decbcfd389f73d4aa96b0b2785aab318cb692
6
+ metadata.gz: cec156a41900ee641e2a71e1745c90196d7a7b4e7ee11fc0a8da50311462baa83559746244e3f548646aa26d14d1c619a12908b03353ea219f647baf289db853
7
+ data.tar.gz: 42bf0e9dd7c5bbee96cbb6756ef1d42dc5ecb49002dd9cdcad615a008f1e2e2ab995d50f04a705ac3094316ac389f31bf6d0eadd21cc0629f0012ca184964c46
data/README.md CHANGED
@@ -2,18 +2,28 @@
2
2
 
3
3
  Pocky generates dependency graphs for your packwerk packages. The gem is named after pocky, a beloved Japanese snack that comes in small packages.
4
4
 
5
- ![Pocky](https://user-images.githubusercontent.com/138784/103248942-c141de80-4921-11eb-99bd-3744816abc37.png)
6
5
 
7
6
  ## Usage
8
7
 
9
- Invoke from irb or code, only `root_path` is required.
8
+ Invoke from irb or code.
9
+
10
+ ```ruby
11
+ Pocky::Packwerk.generate
12
+ ```
13
+
14
+ Invoke as a rake task:
15
+
16
+ $ rake pocky:generate
17
+
18
+
19
+ #### Generate with custom options
10
20
  ```ruby
11
21
  Pocky::Packwerk.generate(
12
- root_path: 'path/to/app/packages',
22
+ package_path: 'app/packages', # Relative path to packages directory
13
23
  default_package: 'app', # The default package listed as "." in package.yml and deprecated_references.yml
14
- filename: 'packwerk-viz.png', # Name of output file
24
+ filename: 'packwerk.png', # Name of output file
15
25
  dpi: 100, # Output file resolution
16
- package_color: 'darkgray', # color name or hex color, see https://graphviz.org/doc/info/colors.html for more details
26
+ package_color: '#5CC8FF', # color name or hex color, see https://graphviz.org/doc/info/colors.html for more details
17
27
  deprecated_reference_edge: 'black',
18
28
  dependency_edge: 'darkgreen',
19
29
  )
@@ -25,7 +35,7 @@ Note that the the bold edges indicate heavier dependencies.
25
35
 
26
36
  Invoke as a rake task:
27
37
 
28
- $ rake pocky:generate"[path/to/app/packages,Monolith,packages.png,100]"
38
+ $ rake pocky:generate"[app/packages,Monolith,packages.png,100]"
29
39
 
30
40
 
31
41
  #### `root_path` as an array
@@ -33,16 +43,16 @@ Invoke as a rake task:
33
43
 
34
44
  ```ruby
35
45
  Pocky::Packwerk.generate(
36
- root_path: [
37
- 'path/to/app/packages/a',
38
- 'path/to/app/packages/z',
46
+ package_path: [
47
+ 'app/packages/a',
48
+ 'app/packages/z',
39
49
  ]
40
50
  )
41
51
  ```
42
52
 
43
53
  Generate the same graph using the rake task:
44
54
 
45
- $ rake pocky:generate"[path/to/app/packages/a path/to/app/packages/z]"
55
+ $ rake pocky:generate"[app/packages/a app/packages/z]"
46
56
 
47
57
 
48
58
  ## Installation
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pathname'
3
4
  require 'yaml'
4
5
  require 'ruby-graphviz'
5
6
 
@@ -18,16 +19,16 @@ module Pocky
18
19
 
19
20
  private_class_method :new
20
21
  def initialize(
21
- root_path:,
22
+ package_path: nil,
22
23
  default_package: 'app',
23
- filename: 'packwerk-viz.png',
24
+ filename: 'packwerk.png',
24
25
  dpi: 100,
25
- package_color: 'darkgray',
26
- dependency_edge: 'green3',
26
+ package_color: '#5CC8FF',
27
+ dependency_edge: 'darkgreen',
27
28
  deprecated_reference_edge: 'black'
28
29
  )
29
- @root_paths = [*root_path]
30
- raise InvalidRootPathError, 'root_path is required' if @root_paths.empty?
30
+ @package_paths = [*package_path] if package_path
31
+ @root_path = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)
31
32
 
32
33
  @default_package = default_package
33
34
  @filename = filename
@@ -41,6 +42,7 @@ module Pocky
41
42
  fontcolor: 'white',
42
43
  fillcolor: package_color,
43
44
  color: package_color,
45
+ height: 1.0,
44
46
  style: 'filled, rounded',
45
47
  shape: 'box',
46
48
  }
@@ -109,14 +111,22 @@ module Pocky
109
111
  end
110
112
 
111
113
  def deprecated_references_files
112
- @deprecated_references_files ||= @root_paths.flat_map do |path|
113
- Dir["#{path}/**/#{DEPRECATED_REFERENCES_FILENAME}"]
114
+ @deprecated_references_files ||= begin
115
+ return Dir[@root_path.join('**', DEPRECATED_REFERENCES_FILENAME).to_s] unless @package_paths
116
+
117
+ @package_paths.flat_map do |path|
118
+ Dir[@root_path.join(path, '**', DEPRECATED_REFERENCES_FILENAME).to_s]
119
+ end
114
120
  end
115
121
  end
116
122
 
117
123
  def dependencies_files
118
- @dependencies_files ||= @root_paths.flat_map do |path|
119
- Dir["#{path}/**/#{DEPENDENCIES_FILENAME}"]
124
+ @dependencies_files ||= begin
125
+ return Dir[@root_path.join('**', DEPENDENCIES_FILENAME).to_s] unless @package_paths
126
+
127
+ @package_paths.flat_map do |path|
128
+ Dir[@root_path.join(path, '**', DEPENDENCIES_FILENAME).to_s]
129
+ end
120
130
  end
121
131
  end
122
132
 
@@ -142,21 +152,12 @@ module Pocky
142
152
  end
143
153
 
144
154
  def parse_package_name(filename)
145
- File.basename(File.dirname(filename))
155
+ name = File.dirname(filename).gsub(@root_path.to_s, '')
156
+ name == '' ? @default_package : name.gsub(/^\//, '')
146
157
  end
147
158
 
148
159
  def package_name_for_dependency(name)
149
- return @default_package if name == '.'
150
-
151
- reference_filename = deprecated_references_files.find do |ref|
152
- ref.match(/#{name}\/#{DEPRECATED_REFERENCES_FILENAME}$/)
153
- end
154
-
155
- if reference_filename
156
- parse_package_name(reference_filename)
157
- else
158
- name
159
- end
160
+ name == '.' ? @default_package : name
160
161
  end
161
162
  end
162
163
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pocky
4
- VERSION = "1.9.2"
4
+ VERSION = "2.0.0"
5
5
  end
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.2
4
+ version: 2.0.0
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-06 00:00:00.000000000 Z
11
+ date: 2021-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-graphviz