Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any ways to get dependency graph for project?

Tags:

typescript

Actually I'm looking for something like -M key in gcc but for tsc

like image 320
lazdmx Avatar asked Nov 28 '16 20:11

lazdmx


2 Answers

Dependency cruiser can generate dependencies graphs:

First you have to install it via npm:

npm install --save-dev dependency-cruiser

To make sure TypeScript support works you should first run:

node_modules/.bin/depcruise --info

You can create a JSON file containing the dependencies between your TypeScript files:

node_modules/.bin/depcruise --exclude "^node_modules" --output-type json [your_entry_point.ts] > dependencies.json

If you have installed the dot utility included in graphviz you can generate an SVG

node_modules/.bin/depcruise --exclude "^node_modules" --output-type dot [your_entry_point.ts] > dependencies.dot
dot dependencies.dot -T svg -o dependencies.svg

Dot support many other output formats and graphviz is available as package of most Linux distributions and other operational systems as well

like image 97
Michael Tamm Avatar answered Sep 21 '22 19:09

Michael Tamm


I created ts-dependency-graph, since dependency cruiser did never finish for my rather large project. It contains some options to handle large dependency graphs.

npm i ts_dependency_graph -g

ts_dependency_graph --start src/index.ts

Copy output e.g. to https://dreampuf.github.io/GraphvizOnline/

 ts_dependency_graph --help
Options:
  --help                        Show help                              [boolean]
  --version                     Show version number                    [boolean]
  --start                       the starting file, for the analysis     [string]
  --aggregate_by_folder, --agg  create graph on folder level
                                                      [boolean] [default: false]
  --max_depth                                           [number] [default: 1000]
  --filter                      filters files containing the provided strings
                                                           [array] [default: []]
  --verbose, -v                 prints information about ignored files
                                                      [boolean] [default: false]
  --hotspots, -h                identify hotspots, by analyzing number of
                                incoming and outgoing edges
                                                      [boolean] [default: false]
  --base_path                   calculates path relatives to the base path
   [string] [default: "/currentpath"]
like image 20
Pascalius Avatar answered Sep 17 '22 19:09

Pascalius