• Stars
    star
    164
  • Rank 222,344 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 1 year ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🕸️ dependency-graph is a command-line tool that can visualize the dependencies of packages.

🕸️ dependency-graph

Build and Test SwiftLint

dependency-graph is a command-line tool that can visualize the dependencies of packages. The tool takes the path to an Xcode project or a Package.swift file as input and outputs a graph that shows the dependencies of the packages in the project or package.

👀 Examples

The following graphs are examples of the graphs that dependency-graph can output. The first graph built by providing dependency-graph the path to a Package.swift file and the second graph was made by providing dependency-graph the path to an .xcodeproj file as input.

Swift Package Xcode Project
Example graph showing the dependencies of this package. Example graph showing the dependencies of an Xcode project.

Nodes shaped as ellipsis represent products, e.g. the libraries in a Swift package, and the square nodes represent targets.

🚀 Getting Started

Start off by installing the tool with Homebrew.

brew tap simonbs/dependency-graph https://github.com/simonbs/dependency-graph.git
brew install dependency-graph

Note If you get the following error when attempting to install dependency-graph:

Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
   arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.

You can use the the following to install dependency-graph:

arch -arm64 brew install dependency-graph

You may now run the following command to verify that the tool was installed correctly. The following command should print information on how the tool can be used.

dependency-graph --help

Run the dependency-graph command with the path to a folder containing an .xcodeproj or Package.swift file.

dependency-graph ~/Developer/Example

You may also pass the full path to the .xcodeproj or Package.swift file as shown below.

dependency-graph ~/Developer/Example/Example.xcodeproj

Rendering a Graph

The dependency-graph command will output a textual representation of a graph. By default the tool will output a graph using the DOT syntax. For example, if the Xcode project or Package.swift file contains the following dependencies:

Library A in Package A depends on Target A
Library B in Package B depends on Target B
Library A in Package A depends on Library B in Package B

The output of the tool would be a graph that looks like this:

digraph g {
  subgraph cluster_packageA {
    label="Package A"
    libraryA [label="LibraryB", shape=ellipse]
    targetA [label="TargetA", shape=box]
  }

  subgraph cluster_packageB {
    label="Package B"
    libraryB [label="LibraryB", shape=ellipse]
    targetB [label="TargetB", shape=box]
  }

  libraryA -> targetA
  libraryB -> targetB
  libraryA -> libraryB
}

The output can be rendered to an image by piping it to a renderer. See the following sections for details on the supported renderers.

DOT

Example graph rendered with dot.

By default dependency-graph will use the DOT syntax which can be rendered by the dot CLI, which is part of Graphviz.

Install Graphviz and run dependency-graph and pass the output to the newly installed dot CLI.

brew install graphviz
dependency-graph ~/Developer/Example | dot -Tsvg -o graph.svg

When rendering the graph to a PNG, you will likely want to specify the size of the output to ensure it is readable. To generate an image with dot that is exactly 6000 pixels wide or 8000 pixels tall but not necessarily both, do the following:

dependency-graph ~/Developer/Example | dot -Tpng -Gsize=60,80\! -Gdpi=100 -o graph.png

You may want to play around with the values for --node-spacing and --rank-spacing to increase the readability of the graph.

dependency-graph --node-spacing 50 --rank-spacing 150 ~/Developer/Example | dot -Tsvg -o graph.svg

For large projects the graph may become unreadable. Passing the output through Grahpviz' unflatten command may improve the results.

dependency-graph ~/Developer/Example | unflatten -l 100 -c 100 -f | dot -Tpng -o graph.png

Mermaid

Example graph rendered with mermaid.

Specify the --syntax mermaid option to have dependency-graph output a graph using the Mermaid diagram syntax.

The output be rendered to an image using the the mermaid cli.

npm install -g @mermaid-js/mermaid-cli
dependency-graph --syntax mermaid ~/Developer/Example | mmdc -o graph.svg

To generate an image on a page that is 6000 pixels wide with mermaid, do the following:

dependency-graph --syntax mermaid ~/Developer/Example | mmdc -o graph.png -w 6000

You may also want to play around with the values for --node-spacing and --rank-spacing to increase the readability of the graph.

dependency-graph --syntax mermaid --node-spacing 50 --rank-spacing 150 ~/Developer/Example | mmdc -o graph.png

D2

Example graph rendered with D2.

Specify the --syntax d2 option to have dependency-graph output a graph using the d2 scripting language.

The output be rendered to an image using the the d2 cli.

curl -fsSL https://d2lang.com/install.sh | sh -s --
dependency-graph --syntax d2 ~/Developer/Example | d2 - graph.png

The ELK layout engine renders some quite tidy graphs, as shown in the example below.

Example graph rendered with D2 and the ELK layout engine.

Graphing Packages Only

Pass the --packages-only flag to include only the Xcode project and Swift packages in the graph. This omits the libraries and targets within the Xcode project and Swift packages.

Example graph showing only an Xcode project and Swift packages.

🤷‍♂️ OK, why?

As I'm splitting my iOS and macOS applications into small Swift packages with several small targets, I started wishing for a way to visualise the relationship between the products and targets in my Swift packages. That's why I built this tool.

Several other tools can visualise a Swift package, however, I wanted a tool that can take both a Swift package and an Xcode project as input.

The example in the top of this README shows a visualization of a Swift package and the graph below shows a visualisation of an Xcode project. Notice that the left-most subgraph represents an Xcode project named ScriptUIEditor.xcodeproj and it has three targets: ScriptUIEditor, ScriptBrowserFeature, and ScriptBrowserFeatureUITests. Two of these depends on the Swift packages represented by the remaining subgraphs.

These graphs provide a good way to get an overview of a package or the relationship between several packages. Sometimes it can be helpful to generate multiple graphs to get a good overview, for example, a graph of the entire project and graphs of selected packages. Fortunately, the dependency-graph CLI makes this easy as it can take either an Xcode project and a Package.swift file as input.

🧐 ...but how?

dependency-graph parses Xcode project using XcodeProj and interprets Package.swift files using the output from the swift package dump-package command.

This means that dependency-graph does not perform any package resolution or build the project, making it very fast to run the dependency-graph command but also produces a less detailed output that tools that rely on package resolution.

The tool has a focus on visualising local dependencies, that is, Swift packages stored locally in a project. dependency-graph will include remote dependencies in the visualisation but it will not clone those dependencies to determine their dependency graph. It is technically possible to include this but it has not been necessary for my use cases.

More Repositories

1

Runestone

📝 Performant plain text editor for iOS with syntax highlighting, line numbers, invisible characters and much more.
Swift
2,301
star
2

SBSAnimoji

🐵 Animoji app using Apples AvatarKit
Objective-C
985
star
3

BSKeyboardControls

Put controls above the keyboard on your iPhone or iPad app.
Objective-C
528
star
4

KeyboardToolbar

⌨️ Add tools above your keyboard with iOS-like keyboard buttons.
Swift
219
star
5

SBSCustomAnimoji

🐶 Custom Animoji using Apples AvatarKit
Objective-C
106
star
6

xctemplates

⚙️ Opinionated Xcode templates
Shell
94
star
7

darkdocs

Safari extension that adds support for dark mode in Apple’s developer documentation.
CSS
73
star
8

InfiniteCanvas

🖌 Infinite canvas using PencilKit
Swift
65
star
9

alfred-youtube-workflow

A workflow for Alfred 2.0 which lets the user search for YouTube videos and have them returned to Alfred.
Python
54
star
10

alfred-tweetbot-workflow

Control Tweetbot from Alfred 2.0
Python
44
star
11

Prettier

✨ Wrapper for the Prettier code formatter written in Swift
Swift
44
star
12

thingsapp

Node module for creating todos in Things.app
JavaScript
38
star
13

BSPanViewController

A take on the sliding controllers which can optionally move the status bar along with the main view.
Objective-C
36
star
14

Temperatus

A Mac application which shows the current temperature using a Thermodo device
Objective-C
35
star
15

TreeSitterLanguages

Languages for Tree-sitter wrapped in Swift packages
C
33
star
16

alfred-safari-tabs-workflow

Manage tabs in Safari
Python
22
star
17

ios-widget-sizes

The sizes of widgets for select iPhones and iPads.
19
star
18

alfred-movies-workflow

Lookup movies on IMDb and OMDb
Python
17
star
19

homebridge-roomba

Roomba plugin for Homebridge
JavaScript
15
star
20

AppleFeedback

💬 Sample projects submitted to Apple Feedback
Swift
15
star
21

appiconset-creator

Creates .appiconset directories for iOS projects
JavaScript
15
star
22

homebridge-samsungtv

Samsung TV plugin for homebridge.
JavaScript
14
star
23

alfred-cloudapp-workflow

CloudApp workflow for Alfred 2.0 which allows for managing uploads.
Python
14
star
24

BuildABuddyKit

Learning material guiding the reader through documenting their project using Apple's DocC tool.
Swift
12
star
25

samsungtv

Node module for controlling a Samsung TV.
JavaScript
11
star
26

dotfiles

My dotfiles.
Python
10
star
27

Knob

Volume knob for Beoplay speakers
Swift
10
star
28

simonsays

Simon Says for your touch bar.
Swift
10
star
29

CharlesTVDB

A collection of classes for OS X and iOS which provides a block based interface for TheTVDB which is extremely easy to use.
Objective-C
10
star
30

synology-diskstation

Turn on and off a Synology DiskStation
JavaScript
10
star
31

Emcee

Shows the song currently playing in Spotify, Rdio or iTunes.
Swift
10
star
32

ImmersiveMoveAndRotate

Example project showing how an immersive scene on visionOS can contain a RealityView that presents a ModelEntity and how that entity can be dragged using DragGesture and rotated using RotateGesture.
Swift
9
star
33

ColoredTunes

Uses the artwork of the song currently playing in Spotify to change the color of your Philips Hue light bulbs.
Objective-C
6
star
34

BSSwipeTableViewCell

A very customizable table view cell which can be swiped left and right.
Objective-C
6
star
35

Charles

Charles helps you rename your video files and subtitles using data from TheTVDB.
Objective-C
6
star
36

install-op-cli

GitHub Action to install a specified version of the 1Password CLI.
HTML
5
star
37

spotify-controls-api

Simple API for controlling Spotify from other services.
JavaScript
5
star
38

SBSAnimojiRecording

🐨 Proof of concept showing how to overlay an Animoji on top of a camera feed using ARKit
Objective-C
5
star
39

jodelihood

Creates a map with posts from the Jodel community in your neighbourhood.
CSS
5
star
40

findemoji

Slå op i Fødevarestyrelsens kontrolrapporter og find en passende emoji
JavaScript
4
star
41

ThermoWallpaper

An OS X application which sets the desktop wallpaper to a Thermo thermometer showing the current temperature.
Objective-C
4
star
42

Cursor

Trigger an action when device is pointing at a known location.
Swift
3
star
43

alfred-rap-genius-workflow

Look up a song on Rap Genius from Alfred
3
star
44

YourStatusBar

Customize the iOS StatusBar with any text or your custom UIView
Objective-C
2
star
45

Edinem

Editor for Charles session files built on Electron using React
JavaScript
2
star
46

dr-tv-player

OS X app for viewing DR TV live streams. Fast.
Swift
2
star
47

comedy-festival-api

Scrapes shows for the Comedy Festival
JavaScript
2
star
48

findemoji-ios

The Smileyordning is boring. The Emojiordning is more fun.
Swift
2
star
49

forspeciale

Forspeciale, Embedded and Distributed Systems, AAU 2015
TeX
2
star
50

alfred-lyricsfinder-workflow

A workflow for Alfred 2.0 which lets you quickly find lyrics for the song currently playing in Spotify.
Python
2
star
51

comedyfestival

Unofficial Comedy Festival app.
Swift
2
star
52

atju

iOS app for viewing pollen readings from DMI.
Swift
2
star
53

alfred-drtv-workflow

A workflow to browsing and downloading programs from DR TV.
Python
2
star
54

context-aware-home-automation

Context aware home automation based on the users position and motion gestures.
Java
1
star
55

roomba

Node module for controlling a Roomba vacuum cleaner.
JavaScript
1
star
56

speciale

Master's thesis at the Distributed and Embedded systems unit, Aalborg University, Denmark
TeX
1
star
57

BSConfig

Manage configurations in a property list.
Objective-C
1
star
58

docs.runestone.app

📖 Documentation for Runestone hosted on docs.runestone.app
HTML
1
star
59

pawawax

tvOS parallax on arbitrary views
Swift
1
star
60

WordbaseCheater

C++
1
star
61

atju-backend

Polls for pollen readings from DMI and stores them.
JavaScript
1
star
62

google-home-calendar-refresh

Copies calendar events into a primary Google calendar from iCal feeds thereby making it possible for a Google Home to read the calendar events.
JavaScript
1
star