packwerk_mermaid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d5fc2720c27d3ef40d87efaa581629539ca1d5e50216fb912f4c83bdd0505b3
4
+ data.tar.gz: 186f3583d0c2292740fa888674c47f949709e9406423fdbfd55854d15182faec
5
+ SHA512:
6
+ metadata.gz: ac63ab51ec034b0dd259edfe5eb9a7f51b23500d38c30e7207521ebfd481fe590d0070c58fd4b96bc1271ed34d5bccc26a4d6949e536b616592dd7135a9c28be
7
+ data.tar.gz: 373a1e0616850c5172c4debff7a183dc2aec5771119a6817bac091f28038acdb82675af4a140d6cf65c68e5a82c3d4f61d04462525d9ef0478b634a5b803e13e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # IDEs
14
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Style/Documentation:
16
+ Enabled: false
17
+
18
+ Naming/AccessorMethodName:
19
+ Enabled: false
20
+
21
+ Metrics/ClassLength:
22
+ Max: 300
23
+
24
+ Metrics/MethodLength:
25
+ Max: 100
26
+
27
+ Metrics/CyclomaticComplexity:
28
+ Max: 50
29
+
30
+ Metrics/AbcSize:
31
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-10-14
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ben@hackerone.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13.0"
8
+
9
+ gem "rspec", "~> 3.0"
10
+
11
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,128 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ packwerk_mermaid (0.1.0)
5
+ packwerk
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionview (7.1.1)
11
+ activesupport (= 7.1.1)
12
+ builder (~> 3.1)
13
+ erubi (~> 1.11)
14
+ rails-dom-testing (~> 2.2)
15
+ rails-html-sanitizer (~> 1.6)
16
+ activesupport (7.1.1)
17
+ base64
18
+ bigdecimal
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ connection_pool (>= 2.2.5)
21
+ drb
22
+ i18n (>= 1.6, < 2)
23
+ minitest (>= 5.1)
24
+ mutex_m
25
+ tzinfo (~> 2.0)
26
+ ast (2.4.2)
27
+ base64 (0.1.1)
28
+ better_html (2.0.2)
29
+ actionview (>= 6.0)
30
+ activesupport (>= 6.0)
31
+ ast (~> 2.0)
32
+ erubi (~> 1.4)
33
+ parser (>= 2.4)
34
+ smart_properties
35
+ bigdecimal (3.1.4)
36
+ builder (3.2.4)
37
+ concurrent-ruby (1.2.2)
38
+ connection_pool (2.4.1)
39
+ constant_resolver (0.2.0)
40
+ crass (1.0.6)
41
+ diff-lcs (1.5.0)
42
+ drb (2.1.1)
43
+ ruby2_keywords
44
+ erubi (1.12.0)
45
+ i18n (1.14.1)
46
+ concurrent-ruby (~> 1.0)
47
+ json (2.6.3)
48
+ language_server-protocol (3.17.0.3)
49
+ loofah (2.21.4)
50
+ crass (~> 1.0.2)
51
+ nokogiri (>= 1.12.0)
52
+ minitest (5.20.0)
53
+ mutex_m (0.1.2)
54
+ nokogiri (1.15.4-arm64-darwin)
55
+ racc (~> 1.4)
56
+ packwerk (3.1.0)
57
+ activesupport (>= 6.0)
58
+ ast
59
+ better_html
60
+ bundler
61
+ constant_resolver (>= 0.2.0)
62
+ parallel
63
+ parser
64
+ sorbet-runtime (>= 0.5.9914)
65
+ zeitwerk (>= 2.6.1)
66
+ parallel (1.23.0)
67
+ parser (3.2.2.4)
68
+ ast (~> 2.4.1)
69
+ racc
70
+ racc (1.7.1)
71
+ rails-dom-testing (2.2.0)
72
+ activesupport (>= 5.0.0)
73
+ minitest
74
+ nokogiri (>= 1.6)
75
+ rails-html-sanitizer (1.6.0)
76
+ loofah (~> 2.21)
77
+ nokogiri (~> 1.14)
78
+ rainbow (3.1.1)
79
+ rake (13.0.6)
80
+ regexp_parser (2.8.2)
81
+ rexml (3.2.6)
82
+ rspec (3.12.0)
83
+ rspec-core (~> 3.12.0)
84
+ rspec-expectations (~> 3.12.0)
85
+ rspec-mocks (~> 3.12.0)
86
+ rspec-core (3.12.2)
87
+ rspec-support (~> 3.12.0)
88
+ rspec-expectations (3.12.3)
89
+ diff-lcs (>= 1.2.0, < 2.0)
90
+ rspec-support (~> 3.12.0)
91
+ rspec-mocks (3.12.6)
92
+ diff-lcs (>= 1.2.0, < 2.0)
93
+ rspec-support (~> 3.12.0)
94
+ rspec-support (3.12.1)
95
+ rubocop (1.57.1)
96
+ base64 (~> 0.1.1)
97
+ json (~> 2.3)
98
+ language_server-protocol (>= 3.17.0)
99
+ parallel (~> 1.10)
100
+ parser (>= 3.2.2.4)
101
+ rainbow (>= 2.2.2, < 4.0)
102
+ regexp_parser (>= 1.8, < 3.0)
103
+ rexml (>= 3.2.5, < 4.0)
104
+ rubocop-ast (>= 1.28.1, < 2.0)
105
+ ruby-progressbar (~> 1.7)
106
+ unicode-display_width (>= 2.4.0, < 3.0)
107
+ rubocop-ast (1.29.0)
108
+ parser (>= 3.2.1.0)
109
+ ruby-progressbar (1.13.0)
110
+ ruby2_keywords (0.0.5)
111
+ smart_properties (1.17.0)
112
+ sorbet-runtime (0.5.11074)
113
+ tzinfo (2.0.6)
114
+ concurrent-ruby (~> 1.0)
115
+ unicode-display_width (2.5.0)
116
+ zeitwerk (2.6.12)
117
+
118
+ PLATFORMS
119
+ arm64-darwin-21
120
+
121
+ DEPENDENCIES
122
+ packwerk_mermaid!
123
+ rake (~> 13.0)
124
+ rspec (~> 3.0)
125
+ rubocop (~> 1.7)
126
+
127
+ BUNDLED WITH
128
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Ben Willis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Packwerk Mermaid
2
+
3
+ This is a simple gem for a project using [packwerk](https://github.com/Shopify/packwerk) to generate a [Mermaid](https://mermaid.js.org/) diagram.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'packwerk_mermaid'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install packwerk_mermaid
20
+
21
+ ## Usage
22
+
23
+ There is no CLI, but it's easy enough to write a Ruby script and run it like so:
24
+
25
+ ```ruby
26
+ require "packwerk_mermaid"
27
+ require "packwerk_mermaid/packwerk_flowchart"
28
+
29
+ configuration = PackwerkMermaid.configure do |config|
30
+ # The title that appears at the top of your diagram
31
+ config.mermaid_title = 'Title of my Diagram'
32
+
33
+ # Text or Markdown support
34
+ config.mermaid_text_type = 'text'
35
+
36
+ # What shape should the diagram use
37
+ config.mermaid_shape_style = 'rectangle_rounded'
38
+
39
+ # What directory is packwerk's root dir
40
+ config.packwerk_directory = '.'
41
+
42
+ # Simple static mapping for renaming packages, these happened
43
+ # before the packwerk_package_name_callback runs
44
+ config.packwerk_package_name_mapping = {
45
+ '.' => 'root',
46
+ 'packs/cli' => 'CLI',
47
+ }
48
+
49
+ # Flexible way to rename packages
50
+ config.packwerk_package_name_callback = lambda { |name| name.gsub('packs/', '') }
51
+
52
+ # Hide packages from the diagram
53
+ config.packwerk_packages_hidden = [
54
+ 'packs/utilities',
55
+ 'packs/legacy_service',
56
+ ]
57
+ end
58
+
59
+ PackwerkMermaid::PackwerkFlowchart.new(configuration).generate
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bwillis/packwerk_mermaid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bwillis/packwerk_mermaid/blob/master/CODE_OF_CONDUCT.md).
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
69
+
70
+ ## Code of Conduct
71
+
72
+ Everyone interacting in the Packs::Mermaid project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/packs-mermaid/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PackwerkMermaid
4
+ class Configuration
5
+ attr_accessor :packwerk_directory,
6
+ :packwerk_package_name_mapping,
7
+ :packwerk_loader,
8
+ :packwerk_package_name_callback,
9
+ :packwerk_packages_hidden,
10
+ :mermaid_title,
11
+ :mermaid_text_type,
12
+ :mermaid_shape_style
13
+
14
+ def initialize
15
+ @packwerk_directory = "."
16
+ @packwerk_package_name_mapping = {}
17
+ @packwerk_loader = Proc.new { |dir| Packwerk::PackageSet.load_all_from(dir) }
18
+ @packwerk_packages_hidden = []
19
+ @mermaid_title = nil
20
+ @mermaid_text_type = MermaidFlowchartBuilder::TEXT
21
+ @mermaid_shape_style = MermaidFlowchartBuilder::RECTANGLE_ROUNDED
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PackwerkMermaid
4
+ class MermaidFlowchartBuilder
5
+ Node = Struct.new(:short_identifier, :identifier) do
6
+ def display_name
7
+ @display_name || identifier
8
+ end
9
+
10
+ attr_writer :display_name
11
+ end
12
+
13
+ DIRECTION = [
14
+ TOP_DOWN = "TD",
15
+ LEFT_TO_RIGHT = "LR"
16
+ ].freeze
17
+
18
+ NODE_SHAPE = [
19
+ RECTANGLE = "rectangle",
20
+ RECTANGLE_ROUNDED = "rectangle_rounded",
21
+ STADIUM = "stadium",
22
+ SUBROUTINE = "subroutine",
23
+ CYLINDRICAL = "cylindrical",
24
+ CIRCLE = "circle",
25
+ CIRCLE_DOUBLE = "circle_double",
26
+ ASYMMETRIC = "asymmetric",
27
+ RHOMBUS = "rhombus",
28
+ HEXAGON = "hexagon",
29
+ PARALLELOGRAM_RIGHT = "parallelogram_right",
30
+ PARALLELOGRAM_LEFT = "parallelogram_left",
31
+ TRAPEZOID_DOWN = "trapezoid_down",
32
+ TRAPEZOID_UP = "trapezoid_up"
33
+ ].freeze
34
+
35
+ TEXT_TYPE = [
36
+ TEXT = "text",
37
+ MARKDOWN = "markdown"
38
+ ].freeze
39
+
40
+ def initialize
41
+ @edges = []
42
+ @nodes = []
43
+ @direction = TOP_DOWN
44
+ @title = nil
45
+ @text_type = TEXT
46
+ @shape_style = RECTANGLE_ROUNDED
47
+ end
48
+
49
+ def set_title(title)
50
+ @title = title
51
+
52
+ self
53
+ end
54
+
55
+ def set_text_type(new_text_type)
56
+ raise Error, "Invalid text type, expected one of #{TEXT_TYPE.join(", ")}" unless TEXT_TYPE.include?(new_text_type)
57
+
58
+ @text_type = new_text_type
59
+
60
+ self
61
+ end
62
+
63
+ def set_shape_style(new_shape_style)
64
+ raise Error, "Invalid shape, expected one of #{NODE_SHAPE.join(", ")}" unless NODE_SHAPE.include?(new_shape_style)
65
+
66
+ @shape_style = new_shape_style
67
+
68
+ self
69
+ end
70
+
71
+ # https://mermaid.js.org/syntax/flowchart.html#direction
72
+ def set_direction(new_direction)
73
+ raise Error, "Invalid direction, expected one of: #{DIRECTION.join(",")}" unless DIRECTION.include? new_direction
74
+
75
+ @direction = new_direction
76
+
77
+ self
78
+ end
79
+
80
+ def add_edge(source, destination)
81
+ @edges << [find_or_add_node(source), find_or_add_node(destination)]
82
+
83
+ self
84
+ end
85
+
86
+ def set_node_display_name(identifier, new_name)
87
+ node = find_or_add_node(identifier)
88
+ node.display_name = new_name
89
+
90
+ self
91
+ end
92
+
93
+ def build
94
+ @name_registered = []
95
+ mermaid_string = ""
96
+ if @title
97
+ mermaid_string += <<~TITLE
98
+ ---
99
+ title: #{@title}
100
+ ---
101
+ TITLE
102
+ end
103
+ mermaid_string += "flowchart #{@direction}"
104
+ mermaid_string += "\n"
105
+ @edges.each do |source, destination|
106
+ mermaid_string += " #{add_mermaid_node_reference(source)} --> #{add_mermaid_node_reference(destination)};"
107
+ mermaid_string += "\n"
108
+ end
109
+
110
+ mermaid_string
111
+ end
112
+
113
+ private
114
+
115
+ def add_node(identifier)
116
+ raise Error, "node already exists with this identifier" if @nodes.any? { |node| node.identifier == identifier }
117
+
118
+ Node.new(@nodes.length, identifier).tap do |node|
119
+ @nodes << node
120
+ end
121
+ end
122
+
123
+ def find_or_add_node(identifier)
124
+ @nodes.find { |node| node.identifier == identifier } || add_node(identifier)
125
+ end
126
+
127
+ def add_mermaid_node_reference(node)
128
+ if @name_registered.include? node.short_identifier
129
+ node.short_identifier
130
+ else
131
+ @name_registered << node.short_identifier
132
+ "#{node.short_identifier}#{mermaid_node_style(node.display_name)}"
133
+ end
134
+ end
135
+
136
+ def mermaid_node_style(text, shape_style = @shape_style, text_type = @text_type)
137
+ # https://mermaid.js.org/syntax/flowchart.html#markdown-formatting
138
+ wrapped_text = case text_type
139
+ when TEXT
140
+ "\"#{text}\""
141
+ when MARKDOWN
142
+ "\"`#{text}`\""
143
+ else
144
+ raise Error, "unsupported, but we could support markdown probably"
145
+ end
146
+
147
+ # https://mermaid.js.org/syntax/flowchart.html#node-shapes
148
+ case shape_style
149
+ when RECTANGLE
150
+ "[#{wrapped_text}]"
151
+ when RECTANGLE_ROUNDED
152
+ "(#{wrapped_text})"
153
+ when STADIUM
154
+ "([#{wrapped_text}])"
155
+ when SUBROUTINE
156
+ "[[#{wrapped_text}]]"
157
+ when CYLINDRICAL
158
+ "[(#{wrapped_text})]"
159
+ when CIRCLE
160
+ "((#{wrapped_text}))"
161
+ when CIRCLE_DOUBLE
162
+ "(((#{wrapped_text})))"
163
+ when ASYMMETRIC
164
+ ">#{wrapped_text}]"
165
+ when RHOMBUS
166
+ "{#{wrapped_text}}"
167
+ when HEXAGON
168
+ "{{#{wrapped_text}}}"
169
+ when PARALLELOGRAM_RIGHT
170
+ "[/#{wrapped_text}/]"
171
+ when PARALLELOGRAM_LEFT
172
+ "[\\#{wrapped_text}\\]"
173
+ when TRAPEZOID_DOWN
174
+ "[\\#{wrapped_text}/]"
175
+ when TRAPEZOID_UP
176
+ "[/#{wrapped_text}\\]"
177
+ else
178
+ raise Error, "unsupported, but we could support other shapes"
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "packwerk"
4
+ require_relative "mermaid_flowchart_builder"
5
+
6
+ module PackwerkMermaid
7
+ class PackwerkFlowchart
8
+ def initialize(configuration = PackwerkMermaid.configuration)
9
+ @configuration = configuration
10
+ end
11
+
12
+ def generate
13
+ package_set = @configuration.packwerk_loader.call(@configuration.packwerk_directory)
14
+
15
+ builder = MermaidFlowchartBuilder.new
16
+ builder
17
+ .set_title(@configuration.mermaid_title)
18
+ .set_text_type(@configuration.mermaid_text_type)
19
+ .set_shape_style(@configuration.mermaid_shape_style)
20
+
21
+ package_set.packages.each do |_path, package|
22
+ next if @configuration.packwerk_packages_hidden.include? package.name
23
+
24
+ package.dependencies.each do |dependency_name|
25
+ next if @configuration.packwerk_packages_hidden.include? dependency_name
26
+
27
+ builder.add_edge(
28
+ rename_package(package.name),
29
+ rename_package(dependency_name)
30
+ )
31
+ end
32
+ end
33
+
34
+ builder.build
35
+ end
36
+
37
+ def rename_package(name)
38
+ return @configuration.packwerk_package_name_mapping[name] unless @configuration.packwerk_package_name_mapping[name].nil?
39
+ return name if @configuration.packwerk_package_name_callback.nil?
40
+
41
+ @configuration.packwerk_package_name_callback.call(name)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PackwerkMermaid
4
+ class Version
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "packwerk_mermaid/version"
4
+ require_relative "packwerk_mermaid/configuration"
5
+ require_relative "packwerk_mermaid/packwerk_flowchart"
6
+
7
+ module PackwerkMermaid
8
+ class Error < StandardError; end
9
+
10
+ def self.configure
11
+ Configuration.new.tap do |configuration|
12
+ yield(configuration)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/packwerk_mermaid/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "packwerk_mermaid"
7
+ spec.version = PackwerkMermaid::Version::VERSION
8
+ spec.authors = ["Ben Willis"]
9
+ spec.email = ["benjamin.willis@gmail.com"]
10
+
11
+ spec.summary = "Generate Mermaid diagrams for packwerk projects"
12
+ spec.description = "Generate Mermaid diagrams for packwerk projects"
13
+ spec.homepage = "https://github.com/bwillis/packwerk_mermaid"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/bwillis/packwerk_mermaid"
21
+ spec.metadata["changelog_uri"] = "https://github.com/bwillis/packwerk_mermaid/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
29
+
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ spec.add_dependency "packwerk"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: packwerk_mermaid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Willis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: packwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Generate Mermaid diagrams for packwerk projects
28
+ email:
29
+ - benjamin.willis@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - lib/packwerk_mermaid.rb
45
+ - lib/packwerk_mermaid/configuration.rb
46
+ - lib/packwerk_mermaid/mermaid_flowchart_builder.rb
47
+ - lib/packwerk_mermaid/packwerk_flowchart.rb
48
+ - lib/packwerk_mermaid/version.rb
49
+ - packwerk_mermaid.gemspec
50
+ homepage: https://github.com/bwillis/packwerk_mermaid
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ homepage_uri: https://github.com/bwillis/packwerk_mermaid
55
+ source_code_uri: https://github.com/bwillis/packwerk_mermaid
56
+ changelog_uri: https://github.com/bwillis/packwerk_mermaid/CHANGELOG.md
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.4.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.1.6
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Generate Mermaid diagrams for packwerk projects
76
+ test_files: []