pocky 1.6.0 → 1.7.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: 85bd82c4180bd9152f53dcf8dcfa2e0cdb54f93211f926823c62572b9c98c7bf
4
- data.tar.gz: 759e6fe70c7981b6342957da759754833c275d086bf4c2b7caab6e4406cf6bf5
3
+ metadata.gz: 22de5def074e1cb08bee99280a266ea9ebcf29056ae4dd117f75682e2e3d3221
4
+ data.tar.gz: 7c8258dbf32e3c30099e7d3b4f7d5b7404c7d28348163b7b9a5f51671b490e2c
5
5
  SHA512:
6
- metadata.gz: d7db906a22cfd1c05fca50101bc0f5c896c6d3ade27cb998a7ab0e6218094a420577a0bd59a67bc41c851007bd73590735b4251e6ed60cff79ef41532572e8c8
7
- data.tar.gz: 2a8078b50d6d0f0fd46ae1269b18f2602d5f69487ac431400d122b4bcddf4415457cd2b695483eda803c3117f80a4b52d5c2c78221406fdbc156bae6b1530dcd
6
+ metadata.gz: e659f0fd8a2a3c0f4a6c9e0bc195ae7493a0b27d774996c533cedce3898a20d14d7f703a9c6f6715e290175c02435519ddfa486ca6ce506d5ac38d97017f7f80
7
+ data.tar.gz: a67332ec4f9dc8503b4267fef328a8d98eb0894bd90554867c3b6f299eba35a898f1e42560c190adf94e4748d182bf16b016fccf0636bb1b28c2e6e44edb4432
data/README.md CHANGED
@@ -6,12 +6,11 @@ Pocky generates dependency graphs for your packwerk packages. The gem is named a
6
6
 
7
7
  ## Usage
8
8
 
9
- Invoke from irb or code
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
13
  default_package: 'Default', # The default package listed as "." in deprecated_references.yml
14
- package_prefix: 'app/packages', # this is for matching package names listed in deprecated_references.yml
15
14
  filename: 'packwerk-viz.png', # Name of output file
16
15
  dpi: 150 # Output file resolution
17
16
  )
@@ -21,11 +20,27 @@ Pocky::Packwerk.generate(
21
20
 
22
21
  Note that the the bold edges indicate heavier dependencies.
23
22
 
24
- Invoke as a rake task
23
+ Invoke as a rake task:
25
24
 
25
+ $ rake pocky:generate"[path/to/app/packages,Monolith,packages.png,100]"
26
+
27
+
28
+ #### `root_path` as an array
29
+ `root_path` can also be an array in case your packages are organized in multiple directories. Alternatively, you can also provide paths to individual packages to generate more focused graphs for your package subsystems.
30
+
31
+ ```ruby
32
+ Pocky::Packwerk.generate(
33
+ root_path: [
34
+ 'path/to/app/packages/a',
35
+ 'path/to/app/packages/z',
36
+ ]
37
+ )
26
38
  ```
27
- rake pocky:generate[path/to/app/packages,Default,app/packages,packwerk-viz.png,150]
28
- ```
39
+
40
+ Generate the same graph using the rake task:
41
+
42
+ $ rake pocky:generate"[path/to/app/packages/a path/to/app/packages/z]"
43
+
29
44
 
30
45
  ## Installation
31
46
 
@@ -51,7 +66,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
51
66
 
52
67
  ## Contributing
53
68
 
54
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pocky.
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mquan/pocky.
55
70
 
56
71
  ## License
57
72
 
@@ -4,7 +4,11 @@ require 'yaml'
4
4
  require 'ruby-graphviz'
5
5
 
6
6
  module Pocky
7
+ class InvalidRootPathError < StandardError
8
+ end
9
+
7
10
  class Packwerk
11
+ REFERENCE_FILE_NAME = 'deprecated_references.yml'
8
12
  MAX_EDGE_WIDTH = 5
9
13
 
10
14
  def self.generate(params)
@@ -15,13 +19,13 @@ module Pocky
15
19
  def initialize(
16
20
  root_path:,
17
21
  default_package: 'Default',
18
- package_prefix: '',
19
22
  filename: 'packwerk-viz.png',
20
23
  dpi: 150
21
24
  )
22
- @root_path = root_path
25
+ @root_paths = [*root_path]
26
+ raise InvalidRootPathError, 'root_path is required' if @root_paths.empty?
27
+
23
28
  @default_package = default_package
24
- @package_prefix = package_prefix
25
29
  @filename = filename
26
30
  @dpi = dpi.to_i
27
31
  @deprecated_references = {}
@@ -29,7 +33,7 @@ module Pocky
29
33
  end
30
34
 
31
35
  def generate
32
- load_package_dependencies
36
+ load_package_references
33
37
  build_directed_graph
34
38
  end
35
39
 
@@ -61,33 +65,35 @@ module Pocky
61
65
  ].min
62
66
  end
63
67
 
64
- def load_package_dependencies
65
- Dir.each_child(@root_path) do |elem|
66
- if Dir.exist?(File.join(@root_path, elem))
67
- load_deprecated_references_for_package(elem)
68
- end
68
+ def package_references
69
+ @package_references ||= @root_paths.flat_map do |path|
70
+ Dir["#{path}/**/#{REFERENCE_FILE_NAME}"]
69
71
  end
70
72
  end
71
73
 
72
- def load_deprecated_references_for_package(package)
73
- @deprecated_references[package] ||= begin
74
- filename = deprecated_references_file_for(package)
75
- if File.exist?(filename)
76
- YAML.load_file(filename) || {}
77
- else
78
- {}
79
- end
74
+ def load_package_references
75
+ if package_references.empty?
76
+ raise InvalidRootPathError, "Cannot find any #{REFERENCE_FILE_NAME} in provided root_path"
77
+ end
78
+
79
+ package_references.each do |filename|
80
+ package = parse_package_name(filename)
81
+ @deprecated_references[package] ||= YAML.load_file(filename) || {}
80
82
  end
81
83
  end
82
84
 
83
- def deprecated_references_file_for(package)
84
- File.join(@root_path, package, 'deprecated_references.yml')
85
+ def parse_package_name(filename)
86
+ File.basename(File.dirname(filename))
85
87
  end
86
88
 
87
89
  def package_name_for_dependency(name)
88
90
  return @default_package if name == '.'
89
91
 
90
- name.gsub(@package_prefix, '').gsub(/^\//, '')
92
+ reference_filename = package_references.find do |ref|
93
+ ref.match(/#{name}\/#{REFERENCE_FILE_NAME}$/)
94
+ end
95
+
96
+ parse_package_name(reference_filename)
91
97
  end
92
98
  end
93
99
  end
@@ -2,7 +2,9 @@ require 'pocky'
2
2
 
3
3
  namespace :pocky do
4
4
  desc 'Generate dependency graph for packwerk packages'
5
- task :generate, [:root_path, :default_package, :package_prefix, :filename, :dpi] do |_task, args|
6
- Pocky::Packwerk.generate(args)
5
+ task :generate, [:root_path, :default_package, :filename, :dpi] do |_task, args|
6
+ Pocky::Packwerk.generate(args.merge(
7
+ root_path: arg[:root_path].split(/\s+/)
8
+ ))
7
9
  end
8
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pocky
4
- VERSION = "1.6.0"
4
+ VERSION = "1.7.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.6.0
4
+ version: 1.7.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: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-graphviz